Search in sources :

Example 1 with ListTransactionsResponseData

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);
}
Also used : ListTransactionsResponseData(org.apache.kafka.common.message.ListTransactionsResponseData)

Example 2 with ListTransactionsResponseData

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()));
    }
}
Also used : Node(org.apache.kafka.common.Node) MetadataRequest(org.apache.kafka.common.requests.MetadataRequest) ListTransactionsRequest(org.apache.kafka.common.requests.ListTransactionsRequest) ListTransactionsResponse(org.apache.kafka.common.requests.ListTransactionsResponse) MetadataResponseData(org.apache.kafka.common.message.MetadataResponseData) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) ListTransactionsResponseData(org.apache.kafka.common.message.ListTransactionsResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with ListTransactionsResponseData

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);
}
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)

Example 4 with ListTransactionsResponseData

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) ListTransactionsResponseData(org.apache.kafka.common.message.ListTransactionsResponseData)

Aggregations

ListTransactionsResponseData (org.apache.kafka.common.message.ListTransactionsResponseData)4 ListTransactionsResponse (org.apache.kafka.common.requests.ListTransactionsResponse)2 ListTransactionsOptions (org.apache.kafka.clients.admin.ListTransactionsOptions)1 BrokerKey (org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey)1 Node (org.apache.kafka.common.Node)1 MetadataResponseData (org.apache.kafka.common.message.MetadataResponseData)1 Errors (org.apache.kafka.common.protocol.Errors)1 ListTransactionsRequest (org.apache.kafka.common.requests.ListTransactionsRequest)1 MetadataRequest (org.apache.kafka.common.requests.MetadataRequest)1 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1