use etc/hazelcast.xml + modifications when creating HZ for testing
Change-Id: I92d554d2e8c696780c3a2fab2accdab396a3805b
diff --git a/core/net/pom.xml b/core/net/pom.xml
index b252636..e2703b2 100644
--- a/core/net/pom.xml
+++ b/core/net/pom.xml
@@ -44,6 +44,13 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-store</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.felix</groupId>
diff --git a/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
index b7362b9..d817cf9 100644
--- a/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
@@ -33,20 +33,18 @@
import org.onlab.onos.store.common.StoreService;
import org.onlab.onos.store.device.impl.DistributedDeviceStore;
import org.onlab.onos.store.impl.StoreManager;
+import org.onlab.onos.store.impl.TestStoreManager;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.UUID;
-
import static org.junit.Assert.*;
import static org.onlab.onos.net.Device.Type.SWITCH;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.device.DeviceEvent.Type.*;
-// FIXME This test is painfully slow starting up Hazelcast on each test cases,
-// turning it off in repository for now.
+// FIXME This test is slow starting up Hazelcast on each test cases.
// FIXME DistributedDeviceStore should have it's own test cases.
/**
@@ -84,17 +82,8 @@
service = mgr;
admin = mgr;
registry = mgr;
- // FIXME should be reading the hazelcast.xml
- Config config = new Config();
- // avoid accidentally joining other cluster
- config.getGroupConfig().setName(UUID.randomUUID().toString());
- // quickly form single node cluster
- config.getNetworkConfig().getJoin()
- .getTcpIpConfig()
- .setEnabled(true).setConnectionTimeoutSeconds(0);
- config.getNetworkConfig().getJoin()
- .getMulticastConfig()
- .setEnabled(false);
+ // TODO should find a way to clean Hazelcast instance without shutdown.
+ Config config = TestStoreManager.getTestConfig();
storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config));
storeManager.activate();
@@ -288,18 +277,8 @@
}
}
- private class TestStoreManager extends StoreManager {
- TestStoreManager(HazelcastInstance instance) {
- this.instance = instance;
- }
-
- @Override
- public void activate() {
- setupKryoPool();
- }
- }
-
private static class TestMastershipService extends MastershipServiceAdapter {
+
@Override
public MastershipRole getLocalRole(DeviceId deviceId) {
return MastershipRole.MASTER;
@@ -315,5 +294,4 @@
return MastershipRole.MASTER;
}
}
-
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java b/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
index 52e8ed0..d73dd9e 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
+++ b/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
@@ -110,6 +110,7 @@
@Deactivate
public void deactivate() {
+
log.info("Stopped");
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java b/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
index 77463fd..abd8ade 100644
--- a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
+++ b/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
@@ -45,7 +45,7 @@
@Service
public class StoreManager implements StoreService {
- private static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml";
+ protected static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml";
private final Logger log = LoggerFactory.getLogger(getClass());
diff --git a/core/store/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java b/core/store/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java
new file mode 100644
index 0000000..c9d8821
--- /dev/null
+++ b/core/store/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java
@@ -0,0 +1,54 @@
+package org.onlab.onos.store.impl;
+
+import java.io.FileNotFoundException;
+import java.util.UUID;
+
+import com.hazelcast.config.Config;
+import com.hazelcast.config.FileSystemXmlConfig;
+import com.hazelcast.core.HazelcastInstance;
+
+/**
+ * Dummy StoreManager to use specified Hazelcast instance.
+ */
+public class TestStoreManager extends StoreManager {
+
+ /**
+ * Gets the Hazelcast Config for testing.
+ *
+ * @return
+ */
+ public static Config getTestConfig() {
+ Config config;
+ try {
+ config = new FileSystemXmlConfig(HAZELCAST_XML_FILE);
+ } catch (FileNotFoundException e) {
+ // falling back to default
+ config = new Config();
+ }
+ // avoid accidentally joining other cluster
+ config.getGroupConfig().setName(UUID.randomUUID().toString());
+ // quickly form single node cluster
+ config.getNetworkConfig().getJoin()
+ .getTcpIpConfig()
+ .setEnabled(true).setConnectionTimeoutSeconds(0);
+ config.getNetworkConfig().getJoin()
+ .getMulticastConfig()
+ .setEnabled(false);
+ return config;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param instance Hazelast instance to return on #getHazelcastInstance()
+ */
+ public TestStoreManager(HazelcastInstance instance) {
+ this.instance = instance;
+ }
+
+ // Hazelcast setup removed from original code.
+ @Override
+ public void activate() {
+ setupKryoPool();
+ }
+}