Github user henry-cask commented on a diff in the pull request:
https://github.com/apache/incubator-twill/pull/34#discussion_r30921191
--- Diff:
twill-zookeeper/src/test/java/org/apache/twill/internal/zookeeper/LeaderElectionTest.java
---
@@ -278,6 +279,54 @@ public void follower() {
}
}
+ @Test
+ public void testRace() throws InterruptedException {
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+ final AtomicInteger leaderCount = new AtomicInteger(0);
+ final CountDownLatch completeLatch = new CountDownLatch(2);
+
+ // Starts two threads and try to compete for leader and immediate drop
leadership.
+ // This is to test the case when a follower tries to watch for leader
node, but the leader is already gone
+ for (int i = 0; i < 2; i++) {
+ final ZKClientService zkClient =
ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
+ zkClient.startAndWait();
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < 1000; i++) {
+ final CountDownLatch leaderLatch = new CountDownLatch(1);
--- End diff --
Since the latch is created per thread, what is the latch used for?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---