Add option to use Hazelcast as datastore for development environment.
This patch will set the default backend as Hazelcast.
To use RAMCloud as backend data store, add -Dnet.onrc.onos.datastore.backend=ramcloud to java option.
- ClientMode: Use existing Hazelcast Instance if it exist.
- map name starting with datastore:// is now configured to be strong consistent
- add main for manual testing
- follow PMD,etc. where easily possible
- make HZClient Singleton
Change-Id: Ibe2afc3bfddfd7fd567c91477c16cd679fc543d4
diff --git a/src/test/java/net/onrc/onos/datastore/topology/KVSwitchNoDataStoreTest.java b/src/test/java/net/onrc/onos/datastore/topology/KVSwitchNoDataStoreTest.java
new file mode 100644
index 0000000..e656596
--- /dev/null
+++ b/src/test/java/net/onrc/onos/datastore/topology/KVSwitchNoDataStoreTest.java
@@ -0,0 +1,83 @@
+package net.onrc.onos.datastore.topology;
+
+import static org.junit.Assert.*;
+
+import java.nio.ByteBuffer;
+
+import net.onrc.onos.datastore.topology.KVSwitch.STATUS;
+
+import org.junit.Test;
+
+public class KVSwitchNoDataStoreTest {
+
+ @Test
+ public void testGetDpidFromKeyByteArray() {
+ // reference bytes
+ final byte[] key = KVSwitch.getSwitchID(0x1L);
+
+ assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
+ }
+
+ @Test
+ public void testGetDpidFromKeyByteBuffer() {
+ // reference bytes
+ final ByteBuffer key = ByteBuffer.wrap(KVSwitch.getSwitchID(0x1L));
+
+ assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
+ }
+
+ @Test
+ public void testCreateFromKeyByteArray() {
+ // reference bytes
+ Long dpid = Long.valueOf(0x1L);
+ final byte[] key = KVSwitch.getSwitchID(dpid);
+
+ KVSwitch sw = KVSwitch.createFromKey(key);
+ assertNotNull(sw);
+ assertEquals(dpid, sw.getDpid());
+ }
+
+ @Test
+ public void testGetStatus() {
+ KVSwitch sw = new KVSwitch(0x1L);
+
+ assertEquals(STATUS.INACTIVE, sw.getStatus());
+ }
+
+ @Test
+ public void testSetStatus() {
+ KVSwitch sw = new KVSwitch(0x1L);
+ assertEquals(STATUS.INACTIVE, sw.getStatus());
+
+ sw.setStatus(STATUS.ACTIVE);
+ assertEquals(STATUS.ACTIVE, sw.getStatus());
+ }
+
+ @Test
+ public void testGetDpid() {
+ Long dpid = 0x1L;
+ KVSwitch sw = new KVSwitch(dpid);
+ assertEquals(dpid, sw.getDpid());
+ }
+
+ @Test
+ public void testGetId() {
+ // reference bytes
+ Long dpid = Long.valueOf(0x1L);
+ final byte[] key = KVSwitch.getSwitchID(dpid);
+
+ KVSwitch sw = KVSwitch.createFromKey(key);
+ assertArrayEquals(key, sw.getId());
+ }
+
+ @Test
+ public void testToString() {
+ final String expected = "[" + "KVSwitch"
+ + " 0x" + 1 + " STATUS:" + STATUS.INACTIVE + "]";
+
+ Long dpid = 0x1L;
+ KVSwitch sw = new KVSwitch(dpid);
+
+ assertEquals(expected, sw.toString());
+ }
+}