Search in sources :

Example 1 with NoBatchedFindCoordinatorsException

use of org.apache.kafka.common.requests.FindCoordinatorRequest.NoBatchedFindCoordinatorsException in project kafka by apache.

the class AdminApiDriverTest method testRetryLookupAndDisableBatchAfterNoBatchedFindCoordinatorsException.

@Test
public void testRetryLookupAndDisableBatchAfterNoBatchedFindCoordinatorsException() {
    MockTime time = new MockTime();
    LogContext lc = new LogContext();
    Set<String> groupIds = new HashSet<>(Arrays.asList("g1", "g2"));
    DeleteConsumerGroupsHandler handler = new DeleteConsumerGroupsHandler(lc);
    AdminApiFuture<CoordinatorKey, Void> future = AdminApiFuture.forKeys(groupIds.stream().map(g -> CoordinatorKey.byGroupId(g)).collect(Collectors.toSet()));
    AdminApiDriver<CoordinatorKey, Void> driver = new AdminApiDriver<>(handler, future, time.milliseconds() + API_TIMEOUT_MS, RETRY_BACKOFF_MS, new LogContext());
    assertTrue(((CoordinatorStrategy) handler.lookupStrategy()).batch);
    List<RequestSpec<CoordinatorKey>> requestSpecs = driver.poll();
    // Expect CoordinatorStrategy to try resolving all coordinators in a single request
    assertEquals(1, requestSpecs.size());
    RequestSpec<CoordinatorKey> requestSpec = requestSpecs.get(0);
    driver.onFailure(time.milliseconds(), requestSpec, new NoBatchedFindCoordinatorsException("message"));
    assertFalse(((CoordinatorStrategy) handler.lookupStrategy()).batch);
    // Batching is now disabled, so we now have a request per groupId
    List<RequestSpec<CoordinatorKey>> retryLookupSpecs = driver.poll();
    assertEquals(groupIds.size(), retryLookupSpecs.size());
    // These new requests are treated a new requests and not retries
    for (RequestSpec<CoordinatorKey> retryLookupSpec : retryLookupSpecs) {
        assertEquals(0, retryLookupSpec.nextAllowedTryMs);
        assertEquals(0, retryLookupSpec.tries);
    }
}
Also used : NoBatchedFindCoordinatorsException(org.apache.kafka.common.requests.FindCoordinatorRequest.NoBatchedFindCoordinatorsException) LogContext(org.apache.kafka.common.utils.LogContext) RequestSpec(org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec) MockTime(org.apache.kafka.common.utils.MockTime) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

HashSet (java.util.HashSet)1 RequestSpec (org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec)1 NoBatchedFindCoordinatorsException (org.apache.kafka.common.requests.FindCoordinatorRequest.NoBatchedFindCoordinatorsException)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockTime (org.apache.kafka.common.utils.MockTime)1 Test (org.junit.jupiter.api.Test)1