use of org.apache.kafka.clients.admin.DescribeTransactionsResult in project kafka by apache.
the class TransactionsCommandTest method expectDescribeTransactions.
private void expectDescribeTransactions(Map<String, TransactionDescription> descriptions) {
DescribeTransactionsResult result = Mockito.mock(DescribeTransactionsResult.class);
descriptions.forEach((transactionalId, description) -> {
Mockito.when(result.description(transactionalId)).thenReturn(completedFuture(description));
});
Mockito.when(result.all()).thenReturn(completedFuture(descriptions));
Mockito.when(admin.describeTransactions(descriptions.keySet())).thenReturn(result);
}
use of org.apache.kafka.clients.admin.DescribeTransactionsResult in project kafka by apache.
the class TransactionsCommandTest method testDescribeTransaction.
@Test
public void testDescribeTransaction() throws Exception {
String transactionalId = "foo";
String[] args = new String[] { "--bootstrap-server", "localhost:9092", "describe", "--transactional-id", transactionalId };
DescribeTransactionsResult describeResult = Mockito.mock(DescribeTransactionsResult.class);
int coordinatorId = 5;
long transactionStartTime = time.milliseconds();
KafkaFuture<TransactionDescription> describeFuture = completedFuture(new TransactionDescription(coordinatorId, TransactionState.ONGOING, 12345L, 15, 10000, OptionalLong.of(transactionStartTime), singleton(new TopicPartition("bar", 0))));
Mockito.when(describeResult.description(transactionalId)).thenReturn(describeFuture);
Mockito.when(admin.describeTransactions(singleton(transactionalId))).thenReturn(describeResult);
// Add a little time so that we can see a positive transaction duration in the output
time.sleep(5000);
execute(args);
assertNormalExit();
List<List<String>> table = readOutputAsTable();
assertEquals(2, table.size());
List<String> expectedHeaders = asList(TransactionsCommand.DescribeTransactionsCommand.HEADERS);
assertEquals(expectedHeaders, table.get(0));
List<String> expectedRow = asList(String.valueOf(coordinatorId), transactionalId, "12345", "15", "Ongoing", "10000", String.valueOf(transactionStartTime), "5000", "bar-0");
assertEquals(expectedRow, table.get(1));
}
use of org.apache.kafka.clients.admin.DescribeTransactionsResult 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);
}
Aggregations