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