sijie closed pull request #1649: Issue 1630: 
TestHttpService#testWhoIsAuditorService is flaky
URL: https://github.com/apache/bookkeeper/pull/1649
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 8cdf3b3657..1ea179c7b2 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.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 void process(WatchedEvent event) {
         }
     }
 
-    public void start() {
+    public Future<?> start() {
         running.set(true);
-        submitElectionTask();
+        return submitElectionTask();
     }
 
     /**
@@ -242,7 +243,7 @@ public void run() {
      * Auditor.
      */
     @VisibleForTesting
-    void submitElectionTask() {
+    Future<?> submitElectionTask() {
 
         Runnable r = new Runnable() {
                 public void run() {
@@ -302,7 +303,7 @@ public void run() {
                     }
                 }
             };
-        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 bc57424915..d14b8a4f9e 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.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 void testRecoveryBookieService() throws Exception {
 
     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 @@ private void startAuditorElector() throws Exception {
         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 void testTriggerAuditService() throws Exception {
 
     @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);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to