use of org.apache.kafka.common.utils.Time in project kafka by apache.
the class RetryTest method test.
@Test
public void test() throws ExecutionException {
Exception[] attempts = new Exception[] { new IOException("pretend connect error"), new IOException("pretend timeout error"), new IOException("pretend read error"), // success!
null };
long retryWaitMs = 1000;
long maxWaitMs = 10000;
Retryable<String> call = createRetryable(attempts);
Time time = new MockTime(0, 0, 0);
assertEquals(0L, time.milliseconds());
Retry<String> r = new Retry<>(time, retryWaitMs, maxWaitMs);
r.execute(call);
long secondWait = retryWaitMs * 2;
long thirdWait = retryWaitMs * 4;
long totalWait = retryWaitMs + secondWait + thirdWait;
assertEquals(totalWait, time.milliseconds());
}
use of org.apache.kafka.common.utils.Time in project kafka by apache.
the class RetryTest method testIOExceptionFailure.
@Test
public void testIOExceptionFailure() {
Exception[] attempts = new Exception[] { new IOException("pretend connect error"), new IOException("pretend timeout error"), new IOException("pretend read error"), new IOException("pretend another read error") };
long retryWaitMs = 1000;
long maxWaitMs = 1000 + 2000 + 3999;
Retryable<String> call = createRetryable(attempts);
Time time = new MockTime(0, 0, 0);
assertEquals(0L, time.milliseconds());
Retry<String> r = new Retry<>(time, retryWaitMs, maxWaitMs);
assertThrows(ExecutionException.class, () -> r.execute(call));
assertEquals(maxWaitMs, time.milliseconds());
}
use of org.apache.kafka.common.utils.Time in project kafka by apache.
the class RetryTest method testUseMaxTimeout.
@Test
public void testUseMaxTimeout() throws IOException {
Exception[] attempts = new Exception[] { new IOException("pretend connect error"), new IOException("pretend timeout error"), new IOException("pretend read error") };
long retryWaitMs = 5000;
long maxWaitMs = 5000;
Retryable<String> call = createRetryable(attempts);
Time time = new MockTime(0, 0, 0);
assertEquals(0L, time.milliseconds());
Retry<String> r = new Retry<>(time, retryWaitMs, maxWaitMs);
assertThrows(ExecutionException.class, () -> r.execute(call));
assertEquals(maxWaitMs, time.milliseconds());
}
use of org.apache.kafka.common.utils.Time in project kafka by apache.
the class KafkaAdminClientTest method testListConsumerGroupsMetadataFailure.
@Test
public void testListConsumerGroupsMetadataFailure() throws Exception {
final Cluster cluster = mockCluster(3, 0);
final Time time = new MockTime();
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster, AdminClientConfig.RETRIES_CONFIG, "0")) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
// Empty metadata causes the request to fail since we have no list of brokers
// to send the ListGroups requests to
env.kafkaClient().prepareResponse(RequestTestUtils.metadataResponse(Collections.emptyList(), env.cluster().clusterResource().clusterId(), -1, Collections.emptyList()));
final ListConsumerGroupsResult result = env.adminClient().listConsumerGroups();
TestUtils.assertFutureError(result.all(), KafkaException.class);
}
}
use of org.apache.kafka.common.utils.Time in project kafka by apache.
the class KafkaAdminClientTest method testDeleteConsumerGroupOffsetsNumRetries.
@Test
public void testDeleteConsumerGroupOffsetsNumRetries() throws Exception {
final Cluster cluster = mockCluster(3, 0);
final Time time = new MockTime();
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster, AdminClientConfig.RETRIES_CONFIG, "0")) {
final TopicPartition tp1 = new TopicPartition("foo", 0);
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
env.kafkaClient().prepareResponse(prepareOffsetDeleteResponse(Errors.NOT_COORDINATOR));
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
final DeleteConsumerGroupOffsetsResult result = env.adminClient().deleteConsumerGroupOffsets(GROUP_ID, Stream.of(tp1).collect(Collectors.toSet()));
TestUtils.assertFutureError(result.all(), TimeoutException.class);
}
}
Aggregations