use of org.apache.kafka.common.errors.DisconnectException in project ksql by confluentinc.
the class KafkaTopicClientImplTest method shouldHandleRetriableGetTopicConfigError.
@Test
public void shouldHandleRetriableGetTopicConfigError() {
expect(adminClient.describeConfigs(anyObject())).andReturn(topicConfigResponse(new DisconnectException())).andReturn(topicConfigResponse("fred", overriddenConfigEntry(TopicConfig.RETENTION_MS_CONFIG, "12345"), defaultConfigEntry(TopicConfig.COMPRESSION_TYPE_CONFIG, "producer")));
replay(adminClient);
KafkaTopicClient kafkaTopicClient = new KafkaTopicClientImpl(adminClient);
final Map<String, String> config = kafkaTopicClient.getTopicConfig("fred");
assertThat(config.get(TopicConfig.RETENTION_MS_CONFIG), is("12345"));
assertThat(config.get(TopicConfig.COMPRESSION_TYPE_CONFIG), is("producer"));
}
use of org.apache.kafka.common.errors.DisconnectException in project apache-kafka-on-k8s by banzaicloud.
the class ConsumerCoordinatorTest method testManyInFlightAsyncCommitsWithCoordinatorDisconnect.
@Test
public void testManyInFlightAsyncCommitsWithCoordinatorDisconnect() throws Exception {
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
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, new OffsetCommitCallback() {
@Override
public void onComplete(Map<TopicPartition, OffsetAndMetadata> offsets, Exception exception) {
responses.incrementAndGet();
Throwable cause = exception.getCause();
assertTrue("Unexpected exception cause type: " + (cause == null ? null : cause.getClass()), cause instanceof DisconnectException);
}
});
}
coordinator.markCoordinatorUnknown();
consumerClient.pollNoWakeup();
coordinator.invokeCompletedOffsetCommitCallbacks();
assertEquals(numRequests, responses.get());
}
use of org.apache.kafka.common.errors.DisconnectException in project apache-kafka-on-k8s by banzaicloud.
the class ConsumerCoordinatorTest method testCoordinatorUnknownInUnsentCallbacksAfterCoordinatorDead.
@Test
public void testCoordinatorUnknownInUnsentCallbacksAfterCoordinatorDead() throws Exception {
// 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();
final AtomicBoolean asyncCallbackInvoked = new AtomicBoolean(false);
Map<TopicPartition, OffsetCommitRequest.PartitionData> offsets = singletonMap(new TopicPartition("foo", 0), new OffsetCommitRequest.PartitionData(13L, ""));
consumerClient.send(coordinator.checkAndGetCoordinator(), new OffsetCommitRequest.Builder(groupId, offsets)).compose(new RequestFutureAdapter<ClientResponse, Object>() {
@Override
public void onSuccess(ClientResponse value, RequestFuture<Object> future) {
}
@Override
public void onFailure(RuntimeException e, RequestFuture<Object> future) {
assertTrue("Unexpected exception type: " + e.getClass(), e instanceof DisconnectException);
assertTrue(coordinator.coordinatorUnknown());
asyncCallbackInvoked.set(true);
}
});
coordinator.markCoordinatorUnknown();
consumerClient.pollNoWakeup();
assertTrue(asyncCallbackInvoked.get());
}
use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.
the class AdminApiDriverTest method testCoalescedStaticAndDynamicFulfillment.
@Test
public void testCoalescedStaticAndDynamicFulfillment() {
Map<String, String> dynamicMapping = map("foo", "c1");
Map<String, Integer> staticMapping = map("bar", 1);
TestContext ctx = new TestContext(staticMapping, dynamicMapping);
// Initially we expect a lookup for the dynamic key and a
// fulfillment request for the static key
LookupResult<String> lookupResult = mapped("foo", 1);
ctx.lookupStrategy().expectLookup(mkSet("foo"), lookupResult);
ctx.handler.expectRequest(mkSet("bar"), completed("bar", 10L));
List<RequestSpec<String>> requestSpecs = ctx.driver.poll();
assertEquals(2, requestSpecs.size());
RequestSpec<String> lookupSpec = requestSpecs.get(0);
assertEquals(mkSet("foo"), lookupSpec.keys);
ctx.assertLookupResponse(lookupSpec, lookupResult);
// Receive a disconnect from the fulfillment request so that
// we have an opportunity to coalesce the keys.
RequestSpec<String> fulfillmentSpec = requestSpecs.get(1);
assertEquals(mkSet("bar"), fulfillmentSpec.keys);
ctx.driver.onFailure(ctx.time.milliseconds(), fulfillmentSpec, new DisconnectException());
// Now we should get two fulfillment requests. One of them will
// the coalesced dynamic and static keys for broker 1. The other
// should contain the single dynamic key for broker 0.
ctx.handler.reset();
ctx.handler.expectRequest(mkSet("foo", "bar"), completed("foo", 15L, "bar", 30L));
List<RequestSpec<String>> coalescedSpecs = ctx.driver.poll();
assertEquals(1, coalescedSpecs.size());
RequestSpec<String> coalescedSpec = coalescedSpecs.get(0);
assertEquals(mkSet("foo", "bar"), coalescedSpec.keys);
// Disconnect in order to ensure that only the dynamic key is unmapped.
// Then complete the remaining requests.
ctx.driver.onFailure(ctx.time.milliseconds(), coalescedSpec, new DisconnectException());
Map<Set<String>, LookupResult<String>> fooLookupRetry = map(mkSet("foo"), mapped("foo", 3));
Map<Set<String>, ApiResult<String, Long>> barFulfillmentRetry = map(mkSet("bar"), completed("bar", 30L));
ctx.poll(fooLookupRetry, barFulfillmentRetry);
Map<Set<String>, ApiResult<String, Long>> fooFulfillmentRetry = map(mkSet("foo"), completed("foo", 15L));
ctx.poll(emptyMap(), fooFulfillmentRetry);
ctx.poll(emptyMap(), emptyMap());
}
use of org.apache.kafka.common.errors.DisconnectException in project kafka by apache.
the class AllBrokersStrategyIntegrationTest method testRetryFulfillmentAfterDisconnect.
@Test
public void testRetryFulfillmentAfterDisconnect() throws Exception {
AllBrokersStrategy.AllBrokersFuture<Integer> result = new AllBrokersStrategy.AllBrokersFuture<>();
AdminApiDriver<AllBrokersStrategy.BrokerKey, Integer> driver = buildDriver(result);
List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> lookupSpecs = driver.poll();
assertEquals(1, lookupSpecs.size());
AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> lookupSpec = lookupSpecs.get(0);
int brokerId = 1;
driver.onResponse(time.milliseconds(), lookupSpec, responseWithBrokers(Collections.singleton(brokerId)), Node.noNode());
assertTrue(result.all().isDone());
Map<Integer, KafkaFutureImpl<Integer>> brokerFutures = result.all().get();
KafkaFutureImpl<Integer> future = brokerFutures.get(brokerId);
assertFalse(future.isDone());
List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> requestSpecs = driver.poll();
assertEquals(1, requestSpecs.size());
AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> requestSpec = requestSpecs.get(0);
driver.onFailure(time.milliseconds(), requestSpec, new DisconnectException());
assertFalse(future.isDone());
List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> retrySpecs = driver.poll();
assertEquals(1, retrySpecs.size());
AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> retrySpec = retrySpecs.get(0);
assertEquals(time.milliseconds() + RETRY_BACKOFF_MS, retrySpec.nextAllowedTryMs);
assertEquals(OptionalInt.of(brokerId), retrySpec.scope.destinationBrokerId());
driver.onResponse(time.milliseconds(), retrySpec, null, new Node(brokerId, "host", 1234));
assertTrue(future.isDone());
assertEquals(brokerId, future.get());
assertEquals(Collections.emptyList(), driver.poll());
}
Aggregations