diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2024-09-10 16:12:28 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2024-10-10 12:46:36 +0100 |
commit | 8e46da6c3a7b46a067bf72ebae0be1811ea7f9d0 (patch) | |
tree | 658d87fcc8d14f6101b78c08c5df785586c92cfc /cps-ncmp-service/src/test | |
parent | e2517a8b993ed884edb251b91ce600d0a1a9fefe (diff) |
use one hazelcast instance per jvm
- updated all the cache(distributed datastructures) to use the same instance config now.
- there will be just one instance per JVM now
- Better cleanup of hz instance in the testware
- Refactored the testware to verify the configs
- Expected Impact on lowering the memory usage, less number of TCP
communications between members
- NOTE: we need to do a full regression as the changes impacts all the
use cases which involves cache
Issue-ID: CPS-2408
Change-Id: I7564992a9990f44ef3defb4f50cb7d094cad7b92
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
5 files changed, 41 insertions, 49 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy index e7eb893b03..dc38e0fc9b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy @@ -29,29 +29,24 @@ class HazelcastCacheConfigSpec extends Specification { def objectUnderTest = new HazelcastCacheConfig() def 'Create Hazelcast instance with a #scenario'() { - given: 'a cluster name' + given: 'a cluster name and instance name' objectUnderTest.clusterName = 'my cluster' + objectUnderTest.instanceConfigName = 'my instance config' when: 'an hazelcast instance is created (name has to be unique)' - def result = objectUnderTest.createHazelcastInstance(scenario, config) + def result = objectUnderTest.getOrCreateHazelcastInstance(config) then: 'the instance is created and has the correct name' - assert result.name == scenario + assert result.name == 'my instance config' and: 'if applicable it has a map config with the expected name' if (expectMapConfig) { assert result.config.mapConfigs.values()[0].name == 'my map config' - } else { - assert result.config.mapConfigs.isEmpty() } and: 'if applicable it has a queue config with the expected name' if (expectQueueConfig) { assert result.config.queueConfigs.values()[0].name == 'my queue config' - } else { - assert result.config.queueConfigs.isEmpty() } and: 'if applicable it has a set config with the expected name' if (expectSetConfig) { assert result.config.setConfigs.values()[0].name == 'my set config' - } else { - assert result.config.setConfigs.isEmpty() } where: 'the following configs are used' scenario | config || expectMapConfig | expectQueueConfig | expectSetConfig diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfigSpec.groovy index 915bccb53d..740567c4bf 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfigSpec.groovy @@ -36,13 +36,17 @@ class CmSubscriptionConfigSpec extends Specification { @Autowired IMap<String, Map<String, DmiCmSubscriptionDetails>> cmNotificationSubscriptionCache; + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').shutdown() + } + def 'Embedded (hazelcast) cache for Cm Notification Subscription Cache.'() { expect: 'system is able to create an instance of the Cm Notification Subscription Cache' assert null != cmNotificationSubscriptionCache and: 'there is at least 1 instance' assert Hazelcast.allHazelcastInstances.size() > 0 and: 'Cm Notification Subscription Cache is present' - assert Hazelcast.allHazelcastInstances.name.contains('hazelCastInstanceCmNotificationSubscription') + assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config') } def 'Provided CM Subscription data'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfigSpec.groovy index 8e59922c41..4c96d6b822 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfigSpec.groovy @@ -46,6 +46,10 @@ class SynchronizationCacheConfigSpec extends Specification { @Autowired private IMap<String, Boolean> dataSyncSemaphores + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').shutdown() + } + def 'Embedded (hazelcast) Caches for Module and Data Sync.'() { expect: 'system is able to create an instance of the Module Sync Work Queue' assert null != moduleSyncWorkQueue @@ -53,22 +57,19 @@ class SynchronizationCacheConfigSpec extends Specification { assert null != moduleSyncStartedOnCmHandles and: 'system is able to create an instance of a map to hold data sync semaphores' assert null != dataSyncSemaphores - and: 'there are at least 3 instances' - assert Hazelcast.allHazelcastInstances.size() > 2 and: 'they have the correct names (in any order)' - assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores') + assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config') } def 'Verify configs for Distributed objects'(){ - given: 'the Module Sync Work Queue config' - def moduleSyncWorkQueueConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncWorkQueue').config - def moduleSyncDefaultWorkQueueConfig = moduleSyncWorkQueueConfig.queueConfigs.get('defaultQueueConfig') + given: 'hazelcast common config' + def hzConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config + and: 'the Module Sync Work Queue config' + def moduleSyncDefaultWorkQueueConfig = hzConfig.queueConfigs.get('defaultQueueConfig') and: 'the Module Sync Started Cm Handle Map config' - def moduleSyncStartedOnCmHandlesConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncStartedOnCmHandles').config - def moduleSyncStartedOnCmHandlesMapConfig = moduleSyncStartedOnCmHandlesConfig.mapConfigs.get('moduleSyncStartedConfig') + def moduleSyncStartedOnCmHandlesMapConfig = hzConfig.mapConfigs.get('moduleSyncStartedConfig') and: 'the Data Sync Semaphores Map config' - def dataSyncSemaphoresConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config - def dataSyncSemaphoresMapConfig = dataSyncSemaphoresConfig.mapConfigs.get('dataSyncSemaphoresConfig') + def dataSyncSemaphoresMapConfig = hzConfig.mapConfigs.get('dataSyncSemaphoresConfig') expect: 'system created instance with correct config of Module Sync Work Queue' assert moduleSyncDefaultWorkQueueConfig.backupCount == 1 assert moduleSyncDefaultWorkQueueConfig.asyncBackupCount == 0 @@ -79,28 +80,15 @@ class SynchronizationCacheConfigSpec extends Specification { assert dataSyncSemaphoresMapConfig.backupCount == 1 assert dataSyncSemaphoresMapConfig.asyncBackupCount == 0 and: 'all instances are part of same cluster' - def testClusterName = 'cps-and-ncmp-test-caches' - assert moduleSyncWorkQueueConfig.clusterName == testClusterName - assert moduleSyncStartedOnCmHandlesConfig.clusterName == testClusterName - assert dataSyncSemaphoresConfig.clusterName == testClusterName + assert hzConfig.clusterName == 'cps-and-ncmp-test-caches' } def 'Verify deployment network configs for Distributed objects'() { - given: 'the Module Sync Work Queue config' - def queueNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncWorkQueue').config.networkConfig - and: 'the Module Sync Started Cm Handle Map config' - def moduleSyncStartedOnCmHandlesNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncStartedOnCmHandles').config.networkConfig - and: 'the Data Sync Semaphores Map config' - def dataSyncSemaphoresNetworkConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config.networkConfig - expect: 'system created instance with correct config of Module Sync Work Queue' - assert queueNetworkConfig.join.autoDetectionConfig.enabled - assert !queueNetworkConfig.join.kubernetesConfig.enabled - and: 'Module Sync Started Cm Handle Map has the correct settings' - assert moduleSyncStartedOnCmHandlesNetworkConfig.join.autoDetectionConfig.enabled - assert !moduleSyncStartedOnCmHandlesNetworkConfig.join.kubernetesConfig.enabled - and: 'Data Sync Semaphore Map has the correct settings' - assert dataSyncSemaphoresNetworkConfig.join.autoDetectionConfig.enabled - assert !dataSyncSemaphoresNetworkConfig.join.kubernetesConfig.enabled + given: 'common hazelcast network config' + def hzConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config.networkConfig + and: 'all configs has the correct settings' + assert hzConfig.join.autoDetectionConfig.enabled + assert !hzConfig.join.kubernetesConfig.enabled } def 'Verify network config'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy index e79a471015..9391fa0f44 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy @@ -36,13 +36,17 @@ class TrustLevelCacheConfigSpec extends Specification { @Autowired private Map<String, TrustLevel> trustLevelPerCmHandle + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').shutdown() + } + def 'Hazelcast cache for trust level per dmi plugin'() { expect: 'system is able to create an instance of the trust level per dmi plugin cache' assert null != trustLevelPerDmiPlugin and: 'there is at least 1 instance' assert Hazelcast.allHazelcastInstances.size() > 0 and: 'Dmi Plugin Trust Level Cache is present' - assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerDmiPluginMap') + assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config') } def 'Hazelcast cache for trust level per cm handle'() { @@ -51,13 +55,13 @@ class TrustLevelCacheConfigSpec extends Specification { and: 'there is at least 1 instance' assert Hazelcast.allHazelcastInstances.size() > 0 and: 'Hazelcast cache instance for trust level is present' - assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerCmHandleMap') + assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config') } def 'Trust level cache configurations: #scenario'() { - when: 'retrieving the cache config for trustLevel' - def cacheConfig = Hazelcast.getHazelcastInstanceByName(hazelcastInstanceName).config - then: 'the cache config has the right cluster' + given: 'retrieving the common cache config' + def cacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config + and: 'the cache config has the right cluster' assert cacheConfig.clusterName == 'cps-and-ncmp-test-caches' when: 'retrieving the map config for trustLevel' def mapConfig = cacheConfig.mapConfigs.get(hazelcastMapConfigName) @@ -65,14 +69,14 @@ class TrustLevelCacheConfigSpec extends Specification { assert mapConfig.backupCount == 1 assert mapConfig.asyncBackupCount == 0 where: 'the following caches are used' - scenario | hazelcastInstanceName | hazelcastMapConfigName - 'cmhandle map' | 'hazelcastInstanceTrustLevelPerCmHandleMap' | 'trustLevelPerCmHandleCacheConfig' - 'dmi plugin map' | 'hazelcastInstanceTrustLevelPerDmiPluginMap' | 'trustLevelPerDmiPluginCacheConfig' + scenario | hazelcastMapConfigName + 'cmhandle map' | 'trustLevelPerCmHandleCacheConfig' + 'dmi plugin map' | 'trustLevelPerDmiPluginCacheConfig' } def 'Verify deployment network configs for Distributed Caches'() { given: 'the Trust Level Per Dmi Plugin Cache config' - def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerDmiPluginMap').config.networkConfig + def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config.networkConfig expect: 'system created instance with correct config' assert trustLevelDmiPerPluginCacheConfig.join.autoDetectionConfig.enabled assert !trustLevelDmiPerPluginCacheConfig.join.kubernetesConfig.enabled @@ -80,7 +84,7 @@ class TrustLevelCacheConfigSpec extends Specification { def 'Verify deployment network configs for Cm Handle Distributed Caches'() { given: 'the Trust Level Per Cm Handle Cache config' - def trustLevelPerCmHandlePluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerCmHandleMap').config.networkConfig + def trustLevelPerCmHandlePluginCacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config.networkConfig expect: 'system created instance with correct config' assert trustLevelPerCmHandlePluginCacheConfig.join.autoDetectionConfig.enabled assert !trustLevelPerCmHandlePluginCacheConfig.join.kubernetesConfig.enabled diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml index df3375d5d0..12db639633 100644 --- a/cps-ncmp-service/src/test/resources/application.yml +++ b/cps-ncmp-service/src/test/resources/application.yml @@ -99,6 +99,7 @@ ncmp: # Custom Hazelcast Config. hazelcast: cluster-name: "cps-and-ncmp-test-caches" + instance-config-name: "cps-and-ncmp-hazelcast-instance-test-config" mode: kubernetes: enabled: false |