use of org.apache.kafka.common.requests.ListTransactionsRequest 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());
}
use of org.apache.kafka.common.requests.ListTransactionsRequest in project kafka by apache.
the class KafkaAdminClientTest method testListTransactions.
@Test
public void testListTransactions() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
MetadataResponseData.MetadataResponseBrokerCollection brokers = new MetadataResponseData.MetadataResponseBrokerCollection();
env.cluster().nodes().forEach(node -> {
brokers.add(new MetadataResponseData.MetadataResponseBroker().setHost(node.host()).setNodeId(node.id()).setPort(node.port()).setRack(node.rack()));
});
env.kafkaClient().prepareResponse(request -> request instanceof MetadataRequest, new MetadataResponse(new MetadataResponseData().setBrokers(brokers), MetadataResponseData.HIGHEST_SUPPORTED_VERSION));
List<TransactionListing> expected = Arrays.asList(new TransactionListing("foo", 12345L, TransactionState.ONGOING), new TransactionListing("bar", 98765L, TransactionState.PREPARE_ABORT), new TransactionListing("baz", 13579L, TransactionState.COMPLETE_COMMIT));
assertEquals(Utils.mkSet(0, 1, 2), env.cluster().nodes().stream().map(Node::id).collect(Collectors.toSet()));
env.cluster().nodes().forEach(node -> {
ListTransactionsResponseData response = new ListTransactionsResponseData().setErrorCode(Errors.NONE.code());
TransactionListing listing = expected.get(node.id());
response.transactionStates().add(new ListTransactionsResponseData.TransactionState().setTransactionalId(listing.transactionalId()).setProducerId(listing.producerId()).setTransactionState(listing.state().toString()));
env.kafkaClient().prepareResponseFrom(request -> request instanceof ListTransactionsRequest, new ListTransactionsResponse(response), node);
});
ListTransactionsResult result = env.adminClient().listTransactions();
assertEquals(new HashSet<>(expected), new HashSet<>(result.all().get()));
}
}
use of org.apache.kafka.common.requests.ListTransactionsRequest 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.common.requests.ListTransactionsRequest 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());
}
Aggregations