You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/09/05 19:08:29 UTC
[bookkeeper] branch branch-4.7 updated: ISSUE #1630:
TestHttpService#testWhoIsAuditorService is flaky
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch branch-4.7
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.7 by this push:
new 53294f4 ISSUE #1630: TestHttpService#testWhoIsAuditorService is flaky
53294f4 is described below
commit 53294f4a13130ce7efded5648bbf413d5f37d6cb
Author: Qi Wang <co...@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 <co...@gmail.com>
Reviewers: Ivan Kelly <iv...@apache.org>, Enrico Olivelli <eo...@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 1ed1a22..9f014e2 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
@@ -30,6 +30,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;
@@ -585,7 +586,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)
@@ -596,7 +597,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 {
@@ -627,7 +628,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);