Search in sources :

Example 1 with BrokerKey

use of org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey in project kafka by apache.

the class ListTransactionsHandlerTest method assertFatalError.

private void assertFatalError(Errors error) {
    int brokerId = 1;
    BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
    ApiResult<BrokerKey, Collection<TransactionListing>> result = handleResponseWithError(brokerId, error);
    assertEquals(Collections.emptyMap(), result.completedKeys);
    assertEquals(Collections.emptyList(), result.unmappedKeys);
    assertEquals(Collections.singleton(brokerKey), result.failedKeys.keySet());
    Throwable throwable = result.failedKeys.get(brokerKey);
    assertEquals(error, Errors.forException(throwable));
}
Also used : Collection(java.util.Collection) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey)

Example 2 with BrokerKey

use of org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey 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());
}
Also used : TransactionState(org.apache.kafka.clients.admin.TransactionState) ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsRequest(org.apache.kafka.common.requests.ListTransactionsRequest) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) Test(org.junit.jupiter.api.Test)

Example 3 with BrokerKey

use of org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey in project kafka by apache.

the class ListTransactionsHandlerTest method testHandleSuccessfulResponse.

@Test
public void testHandleSuccessfulResponse() {
    int brokerId = 1;
    BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
    ListTransactionsOptions options = new ListTransactionsOptions();
    ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
    ListTransactionsResponse response = sampleListTransactionsResponse1();
    ApiResult<BrokerKey, Collection<TransactionListing>> result = handler.handleResponse(node, singleton(brokerKey), response);
    assertEquals(singleton(brokerKey), result.completedKeys.keySet());
    assertExpectedTransactions(response.data().transactionStates(), result.completedKeys.get(brokerKey));
}
Also used : ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsResponse(org.apache.kafka.common.requests.ListTransactionsResponse) Collection(java.util.Collection) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) Test(org.junit.jupiter.api.Test)

Example 4 with BrokerKey

use of org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey 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 5 with BrokerKey

use of org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey 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());
}
Also used : ListTransactionsOptions(org.apache.kafka.clients.admin.ListTransactionsOptions) ListTransactionsRequest(org.apache.kafka.common.requests.ListTransactionsRequest) BrokerKey(org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey) Test(org.junit.jupiter.api.Test)

Aggregations

BrokerKey (org.apache.kafka.clients.admin.internals.AllBrokersStrategy.BrokerKey)6 ListTransactionsOptions (org.apache.kafka.clients.admin.ListTransactionsOptions)5 Test (org.junit.jupiter.api.Test)4 ListTransactionsRequest (org.apache.kafka.common.requests.ListTransactionsRequest)3 Collection (java.util.Collection)2 ListTransactionsResponse (org.apache.kafka.common.requests.ListTransactionsResponse)2 TransactionState (org.apache.kafka.clients.admin.TransactionState)1 ListTransactionsResponseData (org.apache.kafka.common.message.ListTransactionsResponseData)1