aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutorSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy18
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy18
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy57
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasksSpec.groovy14
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy12
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy13
9 files changed, 103 insertions, 71 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutorSpec.groovy
index 33dcf5d623..9423246134 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutorSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutorSpec.groovy
@@ -75,7 +75,7 @@ class PolicyExecutorSpec extends Specification {
def 'Permission check with "allow" decision.'() {
given: 'allow response'
- mockResponse([decision:'allow'], HttpStatus.OK)
+ mockResponse([permissionResult:'allow'], HttpStatus.OK)
when: 'permission is checked for an operation'
objectUnderTest.checkPermission(new YangModelCmHandle(), operationType, 'my credentials','my resource',someValidJson)
then: 'system logs the operation is allowed'
@@ -88,7 +88,7 @@ class PolicyExecutorSpec extends Specification {
def 'Permission check with "other" decision (not allowed).'() {
given: 'other response'
- mockResponse([decision:'other', decisionId:123, message:'I dont like Mondays' ], HttpStatus.OK)
+ mockResponse([permissionResult:'other', id:123, message:'I dont like Mondays' ], HttpStatus.OK)
when: 'permission is checked for an operation'
objectUnderTest.checkPermission(new YangModelCmHandle(), PATCH, 'my credentials','my resource',someValidJson)
then: 'Policy Executor exception is thrown'
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..1c8a19a3bd 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,12 +42,11 @@ 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 static sampleDataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']"),
new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-2']")]
@@ -56,6 +58,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..0706a1e19f 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 handles is present in 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,11 @@ 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.removeAsync('cmhandle2')
and: '1st and 3rd cm-handle deletes successfully'
with(response.removedCmHandles[0]) {
assert it.status == Status.SUCCESS
@@ -349,7 +352,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/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
index de69927d36..c1a8589c48 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -26,6 +26,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.api.exceptions.DataNodeNotFoundException
+import org.onap.cps.api.exceptions.DataValidationException
import org.onap.cps.impl.utils.CpsValidator
import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException
import org.onap.cps.ncmp.api.inventory.models.CompositeState
@@ -85,7 +87,7 @@ class InventoryPersistenceImplSpec extends Specification {
def alternateId2 = 'another-alternate-id'
def xpath2 = "/dmi-registry/cm-handles[@id='another-cm-handle']"
- def dataNode = new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])
+ def dataNode = new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: leaves)
@Shared
def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]),
@@ -100,7 +102,7 @@ class InventoryPersistenceImplSpec extends Specification {
@Shared
def childDataNodesForCmHandleWithState = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/state", leaves: ['cm-handle-state': 'ADVISED'])]
- def "Retrieve CmHandle using datanode with #scenario."() {
+ def 'Retrieve CmHandle using datanode with #scenario.'() {
given: 'the cps data service returns a data node from the DMI registry'
def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
@@ -127,7 +129,7 @@ class InventoryPersistenceImplSpec extends Specification {
'with state details' | childDataNodesForCmHandleWithState || [] || [] || CmHandleState.ADVISED
}
- def "Handling missing service names as null."() {
+ def 'Handling missing service names as null.'() {
given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes'
def dataNode = new DataNode(childDataNodes:[], leaves: ['id':cmHandleId])
mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
@@ -141,17 +143,28 @@ class InventoryPersistenceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters(cmHandleId)
}
- def "Retrieve multiple YangModelCmHandles using cm handle ids"() {
+ def 'Retrieve multiple YangModelCmHandles using cm handle ids'() {
given: 'the cps data service returns 2 data nodes from the DMI registry'
def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2])]
mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [xpath, xpath2] , INCLUDE_ALL_DESCENDANTS) >> dataNodes
- when: 'retrieving the yang modelled cm handle'
+ when: 'retrieving the yang modelled cm handles'
def results = objectUnderTest.getYangModelCmHandles([cmHandleId, cmHandleId2])
- then: 'verify both have returned and cmhandleIds are correct'
+ then: 'verify both have returned and cm handle Ids are correct'
assert results.size() == 2
assert results.id.containsAll([cmHandleId, cmHandleId2])
}
+ def 'YangModelCmHandles are not returned for invalid cm handle ids'() {
+ given: 'invalid cm handle id throws a data validation exception'
+ mockCpsValidator.validateNameCharacters('Invalid Cm Handle Id') >> {throw new DataValidationException('','')}
+ and: 'empty collection is returned as no valid cm handle ids are given'
+ mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [] , INCLUDE_ALL_DESCENDANTS) >> []
+ when: 'retrieving the yang modelled cm handles'
+ def results = objectUnderTest.getYangModelCmHandles(['Invalid Cm Handle Id'])
+ then: 'no YangModelCmHandle is returned'
+ assert results.size() == 0
+ }
+
def "Retrieve multiple YangModelCmHandles using cm handle references"() {
given: 'the cps data service returns 2 data nodes from the DMI registry'
def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])]
@@ -337,11 +350,15 @@ class InventoryPersistenceImplSpec extends Specification {
assert thrownException.getDetails().contains('No cm handles found with reference alternate id')
}
- def 'Get multiple yang model cm handles by alternate ids, passing empty collection'() {
- when: 'getting the yang model cm handle for no alternate ids'
- objectUnderTest.getYangModelCmHandleByAlternateIds([])
- then: 'query service is not invoked'
- 0 * mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, _)
+ def 'Get multiple yang model cm handles by alternate ids #scenario'() {
+ when: 'getting the yang model cm handle with a empty/populated collection of alternate Ids'
+ objectUnderTest.getYangModelCmHandleByAlternateIds(alternateIdCollection)
+ then: 'query service invoked when needed'
+ expectedInvocations * mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [dataNode]
+ where: 'collections are either empty or populated with alternate ids'
+ scenario | alternateIdCollection || expectedInvocations
+ 'empty collection' | [] || 0
+ 'populated collection' | ['alt'] || 1
}
def 'Get CM handle ids for CM Handles that has given module names'() {
@@ -384,10 +401,24 @@ class InventoryPersistenceImplSpec extends Specification {
1 * mockCpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ['xpath1', 'xpath2'], NO_TIMESTAMP);
}
- def 'Check if cm handle exists for a given cm handle id'() {
+ def 'CM handle exists'() {
given: 'data service returns a datanode with correct cm handle id'
mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
expect: 'cm handle exists for given cm handle id'
- assert true == objectUnderTest.isExistingCmHandleId('some-cm-handle')
+ assert true == objectUnderTest.isExistingCmHandleId(cmHandleId)
+ }
+
+ def 'CM handle does not exist, empty dataNode collection returned'() {
+ given: 'data service returns an empty datanode'
+ mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> []
+ expect: 'false is returned for non-existent cm handle'
+ assert false == objectUnderTest.isExistingCmHandleId(cmHandleId)
+ }
+
+ def 'CM handle does not exist, exception thrown'() {
+ given: 'data service throws an exception'
+ mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@id='non-existent-cm-handle']", INCLUDE_ALL_DESCENDANTS) >> {throw new DataNodeNotFoundException('','')}
+ expect: 'false is returned for non-existent cm handle'
+ assert false == objectUnderTest.isExistingCmHandleId('non-existent-cm-handle')
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy
index ae2554762f..c62a87f5c3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy
@@ -24,7 +24,7 @@
package org.onap.cps.ncmp.impl.inventory
import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade
+import org.onap.cps.api.model.ConditionProperties
import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters
import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters
import org.onap.cps.ncmp.api.inventory.models.CompositeState
@@ -32,12 +32,12 @@ import org.onap.cps.ncmp.api.inventory.models.ConditionApiProperties
import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
import org.onap.cps.ncmp.api.inventory.models.TrustLevel
+import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl
import org.onap.cps.ncmp.impl.inventory.models.CmHandleState
import org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
-import org.onap.cps.api.model.ConditionProperties
import org.onap.cps.utils.JsonObjectMapper
import spock.lang.Specification
@@ -50,7 +50,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
def mockTrustLevelManager = Mock(TrustLevelManager)
def mockAlternateIdMatcher = Mock(AlternateIdMatcher)
- def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager, mockAlternateIdMatcher)
+ def objectUnderTest = new NetworkCmProxyInventoryFacadeImpl(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager, mockAlternateIdMatcher)
def 'Update DMI Registration'() {
given: 'an (updated) dmi plugin registration'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasksSpec.groovy
index 97c2488bc3..c7fe45db90 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasksSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasksSpec.groovy
@@ -194,7 +194,7 @@ class ModuleSyncTasksSpec extends Specification {
def loggingEvent = getLoggingEvent()
assert loggingEvent.level == Level.INFO
and: 'the log indicates the cm handle entry is removed successfully'
- assert loggingEvent.formattedMessage == 'ch-1 removed from in progress map'
+ assert loggingEvent.formattedMessage == 'ch-1 will be removed asynchronously from in progress map'
}
def 'Sync and upgrade CM handle if in upgrade state for #scenario'() {
@@ -214,18 +214,6 @@ class ModuleSyncTasksSpec extends Specification {
'module upgrade failed' | MODULE_UPGRADE_FAILED
}
-
- def 'Remove non-existing cm handle id from hazelcast map'() {
- given: 'hazelcast map does not contains cm handle id'
- def result = moduleSyncStartedOnCmHandles.get('non-existing-cm-handle')
- assert result == null
- when: 'remove cm handle entry from hazelcast map'
- objectUnderTest.removeResetCmHandleFromModuleSyncMap('non-existing-cm-handle')
- then: 'no event is logged'
- def loggingEvent = getLoggingEvent()
- assert loggingEvent == null
- }
-
def cmHandleByIdAndState(cmHandleId, cmHandleState) {
return new YangModelCmHandle(id: cmHandleId, compositeState: new CompositeState(cmHandleState: cmHandleState))
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 4cf07e4c24..a9b88c2d3b 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,11 +44,11 @@ class ModuleSyncWatchdogSpec extends Specification {
def spiedAsyncTaskExecutor = Spy(AsyncTaskExecutor)
- def mockWorkQueueLock = Mock(Lock)
+ def mockCpsAndNcmpLock = Mock(IMap<String,String>)
def spiedSleeper = Spy(Sleeper)
- def objectUnderTest = new ModuleSyncWatchdog(mockModuleOperationsUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor, mockWorkQueueLock, spiedSleeper)
+ def objectUnderTest = new ModuleSyncWatchdog(mockModuleOperationsUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor, mockCpsAndNcmpLock, spiedSleeper)
void setup() {
spiedAsyncTaskExecutor.setupThreadPool()
@@ -59,14 +59,16 @@ class ModuleSyncWatchdogSpec extends Specification {
mockModuleOperationsUtils.getAdvisedCmHandleIds() >> createCmHandleIds(numberOfAdvisedCmHandles)
and: 'module sync utilities returns no failed (locked) cm handles'
mockModuleOperationsUtils.getCmHandlesThatFailedModelSyncOrUpgrade() >> []
- and: 'the work queue is not locked'
- mockWorkQueueLock.tryLock() >> true
+ and: 'the work queue can be locked'
+ mockCpsAndNcmpLock.tryLock('workQueueLock') >> true
and: 'the executor has enough available threads'
spiedAsyncTaskExecutor.getAsyncTaskParallelismLevel() >> 3
when: ' module sync is started'
objectUnderTest.moduleSyncAdvisedCmHandles()
then: 'it performs #expectedNumberOfTaskExecutions tasks'
expectedNumberOfTaskExecutions * spiedAsyncTaskExecutor.executeTask(*_)
+ and: 'the executing thread is unlocked'
+ 1 * mockCpsAndNcmpLock.unlock('workQueueLock')
where: 'the following parameter are used'
scenario | numberOfAdvisedCmHandles || expectedNumberOfTaskExecutions
'none at all' | 0 || 0
@@ -80,8 +82,8 @@ class ModuleSyncWatchdogSpec extends Specification {
def 'Module sync cm handles starts with no available threads.'() {
given: 'module sync utilities returns a advise cm handles'
mockModuleOperationsUtils.getAdvisedCmHandleIds() >> createCmHandleIds(1)
- and: 'the work queue is not locked'
- mockWorkQueueLock.tryLock() >> true
+ and: 'the work queue can be locked'
+ mockCpsAndNcmpLock.tryLock('workQueueLock') >> true
and: 'the executor first has no threads but has one thread on the second attempt'
spiedAsyncTaskExecutor.getAsyncTaskParallelismLevel() >>> [ 0, 1 ]
when: ' module sync is started'
@@ -93,8 +95,8 @@ class ModuleSyncWatchdogSpec extends Specification {
def 'Module sync advised cm handle already handled by other thread.'() {
given: 'module sync utilities returns an advised cm handle'
mockModuleOperationsUtils.getAdvisedCmHandleIds() >> createCmHandleIds(1)
- and: 'the work queue is not locked'
- mockWorkQueueLock.tryLock() >> true
+ and: 'the work queue can be locked'
+ mockCpsAndNcmpLock.tryLock('workQueueLock') >> true
and: 'the executor has a thread available'
spiedAsyncTaskExecutor.getAsyncTaskParallelismLevel() >> 1
and: 'the semaphore cache indicates the cm handle is already being processed'
@@ -131,16 +133,18 @@ class ModuleSyncWatchdogSpec extends Specification {
def 'Module Sync Locking.'() {
given: 'module sync utilities returns an advised cm handle'
mockModuleOperationsUtils.getAdvisedCmHandleIds() >> createCmHandleIds(1)
- and: 'can lock is : #canLock'
- mockWorkQueueLock.tryLock() >> canLock
+ and: 'can be locked is : #canLock'
+ mockCpsAndNcmpLock.tryLock('workQueueLock') >> canLock
when: 'attempt to populate the work queue'
objectUnderTest.populateWorkQueueIfNeeded()
then: 'the queue remains empty is #expectQueueRemainsEmpty'
assert moduleSyncWorkQueue.isEmpty() == expectQueueRemainsEmpty
+ and: 'unlock is called only when thread is able to enter the critical section'
+ expectedInvocationToUnlock * mockCpsAndNcmpLock.unlock('workQueueLock')
where: 'the following lock states are applied'
- canLock | expectQueueRemainsEmpty
- false | true
- true | false
+ canLock || expectQueueRemainsEmpty || expectedInvocationToUnlock
+ false || true || 0
+ true || false || 1
}
def 'Sleeper gets interrupted.'() {
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]