Faster HZ datastore related unit test.
Unit HZ datastore currently starts in client mode, then
fall back to instance mode, when client fails to connect to hazelcast instance.
This patch attempts to minimize the delay (typically around 5s) to fall back to instance mode.
- When only localhost is specified in hazelcast.xml,
Hazelcast tries to connect to localhost:5701, localhost:5702, localhost:5703 and wait for all of them to fail.
Explicitly specifying the ports to detect failure faster.
- Added a property to specify hazelcast retry behavior.
Setting retry count to 0 for unit testing purpose.
Change-Id: I7713e6e78ef53aa0809c29e0e1fe51682d9f1383
diff --git a/src/test/java/net/onrc/onos/core/datastore/AtomicCounterTest.java b/src/test/java/net/onrc/onos/core/datastore/AtomicCounterTest.java
index 9d451dc..439dd53 100644
--- a/src/test/java/net/onrc/onos/core/datastore/AtomicCounterTest.java
+++ b/src/test/java/net/onrc/onos/core/datastore/AtomicCounterTest.java
@@ -26,14 +26,20 @@
public class AtomicCounterTest {
+ static {
+ // configuration to quickly fall back to instance mode for faster test run
+ System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
+ }
+
private static final String TEST_COUNTER = "TestCounter";
private static final byte[] LONG_ZERO = {0, 0, 0, 0, 0, 0, 0, 0}; // 0L
- private static final IKVTableID counterID = DataStoreClient.getClient().getTable(TEST_COUNTER).getTableId();
+ private IKVTableID counterID;
- @After
@Before
+ @After
public void resetCounter() {
IKVClient client = DataStoreClient.getClient();
+ counterID = client.getTable(TEST_COUNTER).getTableId();
client.setCounter(counterID, LONG_ZERO, 0L);
client.destroyCounter(counterID, LONG_ZERO);
}
diff --git a/src/test/java/net/onrc/onos/core/datastore/hazelcast/HZTableTest.java b/src/test/java/net/onrc/onos/core/datastore/hazelcast/HZTableTest.java
index 913012d..dd600d6 100644
--- a/src/test/java/net/onrc/onos/core/datastore/hazelcast/HZTableTest.java
+++ b/src/test/java/net/onrc/onos/core/datastore/hazelcast/HZTableTest.java
@@ -30,6 +30,11 @@
@Rule
public TestName name = new TestName();
+ static {
+ // configuration to quickly fall back to instance mode for faster test run
+ System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
+ }
+
static final String TEST_TABLE_NAME = "TableForUnitTest";
HZTable table;
diff --git a/src/test/java/net/onrc/onos/core/datastore/topology/KVSwitchTest.java b/src/test/java/net/onrc/onos/core/datastore/topology/KVSwitchTest.java
index a789f1c..e8927ae 100644
--- a/src/test/java/net/onrc/onos/core/datastore/topology/KVSwitchTest.java
+++ b/src/test/java/net/onrc/onos/core/datastore/topology/KVSwitchTest.java
@@ -21,6 +21,12 @@
import org.junit.Test;
public class KVSwitchTest {
+
+ static {
+ // configuration to quickly fall back to instance mode for faster test run
+ System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
+ }
+
IKVTable switchTable;
static final Long dpid1 = 0x1L;
KVSwitch sw1;
diff --git a/src/test/java/net/onrc/onos/core/datastore/topology/KVTopologyTest.java b/src/test/java/net/onrc/onos/core/datastore/topology/KVTopologyTest.java
index ce647a4..de71490 100644
--- a/src/test/java/net/onrc/onos/core/datastore/topology/KVTopologyTest.java
+++ b/src/test/java/net/onrc/onos/core/datastore/topology/KVTopologyTest.java
@@ -34,6 +34,11 @@
public class KVTopologyTest {
+ static {
+ // configuration to quickly fall back to instance mode for faster test run
+ System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
+ }
+
static final long VERSION_NONEXISTENT = DataStoreClient.getClient().getVersionNonexistant();
private static final byte[] DEVICE2_MAC_SW2P2 = new byte[]{6, 5, 4, 3, 2, 1, 0};