Search in sources :

Example 6 with DescribeProducersResult

use of org.apache.kafka.clients.admin.DescribeProducersResult in project kafka by apache.

the class TransactionsCommandTest method testDescribeProducers.

private void testDescribeProducers(TopicPartition topicPartition, String[] args, DescribeProducersOptions expectedOptions) throws Exception {
    DescribeProducersResult describeResult = Mockito.mock(DescribeProducersResult.class);
    KafkaFuture<PartitionProducerState> describeFuture = completedFuture(new PartitionProducerState(asList(new ProducerState(12345L, 15, 1300, 1599509565L, OptionalInt.of(20), OptionalLong.of(990)), new ProducerState(98765L, 30, 2300, 1599509599L, OptionalInt.empty(), OptionalLong.empty()))));
    Mockito.when(describeResult.partitionResult(topicPartition)).thenReturn(describeFuture);
    Mockito.when(admin.describeProducers(singleton(topicPartition), expectedOptions)).thenReturn(describeResult);
    execute(args);
    assertNormalExit();
    List<List<String>> table = readOutputAsTable();
    assertEquals(3, table.size());
    List<String> expectedHeaders = asList(TransactionsCommand.DescribeProducersCommand.HEADERS);
    assertEquals(expectedHeaders, table.get(0));
    Set<List<String>> expectedRows = Utils.mkSet(asList("12345", "15", "20", "1300", "1599509565", "990"), asList("98765", "30", "-1", "2300", "1599509599", "None"));
    assertEquals(expectedRows, new HashSet<>(table.subList(1, table.size())));
}
Also used : ProducerState(org.apache.kafka.clients.admin.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult)

Aggregations

DescribeProducersResult (org.apache.kafka.clients.admin.DescribeProducersResult)6 DescribeProducersOptions (org.apache.kafka.clients.admin.DescribeProducersOptions)4 TopicPartition (org.apache.kafka.common.TopicPartition)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)3 ProducerState (org.apache.kafka.clients.admin.ProducerState)3 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)3 Node (org.apache.kafka.common.Node)3 TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)3 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 AbortTransactionResult (org.apache.kafka.clients.admin.AbortTransactionResult)1 AbortTransactionSpec (org.apache.kafka.clients.admin.AbortTransactionSpec)1