use of org.apache.kafka.clients.admin.ListTransactionsOptions in project kafka by apache.
the class ListTransactionsHandlerTest method testBuildRequestWithFilteredProducerId.
@Test
public void testBuildRequestWithFilteredProducerId() {
int brokerId = 1;
BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
long filteredProducerId = 23423L;
ListTransactionsOptions options = new ListTransactionsOptions().filterProducerIds(singleton(filteredProducerId));
ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
ListTransactionsRequest request = handler.buildRequest(brokerId, singleton(brokerKey)).build();
assertEquals(Collections.singletonList(filteredProducerId), request.data().producerIdFilters());
assertEquals(Collections.emptyList(), request.data().stateFilters());
}
use of org.apache.kafka.clients.admin.ListTransactionsOptions in project kafka by apache.
the class ListTransactionsHandlerTest method testBuildRequestWithoutFilters.
@Test
public void testBuildRequestWithoutFilters() {
int brokerId = 1;
BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
ListTransactionsOptions options = new ListTransactionsOptions();
ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
ListTransactionsRequest request = handler.buildRequest(brokerId, singleton(brokerKey)).build();
assertEquals(Collections.emptyList(), request.data().producerIdFilters());
assertEquals(Collections.emptyList(), request.data().stateFilters());
}
use of org.apache.kafka.clients.admin.ListTransactionsOptions in project kafka by apache.
the class TransactionsCommandTest method testFindHangingWithNoTransactionDescription.
@Test
public void testFindHangingWithNoTransactionDescription() 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)));
DescribeTransactionsResult result = Mockito.mock(DescribeTransactionsResult.class);
Mockito.when(result.description(transactionalId)).thenReturn(failedFuture(new TransactionalIdNotFoundException(transactionalId + " not found")));
Mockito.when(admin.describeTransactions(singleton(transactionalId))).thenReturn(result);
execute(args);
assertNormalExit();
assertHangingTransaction(topicPartition, producerId, producerEpoch, coordinatorEpoch, txnStartOffset, lastTimestamp);
}
use of org.apache.kafka.clients.admin.ListTransactionsOptions 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);
}
Aggregations