Search in sources :

Example 1 with ListTransactionsOptions

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

the class ListTransactionsHandlerTest method testBuildRequestWithFilteredState.

@Test
public void testBuildRequestWithFilteredState() {
    int brokerId = 1;
    BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
    TransactionState filteredState = TransactionState.ONGOING;
    ListTransactionsOptions options = new ListTransactionsOptions().filterStates(singleton(filteredState));
    ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
    ListTransactionsRequest request = handler.buildRequest(brokerId, singleton(brokerKey)).build();
    assertEquals(Collections.singletonList(filteredState.toString()), request.data().stateFilters());
    assertEquals(Collections.emptyList(), request.data().producerIdFilters());
}
Also used : TransactionState(org.apache.kafka.clients.admin.TransactionState) ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsRequest(org.apache.kafka.common.requests.ListTransactionsRequest) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) Test(org.junit.jupiter.api.Test)

Example 2 with ListTransactionsOptions

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

the class TransactionsCommandTest method testFindHangingFilterByTransactionInProgressWithSamePartition.

@Test
public void testFindHangingFilterByTransactionInProgressWithSamePartition() 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)));
    // The coordinator shows an active transaction with the same epoch
    // which includes the partition, so no hanging transaction should
    // be detected.
    TransactionDescription description = new TransactionDescription(1, TransactionState.ONGOING, producerId, producerEpoch, 60000, OptionalLong.of(lastTimestamp), singleton(topicPartition));
    expectDescribeTransactions(singletonMap(transactionalId, description));
    execute(args);
    assertNormalExit();
    assertNoHangingTransactions();
}
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)

Example 3 with ListTransactionsOptions

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

the class TransactionsCommandTest method testFindHangingNoMappedTransactionalId.

@Test
public void testFindHangingNoMappedTransactionalId() 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));
    expectListTransactions(new ListTransactionsOptions().filterProducerIds(singleton(producerId)), singletonMap(1, Collections.emptyList()));
    expectDescribeTransactions(Collections.emptyMap());
    execute(args);
    assertNormalExit();
    assertHangingTransaction(topicPartition, producerId, producerEpoch, coordinatorEpoch, txnStartOffset, lastTimestamp);
}
Also used : ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) TopicPartition(org.apache.kafka.common.TopicPartition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ListTransactionsOptions

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

the class ListTransactionsHandlerTest method testHandleSuccessfulResponse.

@Test
public void testHandleSuccessfulResponse() {
    int brokerId = 1;
    BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
    ListTransactionsOptions options = new ListTransactionsOptions();
    ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
    ListTransactionsResponse response = sampleListTransactionsResponse1();
    ApiResult<BrokerKey, Collection<TransactionListing>> result = handler.handleResponse(node, singleton(brokerKey), response);
    assertEquals(singleton(brokerKey), result.completedKeys.keySet());
    assertExpectedTransactions(response.data().transactionStates(), result.completedKeys.get(brokerKey));
}
Also used : ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsResponse(org.apache.kafka.common.requests.ListTransactionsResponse) Collection(java.util.Collection) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) Test(org.junit.jupiter.api.Test)

Example 5 with ListTransactionsOptions

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

the class ListTransactionsHandlerTest method handleResponseWithError.

private ApiResult<BrokerKey, Collection<TransactionListing>> handleResponseWithError(int brokerId, Errors error) {
    BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
    ListTransactionsOptions options = new ListTransactionsOptions();
    ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
    ListTransactionsResponse response = new ListTransactionsResponse(new ListTransactionsResponseData().setErrorCode(error.code()));
    return handler.handleResponse(node, singleton(brokerKey), response);
}
Also used : ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsResponse(org.apache.kafka.common.requests.ListTransactionsResponse) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) ListTransactionsResponseData(org.apache.kafka.common.message.ListTransactionsResponseData)

Aggregations

ListTransactionsOptions (org.apache.kafka.clients.admin.ListTransactionsOptions)9 Test (org.junit.jupiter.api.Test)8 BrokerKey (org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 TransactionListing (org.apache.kafka.clients.admin.TransactionListing)3 ListTransactionsRequest (org.apache.kafka.common.requests.ListTransactionsRequest)3 TransactionDescription (org.apache.kafka.clients.admin.TransactionDescription)2 ListTransactionsResponse (org.apache.kafka.common.requests.ListTransactionsResponse)2 Collection (java.util.Collection)1 DescribeTransactionsResult (org.apache.kafka.clients.admin.DescribeTransactionsResult)1 TransactionState (org.apache.kafka.clients.admin.TransactionState)1 TransactionalIdNotFoundException (org.apache.kafka.common.errors.TransactionalIdNotFoundException)1 ListTransactionsResponseData (org.apache.kafka.common.message.ListTransactionsResponseData)1