Search in sources :

Example 1 with AbortTransactionResult

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

the class TransactionsCommandTest method testOldBrokerAbortTransactionWithUnknownCoordinatorEpoch.

@ParameterizedTest
@ValueSource(ints = { 29, -1 })
public void testOldBrokerAbortTransactionWithUnknownCoordinatorEpoch(int coordinatorEpoch) throws Exception {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    long producerId = 12345L;
    short producerEpoch = 15;
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "abort", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()), "--producer-id", String.valueOf(producerId), "--producer-epoch", String.valueOf(producerEpoch), "--coordinator-epoch", String.valueOf(coordinatorEpoch) };
    AbortTransactionResult abortTransactionResult = Mockito.mock(AbortTransactionResult.class);
    KafkaFuture<Void> abortFuture = completedFuture(null);
    final int expectedCoordinatorEpoch;
    if (coordinatorEpoch < 0) {
        expectedCoordinatorEpoch = 0;
    } else {
        expectedCoordinatorEpoch = coordinatorEpoch;
    }
    AbortTransactionSpec expectedAbortSpec = new AbortTransactionSpec(topicPartition, producerId, producerEpoch, expectedCoordinatorEpoch);
    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) TopicPartition(org.apache.kafka.common.TopicPartition) AbortTransactionResult(org.apache.kafka.clients.admin.AbortTransactionResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AbortTransactionResult

use of org.apache.kafka.clients.admin.AbortTransactionResult 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)

Aggregations

AbortTransactionResult (org.apache.kafka.clients.admin.AbortTransactionResult)2 AbortTransactionSpec (org.apache.kafka.clients.admin.AbortTransactionSpec)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 DescribeProducersResult (org.apache.kafka.clients.admin.DescribeProducersResult)1 PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)1 ProducerState (org.apache.kafka.clients.admin.ProducerState)1 Test (org.junit.jupiter.api.Test)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1