Search in sources :

Example 6 with FindCoordinatorResponseData

use of org.apache.kafka.common.message.FindCoordinatorResponseData in project kafka by apache.

the class CoordinatorStrategyTest method testSuccessfulOldCoordinatorLookup.

@Test
public void testSuccessfulOldCoordinatorLookup() {
    CoordinatorKey group = CoordinatorKey.byGroupId("foo");
    FindCoordinatorResponseData responseData = new FindCoordinatorResponseData().setErrorCode(Errors.NONE.code()).setHost("localhost").setPort(9092).setNodeId(1);
    AdminApiLookupStrategy.LookupResult<CoordinatorKey> result = runOldLookup(group, responseData);
    assertEquals(singletonMap(group, 1), result.mappedKeys);
    assertEquals(emptyMap(), result.failedKeys);
}
Also used : FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData) Test(org.junit.jupiter.api.Test)

Example 7 with FindCoordinatorResponseData

use of org.apache.kafka.common.message.FindCoordinatorResponseData in project kafka by apache.

the class CoordinatorStrategyTest method testHandleOldResponseRequiresOneKey.

@Test
public void testHandleOldResponseRequiresOneKey() {
    FindCoordinatorResponseData responseData = new FindCoordinatorResponseData().setErrorCode(Errors.NONE.code());
    FindCoordinatorResponse response = new FindCoordinatorResponse(responseData);
    CoordinatorStrategy strategy = new CoordinatorStrategy(CoordinatorType.GROUP, new LogContext());
    strategy.disableBatch();
    assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(Collections.emptySet(), response));
    CoordinatorKey group1 = CoordinatorKey.byGroupId("foo");
    CoordinatorKey group2 = CoordinatorKey.byGroupId("bar");
    assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(mkSet(group1, group2), response));
}
Also used : FindCoordinatorResponse(org.apache.kafka.common.requests.FindCoordinatorResponse) LogContext(org.apache.kafka.common.utils.LogContext) FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData) Test(org.junit.jupiter.api.Test)

Example 8 with FindCoordinatorResponseData

use of org.apache.kafka.common.message.FindCoordinatorResponseData in project kafka by apache.

the class CoordinatorStrategyTest method assertFatalLookup.

public Throwable assertFatalLookup(CoordinatorKey key, Errors error) {
    FindCoordinatorResponseData responseData = new FindCoordinatorResponseData().setCoordinators(Collections.singletonList(new FindCoordinatorResponseData.Coordinator().setKey(key.idValue).setErrorCode(error.code())));
    AdminApiLookupStrategy.LookupResult<CoordinatorKey> result = runLookup(singleton(key), responseData);
    assertEquals(emptyMap(), result.mappedKeys);
    assertEquals(singleton(key), result.failedKeys.keySet());
    Throwable throwable = result.failedKeys.get(key);
    assertTrue(error.exception().getClass().isInstance(throwable));
    return throwable;
}
Also used : FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData)

Example 9 with FindCoordinatorResponseData

use of org.apache.kafka.common.message.FindCoordinatorResponseData in project kafka by apache.

the class CoordinatorStrategyTest method testSuccessfulCoordinatorLookup.

@Test
public void testSuccessfulCoordinatorLookup() {
    CoordinatorKey group1 = CoordinatorKey.byGroupId("foo");
    CoordinatorKey group2 = CoordinatorKey.byGroupId("bar");
    FindCoordinatorResponseData responseData = new FindCoordinatorResponseData().setCoordinators(Arrays.asList(new FindCoordinatorResponseData.Coordinator().setKey("foo").setErrorCode(Errors.NONE.code()).setHost("localhost").setPort(9092).setNodeId(1), new FindCoordinatorResponseData.Coordinator().setKey("bar").setErrorCode(Errors.NONE.code()).setHost("localhost").setPort(9092).setNodeId(2)));
    AdminApiLookupStrategy.LookupResult<CoordinatorKey> result = runLookup(new HashSet<>(Arrays.asList(group1, group2)), responseData);
    Map<CoordinatorKey, Integer> expectedResult = new HashMap<>();
    expectedResult.put(group1, 1);
    expectedResult.put(group2, 2);
    assertEquals(expectedResult, result.mappedKeys);
    assertEquals(emptyMap(), result.failedKeys);
}
Also used : HashMap(java.util.HashMap) FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData) Test(org.junit.jupiter.api.Test)

Example 10 with FindCoordinatorResponseData

use of org.apache.kafka.common.message.FindCoordinatorResponseData in project kafka by apache.

the class CoordinatorStrategyTest method testRetriableOldCoordinatorLookup.

private void testRetriableOldCoordinatorLookup(Errors error) {
    CoordinatorKey group = CoordinatorKey.byGroupId("foo");
    FindCoordinatorResponseData responseData = new FindCoordinatorResponseData().setErrorCode(error.code());
    AdminApiLookupStrategy.LookupResult<CoordinatorKey> result = runOldLookup(group, responseData);
    assertEquals(emptyMap(), result.failedKeys);
    assertEquals(emptyMap(), result.mappedKeys);
}
Also used : FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData)

Aggregations

FindCoordinatorResponseData (org.apache.kafka.common.message.FindCoordinatorResponseData)12 Test (org.junit.jupiter.api.Test)4 Coordinator (org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator)2 FindCoordinatorResponse (org.apache.kafka.common.requests.FindCoordinatorResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Cluster (org.apache.kafka.common.Cluster)1 Node (org.apache.kafka.common.Node)1 DescribeTransactionsResponseData (org.apache.kafka.common.message.DescribeTransactionsResponseData)1 Errors (org.apache.kafka.common.protocol.Errors)1 DescribeTransactionsRequest (org.apache.kafka.common.requests.DescribeTransactionsRequest)1 DescribeTransactionsResponse (org.apache.kafka.common.requests.DescribeTransactionsResponse)1 FindCoordinatorRequest (org.apache.kafka.common.requests.FindCoordinatorRequest)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockTime (org.apache.kafka.common.utils.MockTime)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1