Search in sources :

Example 1 with DescribeProducersResult

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

the class TransactionsCommandTest method testFindHangingLookupTopicAndBrokerId.

@Test
public void testFindHangingLookupTopicAndBrokerId() throws Exception {
    int brokerId = 5;
    String topic = "foo";
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--broker-id", String.valueOf(brokerId), "--topic", topic };
    Node node0 = new Node(0, "localhost", 9092);
    Node node1 = new Node(1, "localhost", 9093);
    Node node5 = new Node(5, "localhost", 9097);
    TopicPartitionInfo partition0 = new TopicPartitionInfo(0, node0, Arrays.asList(node0, node1), Arrays.asList(node0, node1));
    TopicPartitionInfo partition1 = new TopicPartitionInfo(1, node1, Arrays.asList(node1, node5), Arrays.asList(node1, node5));
    TopicDescription description = new TopicDescription(topic, false, Arrays.asList(partition0, partition1));
    expectDescribeTopics(singletonMap(topic, description));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(emptyMap()));
    Mockito.when(admin.describeProducers(Collections.singletonList(new TopicPartition(topic, 1)), new DescribeProducersOptions().brokerId(brokerId))).thenReturn(result);
    execute(args);
    assertNormalExit();
    assertNoHangingTransactions();
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DescribeProducersResult

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

the class TransactionsCommandTest method expectDescribeProducers.

private void expectDescribeProducers(TopicPartition topicPartition, long producerId, short producerEpoch, long lastTimestamp, OptionalInt coordinatorEpoch, OptionalLong txnStartOffset) {
    PartitionProducerState partitionProducerState = new PartitionProducerState(singletonList(new ProducerState(producerId, producerEpoch, 500, lastTimestamp, coordinatorEpoch, txnStartOffset)));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(singletonMap(topicPartition, partitionProducerState)));
    Mockito.when(admin.describeProducers(Collections.singletonList(topicPartition), new DescribeProducersOptions())).thenReturn(result);
}
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) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions)

Example 3 with DescribeProducersResult

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

the class TransactionsCommandTest method testFindHangingLookupTopicPartitionsForBroker.

@Test
public void testFindHangingLookupTopicPartitionsForBroker() throws Exception {
    int brokerId = 5;
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--broker-id", String.valueOf(brokerId) };
    String topic = "foo";
    expectListTopics(singleton(topic));
    Node node0 = new Node(0, "localhost", 9092);
    Node node1 = new Node(1, "localhost", 9093);
    Node node5 = new Node(5, "localhost", 9097);
    TopicPartitionInfo partition0 = new TopicPartitionInfo(0, node0, Arrays.asList(node0, node1), Arrays.asList(node0, node1));
    TopicPartitionInfo partition1 = new TopicPartitionInfo(1, node1, Arrays.asList(node1, node5), Arrays.asList(node1, node5));
    TopicDescription description = new TopicDescription(topic, false, Arrays.asList(partition0, partition1));
    expectDescribeTopics(singletonMap(topic, description));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(emptyMap()));
    Mockito.when(admin.describeProducers(Collections.singletonList(new TopicPartition(topic, 1)), new DescribeProducersOptions().brokerId(brokerId))).thenReturn(result);
    execute(args);
    assertNormalExit();
    assertNoHangingTransactions();
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DescribeProducersResult

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

the class TransactionsCommandTest method testNewBrokerAbortTransaction.

@Test
public void testNewBrokerAbortTransaction() throws Exception {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    long startOffset = 9173;
    long producerId = 12345L;
    short producerEpoch = 15;
    int coordinatorEpoch = 76;
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "abort", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()), "--start-offset", String.valueOf(startOffset) };
    DescribeProducersResult describeResult = Mockito.mock(DescribeProducersResult.class);
    KafkaFuture<PartitionProducerState> describeFuture = completedFuture(new PartitionProducerState(singletonList(new ProducerState(producerId, producerEpoch, 1300, 1599509565L, OptionalInt.of(coordinatorEpoch), OptionalLong.of(startOffset)))));
    AbortTransactionResult abortTransactionResult = Mockito.mock(AbortTransactionResult.class);
    KafkaFuture<Void> abortFuture = completedFuture(null);
    AbortTransactionSpec expectedAbortSpec = new AbortTransactionSpec(topicPartition, producerId, producerEpoch, coordinatorEpoch);
    Mockito.when(describeResult.partitionResult(topicPartition)).thenReturn(describeFuture);
    Mockito.when(admin.describeProducers(singleton(topicPartition))).thenReturn(describeResult);
    Mockito.when(abortTransactionResult.all()).thenReturn(abortFuture);
    Mockito.when(admin.abortTransaction(expectedAbortSpec)).thenReturn(abortTransactionResult);
    execute(args);
    assertNormalExit();
}
Also used : AbortTransactionSpec(org.apache.kafka.clients.admin.AbortTransactionSpec) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) AbortTransactionResult(org.apache.kafka.clients.admin.AbortTransactionResult) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) TopicPartition(org.apache.kafka.common.TopicPartition) ProducerState(org.apache.kafka.clients.admin.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DescribeProducersResult

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

the class TransactionsCommandTest method testFindHangingLookupTopicPartitionsForTopic.

@Test
public void testFindHangingLookupTopicPartitionsForTopic() throws Exception {
    String topic = "foo";
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--topic", topic };
    Node node0 = new Node(0, "localhost", 9092);
    Node node1 = new Node(1, "localhost", 9093);
    Node node5 = new Node(5, "localhost", 9097);
    TopicPartitionInfo partition0 = new TopicPartitionInfo(0, node0, Arrays.asList(node0, node1), Arrays.asList(node0, node1));
    TopicPartitionInfo partition1 = new TopicPartitionInfo(1, node1, Arrays.asList(node1, node5), Arrays.asList(node1, node5));
    TopicDescription description = new TopicDescription(topic, false, Arrays.asList(partition0, partition1));
    expectDescribeTopics(singletonMap(topic, description));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(emptyMap()));
    Mockito.when(admin.describeProducers(Arrays.asList(new TopicPartition(topic, 0), new TopicPartition(topic, 1)), new DescribeProducersOptions())).thenReturn(result);
    execute(args);
    assertNormalExit();
    assertNoHangingTransactions();
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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