Search in sources :

Example 6 with DisconnectException

use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.

the class AllBrokersStrategyIntegrationTest method testRetryLookupAfterDisconnect.

@Test
public void testRetryLookupAfterDisconnect() {
    AllBrokersStrategy.AllBrokersFuture<Integer> result = new AllBrokersStrategy.AllBrokersFuture<>();
    AdminApiDriver<AllBrokersStrategy.BrokerKey, Integer> driver = buildDriver(result);
    List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> requestSpecs = driver.poll();
    assertEquals(1, requestSpecs.size());
    AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> spec = requestSpecs.get(0);
    assertEquals(AllBrokersStrategy.LOOKUP_KEYS, spec.keys);
    driver.onFailure(time.milliseconds(), spec, new DisconnectException());
    List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> retrySpecs = driver.poll();
    assertEquals(1, retrySpecs.size());
    AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> retrySpec = retrySpecs.get(0);
    assertEquals(AllBrokersStrategy.LOOKUP_KEYS, retrySpec.keys);
    assertEquals(time.milliseconds(), retrySpec.nextAllowedTryMs);
    assertEquals(Collections.emptyList(), driver.poll());
}
Also used : DisconnectException(org.apache.kafka.common.errors.DisconnectException) Test(org.junit.jupiter.api.Test)

Example 7 with DisconnectException

use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.

the class ConsumerCoordinatorTest method testCoordinatorUnknownInUnsentCallbacksAfterCoordinatorDead.

@Test
public void testCoordinatorUnknownInUnsentCallbacksAfterCoordinatorDead() {
    // When the coordinator is marked dead, all unsent or in-flight requests are cancelled
    // with a disconnect error. This test case ensures that the corresponding callbacks see
    // the coordinator as unknown which prevents additional retries to the same coordinator.
    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));
    final AtomicBoolean asyncCallbackInvoked = new AtomicBoolean(false);
    OffsetCommitRequestData offsetCommitRequestData = new OffsetCommitRequestData().setGroupId(groupId).setTopics(Collections.singletonList(new OffsetCommitRequestData.OffsetCommitRequestTopic().setName("foo").setPartitions(Collections.singletonList(new OffsetCommitRequestData.OffsetCommitRequestPartition().setPartitionIndex(0).setCommittedLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH).setCommittedMetadata("").setCommittedOffset(13L).setCommitTimestamp(0)))));
    consumerClient.send(coordinator.checkAndGetCoordinator(), new OffsetCommitRequest.Builder(offsetCommitRequestData)).compose(new RequestFutureAdapter<ClientResponse, Object>() {

        @Override
        public void onSuccess(ClientResponse value, RequestFuture<Object> future) {
        }

        @Override
        public void onFailure(RuntimeException e, RequestFuture<Object> future) {
            assertTrue(e instanceof DisconnectException, "Unexpected exception type: " + e.getClass());
            assertTrue(coordinator.coordinatorUnknown());
            asyncCallbackInvoked.set(true);
        }
    });
    coordinator.markCoordinatorUnknown("test cause");
    consumerClient.pollNoWakeup();
    assertTrue(asyncCallbackInvoked.get());
}
Also used : ClientResponse(org.apache.kafka.clients.ClientResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OffsetCommitRequestData(org.apache.kafka.common.message.OffsetCommitRequestData) DisconnectException(org.apache.kafka.common.errors.DisconnectException) Test(org.junit.jupiter.api.Test)

Example 8 with DisconnectException

use of org.apache.kafka.common.errors.DisconnectException in project ksql by confluentinc.

the class KafkaTopicClientImplTest method shouldRetryAddingTopicConfig.

@Test
public void shouldRetryAddingTopicConfig() {
    final Map<String, ?> overrides = ImmutableMap.of(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT);
    expect(adminClient.describeConfigs(anyObject())).andReturn(topicConfigResponse("peter", overriddenConfigEntry(TopicConfig.RETENTION_MS_CONFIG, "12345"), defaultConfigEntry(TopicConfig.COMPRESSION_TYPE_CONFIG, "snappy")));
    expect(adminClient.alterConfigs(anyObject())).andReturn(alterTopicConfigResponse(new DisconnectException())).andReturn(alterTopicConfigResponse());
    replay(adminClient);
    KafkaTopicClient kafkaTopicClient = new KafkaTopicClientImpl(adminClient);
    kafkaTopicClient.addTopicConfig("peter", overrides);
    verify(adminClient);
}
Also used : DisconnectException(org.apache.kafka.common.errors.DisconnectException) Test(org.junit.Test)

Example 9 with DisconnectException

use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.

the class ConsumerCoordinatorTest method testManyInFlightAsyncCommitsWithCoordinatorDisconnect.

@Test
public void testManyInFlightAsyncCommitsWithCoordinatorDisconnect() {
    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));
    int numRequests = 1000;
    TopicPartition tp = new TopicPartition("foo", 0);
    final AtomicInteger responses = new AtomicInteger(0);
    for (int i = 0; i < numRequests; i++) {
        Map<TopicPartition, OffsetAndMetadata> offsets = singletonMap(tp, new OffsetAndMetadata(i));
        coordinator.commitOffsetsAsync(offsets, (offsets1, exception) -> {
            responses.incrementAndGet();
            Throwable cause = exception.getCause();
            assertTrue(cause instanceof DisconnectException, "Unexpected exception cause type: " + (cause == null ? null : cause.getClass()));
        });
    }
    coordinator.markCoordinatorUnknown("test cause");
    consumerClient.pollNoWakeup();
    coordinator.invokeCompletedOffsetCommitCallbacks();
    assertEquals(numRequests, responses.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) DisconnectException(org.apache.kafka.common.errors.DisconnectException) Test(org.junit.jupiter.api.Test)

