X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fclustering%2Fservices_implementation%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fservices_implementation%2Finternal%2FClusterManagerTest.java;h=3d234d32c55bb46229d717195427daa270647df0;hb=c7551f594c34504fffa0055d3360132577938b38;hp=736a2b23ec8d9e63b074d2c7b194f6ae2b034859;hpb=650881665d632280824523b05a2ab699e6932bfb;p=controller.git 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 index 736a2b23ec..3d234d32c5 100644 --- 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 @@ -1,15 +1,19 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.clustering.services_implementation.internal; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; 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; @@ -22,7 +26,7 @@ import org.opendaylight.controller.clustering.services.IClusterServices.cacheMod public class ClusterManagerTest { @Test - public void NoManagerSetTest() throws CacheExistException, + public void noManagerSetTest() throws CacheExistException, CacheConfigException { ClusterManager cm = new ClusterManager(); CacheImpl c1 = null; @@ -39,7 +43,7 @@ public class ClusterManagerTest { } @Test - public void WithManagerTest() throws CacheExistException, + public void withManagerTest() throws CacheExistException, CacheConfigException { ClusterManager cm = new ClusterManager(); @@ -52,78 +56,91 @@ public class ClusterManagerTest { assertFalse(cm.existCache("NonExistantContainerName", "NonExistantCacheName")); + String cacheName = "Cache1"; + String containerName = "Container1"; // Create cache with no cacheMode set, expecting it to fail HashSet cacheModeSet = new HashSet(); - Assert.assertNull(cm.createCache("Container1", "Cache1", cacheModeSet)); + Assert.assertNull(cm.createCache(containerName,cacheName, cacheModeSet)); // Create first cache as transactional cacheModeSet.add(cacheMode.TRANSACTIONAL); try { - c1 = (CacheImpl) cm.createCache("Container1", - "Cache1", cacheModeSet); - } catch (CacheExistException cee) { - Assert.assertTrue(false); - } catch (CacheConfigException cce) { - Assert.assertTrue(false); + c1 = (CacheImpl) cm.createCache(containerName, + cacheName, cacheModeSet); + } catch (CacheExistException | CacheConfigException cce) { + fail("Failed to create cache " + cacheName); } // Try creating exact same cache again try { - c1 = (CacheImpl) cm.createCache("Container1", - "Cache1", cacheModeSet); + c1 = (CacheImpl) cm.createCache(containerName, + cacheName, cacheModeSet); } catch (CacheExistException cee) { - Assert.assertTrue(true); + } catch (CacheConfigException cce) { - Assert.assertTrue(false); + fail("Creating cache failed with " + cce); } // Create second cache with both types of cacheMode, expecting it to // complain + String cacheName2 = "Cache2"; cacheModeSet.add(cacheMode.NON_TRANSACTIONAL); try { - c2 = (CacheImpl) cm.createCache("Container1", - "Cache2", cacheModeSet); + c2 = (CacheImpl) cm.createCache(containerName, + cacheName2, cacheModeSet); } catch (CacheExistException cee) { - Assert.assertTrue(false); + fail("Failed to create cache " + cacheName2 + cee); } catch (CacheConfigException cce) { - Assert.assertTrue(true); + } - // Create second cache properly this time, as non_transactional + // Create second cache NON_TRANSACTIONAL but with both ASYNC and SYNC, + // expect to complain cacheModeSet.remove(cacheMode.TRANSACTIONAL); + cacheModeSet.add(cacheMode.SYNC); + cacheModeSet.add(cacheMode.ASYNC); try { - c2 = (CacheImpl) cm.createCache("Container1", - "Cache2", cacheModeSet); + c2 = (CacheImpl) cm.createCache(containerName, cacheName2, cacheModeSet); } catch (CacheExistException cee) { - Assert.assertTrue(false); + fail("Attempted to create cache " + cacheName2 + " with illegal cache modes set " + cacheModeSet); } catch (CacheConfigException cce) { - Assert.assertTrue(false); + + } + + // Create second cache properly this time, as non_transactional and + // ASYNC + cacheModeSet.remove(cacheMode.SYNC); + try { + c2 = (CacheImpl) cm.createCache(containerName, + cacheName2, cacheModeSet); + } catch (CacheExistException | CacheConfigException e) { + fail("Failed to create cache " + cacheName + " though it was supposed to succeed." + e); } // Make sure correct caches exists - Assert.assertTrue(cm.existCache("Container1", "Cache1")); - c1 = (CacheImpl) cm.getCache("Container1", "Cache1"); - Assert.assertTrue(c1 != null); + Assert.assertTrue(cm.existCache(containerName, cacheName)); + c1 = (CacheImpl) cm.getCache(containerName, cacheName); + Assert.assertNotNull(c1); - Assert.assertTrue(cm.existCache("Container1", "Cache2")); - c2 = (CacheImpl) cm.getCache("Container1", "Cache2"); - Assert.assertTrue(c2 != null); + Assert.assertTrue(cm.existCache(containerName, cacheName2)); + c2 = (CacheImpl) cm.getCache(containerName, cacheName2); + Assert.assertNotNull(c2); - Assert.assertNull(cm.getCache("Container1", "Cache3")); + Assert.assertNull(cm.getCache(containerName, "Cache3")); // Get CacheList HashSet cacheList = (HashSet) cm .getCacheList("Container2"); Assert.assertEquals(0, cacheList.size()); - cacheList = (HashSet) cm.getCacheList("Container1"); + cacheList = (HashSet) cm.getCacheList(containerName); Assert.assertEquals(2, cacheList.size()); - Assert.assertTrue(cacheList.contains("Cache1")); - Assert.assertTrue(cacheList.contains("Cache2")); + Assert.assertTrue(cacheList.contains(cacheName)); + Assert.assertTrue(cacheList.contains(cacheName2)); // Get CacheProperties - Assert.assertNull(cm.getCacheProperties("Container1", "")); - Properties p = cm.getCacheProperties("Container1", "Cache1"); + Assert.assertNull(cm.getCacheProperties(containerName, "")); + Properties p = cm.getCacheProperties(containerName, cacheName); Assert.assertEquals(3, p.size()); Assert.assertNotNull(p .getProperty(IClusterServices.cacheProps.TRANSACTION_PROP @@ -136,10 +153,10 @@ public class ClusterManagerTest { .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")); + cm.destroyCache(containerName, cacheName); + cm.destroyCache(containerName, "Cache3"); + Assert.assertFalse(cm.existCache(containerName, cacheName)); + Assert.assertTrue(cm.existCache(containerName, cacheName2)); // Check amIStandBy() boolean standby = cm.amIStandby();