X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fclustered-data-store%2Fimplementation%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdatastore%2Finternal%2FClusteredDataStoreImplTest.java;h=0323df6e2dca6c4b9f77ed56cb6aa16119b9e00c;hb=41571a05c3ac8b54c2f1d66e83f965c888f7a86a;hp=8049bae5af602845c0b1b34616aef7a0cc1f6b30;hpb=0b3fe7299bbeccc10f2c1b859f95de07c168ac9f;p=controller.git diff --git a/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImplTest.java b/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImplTest.java index 8049bae5af..0323df6e2d 100644 --- a/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImplTest.java +++ b/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImplTest.java @@ -9,7 +9,8 @@ import org.opendaylight.controller.clustering.services.IClusterGlobalServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler; import org.opendaylight.controller.md.sal.common.api.data.DataModification; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import java.util.EnumSet; import java.util.Map; @@ -64,6 +65,31 @@ public class ClusteredDataStoreImplTest { } } + @Test + public void constructor_WhenOperationalDataCacheIsAlreadyPresent_ShouldNotAttemptToCreateCache() throws CacheExistException, CacheConfigException { + IClusterGlobalServices mockClusterGlobalServices = mock(IClusterGlobalServices.class); + + Mockito.>when(mockClusterGlobalServices.getCache(ClusteredDataStoreImpl.OPERATIONAL_DATA_CACHE)).thenReturn(new ConcurrentHashMap()); + Mockito.>when(mockClusterGlobalServices.getCache(ClusteredDataStoreImpl.CONFIGURATION_DATA_CACHE)).thenReturn(new ConcurrentHashMap()); + + new ClusteredDataStoreImpl(mockClusterGlobalServices); + + verify(mockClusterGlobalServices, never()).createCache(ClusteredDataStoreImpl.OPERATIONAL_DATA_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + } + + @Test + public void constructor_WhenConfigurationDataCacheIsAlreadyPresent_ShouldNotAttemptToCreateCache() throws CacheExistException, CacheConfigException { + IClusterGlobalServices mockClusterGlobalServices = mock(IClusterGlobalServices.class); + + Mockito.>when(mockClusterGlobalServices.getCache(ClusteredDataStoreImpl.OPERATIONAL_DATA_CACHE)).thenReturn(new ConcurrentHashMap()); + Mockito.>when(mockClusterGlobalServices.getCache(ClusteredDataStoreImpl.CONFIGURATION_DATA_CACHE)).thenReturn(new ConcurrentHashMap()); + + new ClusteredDataStoreImpl(mockClusterGlobalServices); + + verify(mockClusterGlobalServices, never()).createCache(ClusteredDataStoreImpl.CONFIGURATION_DATA_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + } + + @Test public void constructor_WhenPassedAValidClusteringServices_ShouldNotThrowAnyExceptions() throws CacheExistException, CacheConfigException { IClusterGlobalServices mockClusterGlobalServices = createClusterGlobalServices(); @@ -102,9 +128,9 @@ public class ClusteredDataStoreImplTest { IClusterGlobalServices mockClusterGlobalServices = createClusterGlobalServices(); - ConcurrentMap mockOperationalDataCache = mock(ConcurrentMap.class); + ConcurrentMap mockOperationalDataCache = mock(ConcurrentMap.class); - Object valueObject = mock(Object.class); + CompositeNode valueObject = mock(CompositeNode.class); when(mockOperationalDataCache.get(path)).thenReturn(valueObject); @@ -151,9 +177,9 @@ public class ClusteredDataStoreImplTest { IClusterGlobalServices mockClusterGlobalServices = createClusterGlobalServices(); - ConcurrentMap mockConfigurationDataCache = mock(ConcurrentMap.class); + ConcurrentMap mockConfigurationDataCache = mock(ConcurrentMap.class); - Object valueObject = mock(Object.class); + CompositeNode valueObject = mock(CompositeNode.class); when(mockConfigurationDataCache.get(path)).thenReturn(valueObject); @@ -198,7 +224,7 @@ public class ClusteredDataStoreImplTest { when(mockModification.getUpdatedConfigurationData()).thenReturn(configurationData); when(mockModification.getUpdatedOperationalData()).thenReturn(operationalData); - DataCommitHandler.DataCommitTransaction, Object> transaction = store.requestCommit(mockModification); + DataCommitHandler.DataCommitTransaction transaction = store.requestCommit(mockModification); transaction.finish(); @@ -227,7 +253,7 @@ public class ClusteredDataStoreImplTest { when(mockModification.getUpdatedConfigurationData()).thenReturn(configurationData); when(mockModification.getUpdatedOperationalData()).thenReturn(operationalData); - DataCommitHandler.DataCommitTransaction, Object> transaction = store.requestCommit(mockModification); + DataCommitHandler.DataCommitTransaction transaction = store.requestCommit(mockModification); transaction.rollback();