From ae4100f82c13b3e6978c0a0f697312bd073e0eb3 Mon Sep 17 00:00:00 2001 From: "Colin P. Mccabe" Date: Sat, 9 Sep 2017 08:33:08 +0100 Subject: [PATCH] KAFKA-5792; Fix Transient failure in KafkaAdminClientTest.testHandleTimeout Author: Colin P. Mccabe Reviewers: Ismael Juma Closes #3822 from cmccabe/KAFKA-5792 --- .../java/org/apache/kafka/clients/admin/KafkaAdminClient.java | 4 ++++ .../org/apache/kafka/clients/admin/KafkaAdminClientTest.java | 2 ++ .../apache/kafka/clients/admin/MockKafkaAdminClientEnv.java | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java b/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java index 49ac93ee139..88d99c3a228 100644 --- a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java +++ b/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java @@ -370,6 +370,10 @@ public class KafkaAdminClient extends AdminClient { thread.start(); } + Time time() { + return time; + } + @Override public void close(long duration, TimeUnit unit) { long waitTimeMs = unit.toMillis(duration); diff --git a/clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java b/clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java index 96f7e8a425a..83416c62e11 100644 --- a/clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java +++ b/clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java @@ -324,6 +324,8 @@ public class KafkaAdminClientTest { env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.emptySet()); env.kafkaClient().setNode(nodes.get(0)); + assertEquals(time, env.time()); + assertEquals(env.time(), ((KafkaAdminClient) env.adminClient()).time()); // Make a request with an extremely short timeout. // Then wait for it to fail by not supplying any response. diff --git a/clients/src/test/java/org/apache/kafka/clients/admin/MockKafkaAdminClientEnv.java b/clients/src/test/java/org/apache/kafka/clients/admin/MockKafkaAdminClientEnv.java index 66484678b32..9190da23947 100644 --- a/clients/src/test/java/org/apache/kafka/clients/admin/MockKafkaAdminClientEnv.java +++ b/clients/src/test/java/org/apache/kafka/clients/admin/MockKafkaAdminClientEnv.java @@ -52,7 +52,7 @@ public class MockKafkaAdminClientEnv implements AutoCloseable { } public MockKafkaAdminClientEnv(Time time, Cluster cluster, Map config) { - this.time = Time.SYSTEM; + this.time = time; this.adminClientConfig = new AdminClientConfig(config); this.cluster = cluster; this.metadata = new Metadata(adminClientConfig.getLong(AdminClientConfig.RETRY_BACKOFF_MS_CONFIG),