Merge "Adding tests for clustering services. Removed first slash for infinispan-confi...
authorGiovanni Meo <gmeo@cisco.com>
Fri, 26 Apr 2013 13:36:58 +0000 (13:36 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 26 Apr 2013 13:36:58 +0000 (13:36 +0000)
opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java
opendaylight/clustering/services_implementation/src/main/resources/config/infinispan-config.xml
opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java [new file with mode: 0644]

index 3034d3ca6dac2ee80d5c35191a9f277b20bae018..0b2610797fe507f210bf09af989fa4ee643c21ab 100644 (file)
@@ -248,7 +248,7 @@ public class ClusterManager implements IClusterServices {
         logger.info("Starting the ClusterManager");
         try {
             //FIXME keeps throwing FileNotFoundException
-            this.cm = new DefaultCacheManager("/config/infinispan-config.xml");
+            this.cm = new DefaultCacheManager("config/infinispan-config.xml");
             logger.debug("Allocated ClusterManager");
             if (this.cm != null) {
                 this.cm.start();
index 96eff96919b35a5dd166b03d8ae23772b5193323..03a9b4d93e4ad17c89f41976c9a33a3d20bfc359 100644 (file)
@@ -2,7 +2,7 @@
   <global>
     <transport>
       <properties>
-        <property name="configurationFile" value="/config/jgroups.xml"/>
+        <property name="configurationFile" value="config/jgroups.xml"/>
       </properties>
     </transport>
     <!-- Enable JMX statistics -->
diff --git a/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java b/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java
new file mode 100644 (file)
index 0000000..736a2b2
--- /dev/null
@@ -0,0 +1,160 @@
+package org.opendaylight.controller.clustering.services_implementation.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.infinispan.CacheImpl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.clustering.services.IClusterServices.cacheMode;
+
+public class ClusterManagerTest {
+
+    @Test
+    public void NoManagerSetTest() throws CacheExistException,
+            CacheConfigException {
+        ClusterManager cm = new ClusterManager();
+        CacheImpl<String, Integer> c1 = null;
+        CacheImpl<String, Integer> c2 = null;
+        Assert.assertNull(cm.createCache("Container", "Cache", null));
+        Assert.assertNull(cm.getCacheProperties("Container", "Cache"));
+        Assert.assertNull(cm.getCache("Container", "Cache"));
+        Assert.assertFalse(cm.existCache("Container", "Cache"));
+        Assert.assertNull(cm.getCacheList("Container"));
+        Assert.assertTrue(cm.amIStandby());
+        Assert.assertNull(cm.getActiveAddress());
+        Assert.assertNull(cm.getMyAddress());
+        Assert.assertNull(cm.getClusteredControllers());
+    }
+
+    @Test
+    public void WithManagerTest() throws CacheExistException,
+            CacheConfigException {
+
+        ClusterManager cm = new ClusterManager();
+        CacheImpl<String, Integer> c1 = null;
+        CacheImpl<String, Integer> c2 = null;
+
+        cm.start();
+
+        // Check no cache created yet
+        assertFalse(cm.existCache("NonExistantContainerName",
+                "NonExistantCacheName"));
+
+        // Create cache with no cacheMode set, expecting it to fail
+        HashSet<cacheMode> cacheModeSet = new HashSet<cacheMode>();
+        Assert.assertNull(cm.createCache("Container1", "Cache1", cacheModeSet));
+
+        // Create first cache as transactional
+        cacheModeSet.add(cacheMode.TRANSACTIONAL);
+        try {
+            c1 = (CacheImpl<String, Integer>) cm.createCache("Container1",
+                    "Cache1", cacheModeSet);
+        } catch (CacheExistException cee) {
+            Assert.assertTrue(false);
+        } catch (CacheConfigException cce) {
+            Assert.assertTrue(false);
+        }
+
+        // Try creating exact same cache again
+        try {
+            c1 = (CacheImpl<String, Integer>) cm.createCache("Container1",
+                    "Cache1", cacheModeSet);
+        } catch (CacheExistException cee) {
+            Assert.assertTrue(true);
+        } catch (CacheConfigException cce) {
+            Assert.assertTrue(false);
+        }
+
+        // Create second cache with both types of cacheMode, expecting it to
+        // complain
+        cacheModeSet.add(cacheMode.NON_TRANSACTIONAL);
+        try {
+            c2 = (CacheImpl<String, Integer>) cm.createCache("Container1",
+                    "Cache2", cacheModeSet);
+        } catch (CacheExistException cee) {
+            Assert.assertTrue(false);
+        } catch (CacheConfigException cce) {
+            Assert.assertTrue(true);
+        }
+
+        // Create second cache properly this time, as non_transactional
+        cacheModeSet.remove(cacheMode.TRANSACTIONAL);
+        try {
+            c2 = (CacheImpl<String, Integer>) cm.createCache("Container1",
+                    "Cache2", cacheModeSet);
+        } catch (CacheExistException cee) {
+            Assert.assertTrue(false);
+        } catch (CacheConfigException cce) {
+            Assert.assertTrue(false);
+        }
+
+        // Make sure correct caches exists
+        Assert.assertTrue(cm.existCache("Container1", "Cache1"));
+        c1 = (CacheImpl<String, Integer>) cm.getCache("Container1", "Cache1");
+        Assert.assertTrue(c1 != null);
+
+        Assert.assertTrue(cm.existCache("Container1", "Cache2"));
+        c2 = (CacheImpl<String, Integer>) cm.getCache("Container1", "Cache2");
+        Assert.assertTrue(c2 != null);
+
+        Assert.assertNull(cm.getCache("Container1", "Cache3"));
+
+        // Get CacheList
+        HashSet<String> cacheList = (HashSet<String>) cm
+                .getCacheList("Container2");
+        Assert.assertEquals(0, cacheList.size());
+
+        cacheList = (HashSet<String>) cm.getCacheList("Container1");
+        Assert.assertEquals(2, cacheList.size());
+        Assert.assertTrue(cacheList.contains("Cache1"));
+        Assert.assertTrue(cacheList.contains("Cache2"));
+
+        // Get CacheProperties
+        Assert.assertNull(cm.getCacheProperties("Container1", ""));
+        Properties p = cm.getCacheProperties("Container1", "Cache1");
+        Assert.assertEquals(3, p.size());
+        Assert.assertNotNull(p
+                .getProperty(IClusterServices.cacheProps.TRANSACTION_PROP
+                        .toString()));
+        Assert.assertNotNull(p
+                .getProperty(IClusterServices.cacheProps.CLUSTERING_PROP
+                        .toString()));
+        Assert.assertNotNull(p
+                .getProperty(IClusterServices.cacheProps.LOCKING_PROP
+                        .toString()));
+
+        // Destroy cache1 and make sure it's gone
+        cm.destroyCache("Container1", "Cache1");
+        cm.destroyCache("Container1", "Cache3");
+        Assert.assertFalse(cm.existCache("Container1", "Cache1"));
+        Assert.assertTrue(cm.existCache("Container1", "Cache2"));
+
+        // Check amIStandBy()
+        boolean standby = cm.amIStandby();
+        Assert.assertFalse(standby);
+
+        // Check addresses, which are all loopback
+        InetAddress activeAddress = cm.getActiveAddress();
+        Assert.assertEquals("/127.0.0.1", activeAddress.toString());
+        InetAddress myAddress = cm.getMyAddress();
+        Assert.assertEquals("/127.0.0.1", myAddress.toString());
+
+        List<InetAddress> cc = cm.getClusteredControllers();
+        Assert.assertEquals(0, cc.size());
+
+        cm.stop();
+    }
+
+}