summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-08-30 23:23:53 +0100
committermpriyank <priyank.maheshwari@est.tech>2022-09-01 14:14:49 +0100
commit6b9dd2114c7ed2458735673499e393701936023c (patch)
treefd358367397f7f0e0e1bdc70ef4e01da02e93810 /cps-ncmp-service/src/test
parentb176de24a873cbd6ff8df07c7947ed6ba7093af7 (diff)
Performance Improvement: Enhance state handler
- Introduced batch handling capability to state handler - Refactored methods in CompositeStateUtils - Renamed saveCmHandleStates to saveCmHandleStateBatch - Decoupled processing of events in bulk - Test scenarios for the new functionality Issue-ID: CPS-1231 Issue-ID: CPS-1126 Change-Id: Ifacdeb7bbed14712ecf4f5e2a4d9b324bae278d8 Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy69
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy)32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy2
3 files changed, 100 insertions, 3 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
index 3d2e9950af..ddede66393 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
@@ -139,4 +139,73 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
and: 'the method to publish Lcm event is called once'
1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
}
+
+ def 'No state change and no event to be published'() {
+ given: 'Cm Handle batch with same state transition as before'
+ def cmHandleStateMap = setupBatch('NO_CHANGE')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then: 'batch is empty and nothing to update'
+ 1 * mockInventoryPersistence.saveCmHandleBatch(_) >> {
+ args -> {
+ assert (args[0] as Collection<YangModelCmHandle>).size() == 0
+ }
+ }
+ and: 'no event will be published'
+ 0 * mockLcmEventsService.publishLcmEvent(*_)
+ }
+
+ def 'Batch of new cm handles provided'() {
+ given: 'A batch of new cm handles'
+ def cmHandleStateMap = setupBatch('NEW')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then: 'new cm handles are saved using inventory persistence'
+ 1 * mockInventoryPersistence.saveCmHandleBatch(_) >> {
+ args -> {
+ assert (args[0] as Collection<YangModelCmHandle>).id.containsAll('cmhandle1', 'cmhandle2')
+ }
+ }
+ and: 'event service is called to publish event'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _)
+
+ }
+
+ def 'Batch of existing cm handles is updated'() {
+ given: 'A batch of updated cm handles'
+ def cmHandleStateMap = setupBatch('UPDATE')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then : 'existing cm handles composite state is persisted'
+ 1 * mockInventoryPersistence.saveCmHandleStateBatch(_) >> {
+ args -> {
+ assert (args[0] as Map<String, CompositeState>).keySet().containsAll(['cmhandle1','cmhandle2'])
+ }
+ }
+ and: 'event service is called to publish event'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _)
+
+ }
+
+ def setupBatch(type) {
+
+ def yangModelCmHandle1 = new YangModelCmHandle(id: 'cmhandle1', dmiProperties: [], publicProperties: [])
+ def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2', dmiProperties: [], publicProperties: [])
+
+ if ('NEW' == type) {
+ return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): ADVISED]
+ }
+
+ if ('UPDATE' == type) {
+ yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED)
+ yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
+ return [(yangModelCmHandle1): READY, (yangModelCmHandle2): DELETING]
+ }
+
+ if ('NO_CHANGE' == type) {
+ yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED)
+ yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
+ return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): READY]
+ }
+ }
} \ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy
index 09f42e4b9f..5fe2660249 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy
@@ -18,13 +18,14 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.models
+package org.onap.cps.ncmp.api.impl.yangmodels
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
+import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
import spock.lang.Specification
import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
@@ -79,4 +80,31 @@ class YangModelCmHandleSpec extends Specification {
'only data service registered' | null | 'does not matter' | null | MODEL || null
}
+ def 'Yang Model Cm Handle Deep Copy'() {
+ given: 'a yang model cm handle'
+ def currentYangModelCmHandle = new YangModelCmHandle(id: 'cmhandle',
+ publicProperties: [new YangModelCmHandle.Property('publicProperty1', 'value1')],
+ dmiProperties: [new YangModelCmHandle.Property('dmiProperty1', 'value1')],
+ compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: false))
+ when: 'a deep copy is created'
+ def yangModelCmhandleDeepCopy = YangModelCmHandle.deepCopyOf(currentYangModelCmHandle)
+ and: 'we try to mutate current yang model cm handle'
+ currentYangModelCmHandle.id = 'cmhandle-changed'
+ currentYangModelCmHandle.dmiProperties = [new YangModelCmHandle.Property('updatedPublicProperty1', 'value1')]
+ currentYangModelCmHandle.publicProperties = [new YangModelCmHandle.Property('updatedDmiProperty1', 'value1')]
+ currentYangModelCmHandle.compositeState.cmHandleState = CmHandleState.READY
+ currentYangModelCmHandle.compositeState.dataSyncEnabled = true
+ then: 'there is no change in the deep copied object'
+ assert yangModelCmhandleDeepCopy.id == 'cmhandle'
+ assert yangModelCmhandleDeepCopy.dmiProperties == [new YangModelCmHandle.Property('dmiProperty1', 'value1')]
+ assert yangModelCmhandleDeepCopy.publicProperties == [new YangModelCmHandle.Property('publicProperty1', 'value1')]
+ assert yangModelCmhandleDeepCopy.compositeState.cmHandleState == CmHandleState.ADVISED
+ assert yangModelCmhandleDeepCopy.compositeState.dataSyncEnabled == false
+ and: 'equality on reference and hashcode behave as expected'
+ assert currentYangModelCmHandle.hashCode() != yangModelCmhandleDeepCopy.hashCode()
+ assert currentYangModelCmHandle != yangModelCmhandleDeepCopy
+
+ }
+
+
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
index 76f10de831..19c8ae81ce 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
@@ -159,7 +159,7 @@ class InventoryPersistenceSpec extends Specification {
def compositeState2 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
when: 'update cm handle state is invoked with the #scenario state'
def cmHandleStateMap = ['Some-Cm-Handle1' : compositeState1, 'Some-Cm-Handle2' : compositeState2]
- objectUnderTest.saveCmHandleStates(cmHandleStateMap)
+ objectUnderTest.saveCmHandleStateBatch(cmHandleStateMap)
then: 'update node leaves is invoked with the correct params'
1 * mockCpsDataService.updateDataNodesAndDescendants('NCMP-Admin', 'ncmp-dmi-registry', cmHandlesJsonDataMap, _ as OffsetDateTime)
where: 'the following states are used'