Search in sources :

Example 6 with TransactionListing

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

the class TransactionsCommandTest method testFindHangingDoesNotFilterByTransactionInProgressWithDifferentPartitions.

@Test
public void testFindHangingDoesNotFilterByTransactionInProgressWithDifferentPartitions() throws Exception {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()) };
    long producerId = 132L;
    short producerEpoch = 5;
    long lastTimestamp = time.milliseconds() - TimeUnit.MINUTES.toMillis(60);
    int coordinatorEpoch = 19;
    long txnStartOffset = 29384L;
    expectDescribeProducers(topicPartition, producerId, producerEpoch, lastTimestamp, OptionalInt.of(coordinatorEpoch), OptionalLong.of(txnStartOffset));
    String transactionalId = "bar";
    TransactionListing listing = new TransactionListing(transactionalId, producerId, TransactionState.ONGOING);
    expectListTransactions(new ListTransactionsOptions().filterProducerIds(singleton(producerId)), singletonMap(1, Collections.singletonList(listing)));
    // Although there is a transaction in progress from the same
    // producer epoch, it does not include the topic partition we
    // found when describing producers.
    TransactionDescription description = new TransactionDescription(1, TransactionState.ONGOING, producerId, producerEpoch, 60000, OptionalLong.of(time.milliseconds()), singleton(new TopicPartition("foo", 10)));
    expectDescribeTransactions(singletonMap(transactionalId, description));
    execute(args);
    assertNormalExit();
    assertHangingTransaction(topicPartition, producerId, producerEpoch, coordinatorEpoch, txnStartOffset, lastTimestamp);
}
Also used : TransactionDescription(org.apache.kafka.clients.admin.TransactionDescription) ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) TopicPartition(org.apache.kafka.common.TopicPartition) TransactionListing(org.apache.kafka.clients.admin.TransactionListing) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionListing (org.apache.kafka.clients.admin.TransactionListing)6 ListTransactionsOptions (org.apache.kafka.clients.admin.ListTransactionsOptions)4 TopicPartition (org.apache.kafka.common.TopicPartition)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ArrayList (java.util.ArrayList)2 TransactionDescription (org.apache.kafka.clients.admin.TransactionDescription)2 TransactionState (org.apache.kafka.clients.admin.TransactionState)2 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DescribeTransactionsResult (org.apache.kafka.clients.admin.DescribeTransactionsResult)1 ListTransactionsResult (org.apache.kafka.clients.admin.ListTransactionsResult)1 Node (org.apache.kafka.common.Node)1 CoordinatorNotAvailableException (org.apache.kafka.common.errors.CoordinatorNotAvailableException)1 TransactionalIdNotFoundException (org.apache.kafka.common.errors.TransactionalIdNotFoundException)1 ListTransactionsRequestData (org.apache.kafka.common.message.ListTransactionsRequestData)1 ListTransactionsResponseData (org.apache.kafka.common.message.ListTransactionsResponseData)1 Errors (org.apache.kafka.common.protocol.Errors)1