use of org.apache.kafka.common.message.ListTransactionsResponseData in project kafka by apache.
the class RequestResponseTest method createListTransactionsResponse.
private ListTransactionsResponse createListTransactionsResponse() {
ListTransactionsResponseData response = new ListTransactionsResponseData();
response.setErrorCode(Errors.NONE.code());
response.setTransactionStates(asList(new ListTransactionsResponseData.TransactionState().setTransactionalId("foo").setProducerId(12345L).setTransactionState("Ongoing"), new ListTransactionsResponseData.TransactionState().setTransactionalId("bar").setProducerId(98765L).setTransactionState("PrepareAbort")));
return new ListTransactionsResponse(response);
}
use of org.apache.kafka.common.message.ListTransactionsResponseData 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.message.ListTransactionsResponseData 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);
}
use of org.apache.kafka.common.message.ListTransactionsResponseData in project kafka by apache.
the class ListTransactionsRequest method getErrorResponse.
@Override
public ListTransactionsResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
ListTransactionsResponseData response = new ListTransactionsResponseData().setErrorCode(error.code()).setThrottleTimeMs(throttleTimeMs);
return new ListTransactionsResponse(response);
}
Aggregations