diff options
author | 2024-12-09 13:00:25 +0000 | |
---|---|---|
committer | 2024-12-09 14:23:32 +0000 | |
commit | a7ef4032a55a8343bcf3117bc6d1e37eef919ddd (patch) | |
tree | 29689f81269da6cddb2c75f7da9b468f7d5fc750 /cps-ncmp-service/src/test/groovy/org | |
parent | 42dfa67015d7478eca07eb5778ec55c2c24c19a5 (diff) |
Hazelcast Optimisation
Issue-ID: CPS-2420
Change-Id: I707e0fbbddeb4ddc7c573a2b3ebd8fbca08126a6
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
4 files changed, 43 insertions, 26 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index d19081cee5..7ac2b2cded 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -21,6 +21,9 @@ package org.onap.cps.ncmp.impl.inventory +import com.hazelcast.config.Config +import com.hazelcast.core.Hazelcast +import com.hazelcast.instance.impl.HazelcastInstanceFactory import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsQueryService import org.onap.cps.impl.utils.CpsValidator @@ -39,11 +42,17 @@ class CmHandleQueryServiceImplSpec extends Specification { def mockCpsQueryService = Mock(CpsQueryService) def mockCpsDataService = Mock(CpsDataService) - def trustLevelPerDmiPlugin = [:] - def trustLevelPerCmHandleId = [ 'PNFDemo': TrustLevel.COMPLETE, 'PNFDemo2': TrustLevel.NONE, 'PNFDemo4': TrustLevel.NONE ] + def trustLevelPerDmiPlugin = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerDmiPlugin') + def trustLevelPerCmHandleId = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerCmHandleId') def mockCpsValidator = Mock(CpsValidator) - def objectUnderTest = new CmHandleQueryServiceImpl(mockCpsDataService, mockCpsQueryService, trustLevelPerDmiPlugin, trustLevelPerCmHandleId, mockCpsValidator) + + def objectUnderTest = new CmHandleQueryServiceImpl(mockCpsDataService, mockCpsQueryService, + trustLevelPerDmiPlugin, trustLevelPerCmHandleId, mockCpsValidator) def static sampleDataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']"), new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-2']")] @@ -56,6 +65,16 @@ class CmHandleQueryServiceImplSpec extends Specification { def static pnfDemo4 = createDataNode('PNFDemo4') def static pnfDemo5 = createDataNode('PNFDemo5') + def setup() { + trustLevelPerCmHandleId.put("PNFDemo", TrustLevel.COMPLETE) + trustLevelPerCmHandleId.put("PNFDemo2", TrustLevel.NONE) + trustLevelPerCmHandleId.put("PNFDemo4", TrustLevel.NONE) + } + + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('hazelcastInstanceName').shutdown() + } + def 'Query CmHandles with public properties query pair.'() { given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.' mockResponses() diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy index 67778fc0a3..faa193ea33 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy @@ -64,7 +64,7 @@ class CmHandleRegistrationServiceSpec extends Specification { def objectUnderTest = Spy(new CmHandleRegistrationService( mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsDataService, mockLcmEventsCmHandleStateHandler, - mockModuleSyncStartedOnCmHandles, mockTrustLevelManager, mockAlternateIdChecker)) + mockModuleSyncStartedOnCmHandles as IMap<String, Object>, mockTrustLevelManager, mockAlternateIdChecker)) def setup() { // always accept all cm handles @@ -86,14 +86,14 @@ class CmHandleRegistrationServiceSpec extends Specification { mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: CmHandleState.READY)) and: 'cm handle is in READY state' mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> true + and: 'cm handle to be removed is in progress map' + mockModuleSyncStartedOnCmHandles.containsKey('cmhandle-2') >> true when: 'registration is processed' objectUnderTest.updateDmiRegistration(dmiRegistration) then: 'cm-handles are removed first' 1 * objectUnderTest.processRemovedCmHandles(*_) and: 'de-registered cm handle entry is removed from in progress map' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2') - then: 'cm-handles are created' - 1 * objectUnderTest.processCreatedCmHandles(*_) + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle-2') then: 'cm-handles are updated' 1 * objectUnderTest.processUpdatedCmHandles(*_) 1 * mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(*_) >> [] @@ -310,6 +310,9 @@ class CmHandleRegistrationServiceSpec extends Specification { given: 'a registration with three cm-handles to be deleted' def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3']) + and: 'cm handles to be deleted in the progress map' + mockModuleSyncStartedOnCmHandles.containsKey("cmhandle1") >> true + mockModuleSyncStartedOnCmHandles.containsKey("cmhandle3") >> true and: 'cm-handle deletion fails on batch' mockInventoryPersistence.deleteDataNodes(_) >> { throw new RuntimeException("Failed") } and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd' @@ -321,11 +324,12 @@ class CmHandleRegistrationServiceSpec extends Specification { and: 'a response is received for all cm-handles' response.removedCmHandles.size() == 3 and: 'successfully de-registered cm handle 1 is removed from in progress map' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle1') + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle1') and: 'successfully de-registered cm handle 3 is removed from in progress map even though it was already being removed' - 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle3') >> 'already in progress' + 1 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle3') and: 'failed de-registered cm handle entries should NOT be removed from in progress map' - 0 * mockModuleSyncStartedOnCmHandles.remove('cmhandle2') + 0 * mockModuleSyncStartedOnCmHandles.containsKey('cmhandle2') + 0 * mockModuleSyncStartedOnCmHandles.removeAsync('cmhandle2') and: '1st and 3rd cm-handle deletes successfully' with(response.removedCmHandles[0]) { assert it.status == Status.SUCCESS @@ -349,7 +353,6 @@ class CmHandleRegistrationServiceSpec extends Specification { }) and: 'No cm handles state updates for "upgraded cm handles"' 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch([:]) - } def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy index 32f4503005..097387c038 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy @@ -20,6 +20,9 @@ package org.onap.cps.ncmp.impl.inventory.trustlevel +import com.hazelcast.config.Config +import com.hazelcast.core.Hazelcast +import com.hazelcast.instance.impl.HazelcastInstanceFactory import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.dmi.DmiRestClient import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService @@ -32,11 +35,16 @@ class DmiPluginTrustLevelWatchDogSpec extends Specification { def mockDmiRestClient = Mock(DmiRestClient) def mockCmHandleQueryService = Mock(CmHandleQueryService) def mockTrustLevelManager = Mock(TrustLevelManager) - def trustLevelPerDmiPlugin = [:] - + def trustLevelPerDmiPlugin = HazelcastInstanceFactory + .getOrCreateHazelcastInstance(new Config('hazelcastInstanceName')) + .getMap('trustLevelPerDmiPlugin') def objectUnderTest = new DmiPluginTrustLevelWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin) + def cleanupSpec() { + Hazelcast.getHazelcastInstanceByName('hazelcastInstanceName').shutdown() + } + def 'watch dmi plugin health status for #dmiHealhStatus'() { given: 'the cache has been initialised and "knows" about dmi-1' trustLevelPerDmiPlugin.put('dmi-1', dmiOldTrustLevel) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy index 1088ca8e06..1ab517cdcf 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy @@ -77,19 +77,6 @@ class TrustLevelManagerSpec extends Specification { assert trustLevelPerCmHandleId.get('ch-2') == TrustLevel.COMPLETE } - def 'Initial cm handle registration where a cm handle is already in the cache'() { - given: 'a trusted cm handle' - def cmHandleModelsToBeCreated = ['ch-1': TrustLevel.NONE] - and: 'the cm handle id already in the cache' - trustLevelPerCmHandleId.put('ch-1', TrustLevel.COMPLETE) - when: 'method to register to the cache is called' - objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) - then: 'no notification sent' - 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) - and: 'cm handle cache is not updated' - assert trustLevelPerCmHandleId.get('ch-1') == TrustLevel.COMPLETE - } - def 'Initial cm handle registration with a cm handle that is not trusted'() { given: 'a not trusted cm handle' def cmHandleModelsToBeCreated = ['ch-2': TrustLevel.NONE] |