From: Alissa Bonas Date: Mon, 28 Oct 2013 10:26:36 +0000 (+0200) Subject: Refactor ClusterManagerTest to use correctly junit X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~522 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=5e0bede38b3a05c273e145c2e13969ced2cb5b7e Refactor ClusterManagerTest to use correctly junit Change-Id: Id3b71d21de5a5330e236aed9c05cc47dd257c566 Signed-off-by: Alissa Bonas --- 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 d2a02c9f10..df9036467f 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,6 +1,7 @@ package org.opendaylight.controller.clustering.services_implementation.internal; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import java.net.InetAddress; import java.util.HashSet; @@ -18,7 +19,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; @@ -35,7 +36,7 @@ public class ClusterManagerTest { } @Test - public void WithManagerTest() throws CacheExistException, + public void withManagerTest() throws CacheExistException, CacheConfigException { ClusterManager cm = new ClusterManager(); @@ -48,41 +49,42 @@ 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 NON_TRANSACTIONAL but with both ASYNC and SYNC, @@ -91,49 +93,47 @@ public class ClusterManagerTest { 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(true); + } // Create second cache properly this time, as non_transactional and // ASYNC cacheModeSet.remove(cacheMode.SYNC); try { - c2 = (CacheImpl) cm.createCache("Container1", - "Cache2", cacheModeSet); - } catch (CacheExistException cee) { - Assert.assertTrue(false); - } catch (CacheConfigException cce) { - Assert.assertTrue(false); + 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 @@ -146,10 +146,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();