diff --git a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsyncMapTest.java b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsyncMapTest.java
index acc70d73af7..d2653f86d08 100644
--- a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsyncMapTest.java
+++ b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsyncMapTest.java
@@ -19,20 +19,36 @@
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.test.fakecluster.FakeClusterManager;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* @author Tim Fox
*/
public class ClusteredAsyncMapTest extends AsyncMapTest {
- int pos;
+ protected final int numNodes = 3;
+ AtomicInteger pos = new AtomicInteger();
+
+ public void setUp() throws Exception {
+ super.setUp();
+ startNodes(numNodes);
+ }
+
+ @Override
+ protected ClusterManager getClusterManager() {
+ return new FakeClusterManager();
+ }
@Override
protected Vertx getVertx() {
- Vertx vertx = vertices[pos];
- if (++pos == getNumNodes()) {
- pos = 0;
- }
- return vertx;
+ int i = pos.incrementAndGet();
+ i = mod(i, numNodes);
+ return vertices[i];
+ }
+
+ private int mod(int idx, int size) {
+ int i = idx % size;
+ return i < 0 ? i + size : i;
}
@Test
@@ -59,17 +75,4 @@ public void testGetLocalAsyncMap() {
await();
}
- public void setUp() throws Exception {
- super.setUp();
- startNodes(getNumNodes());
- }
-
- protected int getNumNodes() {
- return 2;
- }
-
- @Override
- protected ClusterManager getClusterManager() {
- return new FakeClusterManager();
- }
}
diff --git a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsynchronousLockTest.java b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsynchronousLockTest.java
index a1db8562ba7..1bba8078414 100644
--- a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsynchronousLockTest.java
+++ b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredAsynchronousLockTest.java
@@ -30,19 +30,18 @@
*/
public class ClusteredAsynchronousLockTest extends AsynchronousLockTest {
- @Override
- protected ClusterManager getClusterManager() {
- return new FakeClusterManager();
- }
-
protected final int numNodes = 3;
+ AtomicInteger pos = new AtomicInteger();
public void setUp() throws Exception {
super.setUp();
startNodes(numNodes);
}
- AtomicInteger pos = new AtomicInteger();
+ @Override
+ protected ClusterManager getClusterManager() {
+ return new FakeClusterManager();
+ }
@Override
protected Vertx getVertx() {
diff --git a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredSharedCounterTest.java b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredSharedCounterTest.java
index f7a84a1be09..114208e5496 100644
--- a/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredSharedCounterTest.java
+++ b/vertx-core/src/test/java/io/vertx/tests/shareddata/ClusteredSharedCounterTest.java
@@ -19,21 +19,36 @@
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.test.fakecluster.FakeClusterManager;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* @author Tim Fox
*/
public class ClusteredSharedCounterTest extends SharedCounterTest {
+ protected final int numNodes = 3;
+ AtomicInteger pos = new AtomicInteger();
+
+ public void setUp() throws Exception {
+ super.setUp();
+ startNodes(numNodes);
+ }
+
@Override
protected ClusterManager getClusterManager() {
return new FakeClusterManager();
}
- protected final int numNodes = 2;
+ @Override
+ protected Vertx getVertx() {
+ int i = pos.incrementAndGet();
+ i = mod(i, numNodes);
+ return vertices[i];
+ }
- public void setUp() throws Exception {
- super.setUp();
- startNodes(numNodes);
+ private int mod(int idx, int size) {
+ int i = idx % size;
+ return i < 0 ? i + size : i;
}
@Test
@@ -57,15 +72,4 @@ public void testGetLocalCounter() {
await();
}
- int pos;
- @Override
- protected Vertx getVertx() {
- Vertx vertx = vertices[pos];
- if (++pos == numNodes) {
- pos = 0;
- }
- return vertx;
- }
-
-
}