This is an automated email from the ASF dual-hosted git repository. sijie pushed a commit to branch branch-4.8 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.8 by this push: new 65f02ab ISSUE #1630: TestHttpService#testWhoIsAuditorService is flaky 65f02ab is described below commit 65f02abe97edd478f5fb89a8bc000176d3227ba7 Author: Qi Wang <codingwan...@gmail.com> AuthorDate: Wed Sep 5 12:07:29 2018 -0700 ISSUE #1630: TestHttpService#testWhoIsAuditorService is flaky Descriptions of the changes in this PR: ### Motivation Fixes #1630. The problem is auditor elector was started async, the test itself doesn't wait until election completed. so the test can be running before auditor runs elector. ### Changes The fix is simple, just wait until auditor completes election. Master Issue: #1630 Author: Qi Wang <codingwan...@gmail.com> Reviewers: Ivan Kelly <iv...@apache.org>, Enrico Olivelli <eolive...@gmail.com>, Sijie Guo <si...@apache.org> This closes #1649 from codingwangqi/issue_1630, closes #1630 (cherry picked from commit 18a40787930df990e9e3ac3aad58011dc65b1b9f) Signed-off-by: Sijie Guo <si...@apache.org> --- .../java/org/apache/bookkeeper/replication/AuditorElector.java | 9 +++++---- .../java/org/apache/bookkeeper/server/http/TestHttpService.java | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java index 8cdf3b3..1ea179c 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java @@ -33,6 +33,7 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; @@ -206,9 +207,9 @@ public class AuditorElector { } } - public void start() { + public Future<?> start() { running.set(true); - submitElectionTask(); + return submitElectionTask(); } /** @@ -242,7 +243,7 @@ public class AuditorElector { * Auditor. */ @VisibleForTesting - void submitElectionTask() { + Future<?> submitElectionTask() { Runnable r = new Runnable() { public void run() { @@ -302,7 +303,7 @@ public class AuditorElector { } } }; - executor.submit(r); + return executor.submit(r); } @VisibleForTesting diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/server/http/TestHttpService.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/server/http/TestHttpService.java index d360b1f..5d87ca9 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/server/http/TestHttpService.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/server/http/TestHttpService.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Future; import lombok.Cleanup; import org.apache.bookkeeper.client.BookKeeper; import org.apache.bookkeeper.client.LedgerHandle; @@ -586,7 +587,7 @@ public class TestHttpService extends BookKeeperClusterTestCase { ZooKeeper auditorZookeeper; AuditorElector auditorElector; - private void startAuditorElector() throws Exception { + private Future<?> startAuditorElector() throws Exception { auditorZookeeper = ZooKeeperClient.newBuilder() .connectString(zkUtil.getZooKeeperConnectString()) .sessionTimeoutMs(10000) @@ -597,7 +598,7 @@ public class TestHttpService extends BookKeeperClusterTestCase { conf.setMetadataServiceUri("zk://" + zkUtil.getZooKeeperConnectString() + "/ledgers"); auditorElector = new AuditorElector(addr, conf, auditorZookeeper); - auditorElector.start(); + return auditorElector.start(); } private void stopAuditorElector() throws Exception { @@ -628,7 +629,8 @@ public class TestHttpService extends BookKeeperClusterTestCase { @Test public void testWhoIsAuditorService() throws Exception { - startAuditorElector(); + // start the auditor elector and wait until auditor finishes election. + startAuditorElector().get(); HttpEndpointService whoIsAuditorService = bkHttpServiceProvider .provideHttpEndpointService(HttpServer.ApiType.WHO_IS_AUDITOR);