Example 10 with DisconnectException

use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.

the class AdminApiDriverTest method testRetryLookupAfterDisconnect.

@Test
public void testRetryLookupAfterDisconnect() {
    TestContext ctx = TestContext.dynamicMapped(map("foo", "c1"));
    int initialLeaderId = 1;
    Map<Set<String>, LookupResult<String>> initialLookup = map(mkSet("foo"), mapped("foo", initialLeaderId));
    ctx.poll(initialLookup, emptyMap());
    assertMappedKey(ctx, "foo", initialLeaderId);
    ctx.handler.expectRequest(mkSet("foo"), completed("foo", 15L));
    List<RequestSpec<String>> requestSpecs = ctx.driver.poll();
    assertEquals(1, requestSpecs.size());
    RequestSpec<String> requestSpec = requestSpecs.get(0);
    assertEquals(OptionalInt.of(initialLeaderId), requestSpec.scope.destinationBrokerId());
    ctx.driver.onFailure(ctx.time.milliseconds(), requestSpec, new DisconnectException());
    assertUnmappedKey(ctx, "foo");
    int retryLeaderId = 2;
    ctx.lookupStrategy().expectLookup(mkSet("foo"), mapped("foo", retryLeaderId));
    List<RequestSpec<String>> retryLookupSpecs = ctx.driver.poll();
    assertEquals(1, retryLookupSpecs.size());
    RequestSpec<String> retryLookupSpec = retryLookupSpecs.get(0);
    assertEquals(ctx.time.milliseconds(), retryLookupSpec.nextAllowedTryMs);
    assertEquals(1, retryLookupSpec.tries);
}
Also used : HashSet(java.util.HashSet) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) LookupResult(org.apache.kafka.clients.admin.internals.AdminApiLookupStrategy.LookupResult) RequestSpec(org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec) DisconnectException(org.apache.kafka.common.errors.DisconnectException) Test(org.junit.jupiter.api.Test)

Aggregations

DisconnectException (org.apache.kafka.common.errors.DisconnectException)10 Test (org.junit.jupiter.api.Test)6 Test (org.junit.Test)4 TopicPartition (org.apache.kafka.common.TopicPartition)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClientResponse (org.apache.kafka.clients.ClientResponse)2 RequestSpec (org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec)2 LookupResult (org.apache.kafka.clients.admin.internals.AdminApiLookupStrategy.LookupResult)2 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)2 Utils.mkSet (org.apache.kafka.common.utils.Utils.mkSet)2 TimeoutException (java.util.concurrent.TimeoutException)1 ApiResult (org.apache.kafka.clients.admin.internals.AdminApiHandler.ApiResult)1 CommitFailedException (org.apache.kafka.clients.consumer.CommitFailedException)1 OffsetCommitCallback (org.apache.kafka.clients.consumer.OffsetCommitCallback)1 RetriableCommitFailedException (org.apache.kafka.clients.consumer.RetriableCommitFailedException)1 KafkaException (org.apache.kafka.common.KafkaException)1 Node (org.apache.kafka.common.Node)1