minor fix in distributed lifecycle test case
package com.orientechnologies.orient.server.distributed;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.OPair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Assert;
import org.junit.Test;
@@ -40,6 +45,8 @@ public class DistributedLifecycleListenerIT extends AbstractServerClusterTest
private final List<OPair<String, ODistributedServerManager.DB_STATUS>> changeStatus =
Collections.synchronizedList(
new ArrayList<OPair<String, ODistributedServerManager.DB_STATUS>>());
+ private final CountDownLatch started = new CountDownLatch(SERVERS - 1);
+ private final CountDownLatch ended = new CountDownLatch(SERVERS - 1);
@Override
public boolean onNodeJoining(String iNode) {
@@ -50,11 +57,13 @@ public class DistributedLifecycleListenerIT extends AbstractServerClusterTest
@Override
public void onNodeJoined(String iNode) {
afterNodeJoin.incrementAndGet();
+ started.countDown();
}
@Override
public void onNodeLeft(String iNode) {
nodeLeft.incrementAndGet();
+ ended.countDown();
}
@Override
@@ -87,7 +96,7 @@ public class DistributedLifecycleListenerIT extends AbstractServerClusterTest
@Override
protected void executeTest() throws Exception {
- Thread.sleep(1000);
+ assertTrue(started.await(5, TimeUnit.SECONDS));
}
@Override
@@ -95,13 +104,10 @@ public class DistributedLifecycleListenerIT extends AbstractServerClusterTest
Assert.assertEquals(SERVERS - 1, beforeNodeJoin.get());
Assert.assertEquals(SERVERS - 1, afterNodeJoin.get());
- for (int attempt = 0; attempt < 50; ++attempt) {
- if (nodeLeft.get() >= SERVERS - 1) break;
try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ assertTrue(ended.await(5, TimeUnit.SECONDS));
+ } catch (InterruptedException e1) {
+ fail();
}
Assert.assertEquals(SERVERS - 1, nodeLeft.get());
