diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-09-02 09:40:35 +0100 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-09-02 15:29:00 +0100 |
commit | 5c1c7a8f467c0c7e673aa81de9e39766c67eb20f (patch) | |
tree | 0f805f0436d2eb61bf8f9f3bc02709bc44dba58c /cps-ncmp-service/src/test/groovy/org/onap | |
parent | 3c29b33cb1f9398106921e5d9510c62c34cc7694 (diff) |
Performance Improvement: Use save batches of cmhandles
-Used cm handle batch to persist from state handler.
Issue-ID: CPS-1230
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: I68b7fde7dc85818b818f1af588344c26b549d87b
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap')
3 files changed, 50 insertions, 34 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy index ed985ec000..86a32a1a59 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy @@ -159,12 +159,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { assert it.cmHandle == 'cmhandle' } and: 'state handler is invoked with the expected parameters' - 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, _) >> { - args -> { - def result = (args[0] as YangModelCmHandle) - assert result.id == 'cmhandle' - assert result.dmiServiceName == 'my-server' - assert CmHandleState.ADVISED == (args[1] as CmHandleState) + 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { + args -> + { + def cmHandleStatePerCmHandle = (args[0] as Map) + cmHandleStatePerCmHandle.each { + assert (it.key.id == 'cmhandle' + && it.key.dmiServiceName == 'my-server' + && it.value == CmHandleState.ADVISED) + } } } where: @@ -173,36 +176,29 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { 'with only public properties' | [:] | ['public-key': 'public-value'] || '[]' | '[{"name":"public-key","value":"public-value"}]' 'with only dmi properties' | ['dmi-key': 'dmi-value'] | [:] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[]' 'without dmi & public properties' | [:] | [:] || '[]' | '[]' - } - def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed'() { + def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed with some failures'() { given: 'a registration with three cm-handles to be created' def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', - createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'), - new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'), - new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')]) + createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'), + new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'), + new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')]) and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd' - mockLcmEventsCmHandleStateHandler.updateCmHandleState(*_) >> {} >> { throw new RuntimeException("Failed") } >> {} + mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw new RuntimeException("Failed") } when: 'registration is updated to create cm-handles' def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a response is received for all cm-handles' - response.getCreatedCmHandles().size() == 3 - and: '1st and 3rd cm-handle are created successfully' + response.getCreatedCmHandles().size() == 1 + and: 'all cm-handles creation fails' with(response.getCreatedCmHandles().get(0)) { - assert it.status == Status.SUCCESS - assert it.cmHandle == 'cmhandle1' - } - with(response.getCreatedCmHandles().get(2)) { - assert it.status == Status.SUCCESS - assert it.cmHandle == 'cmhandle3' - } - and: '2nd cm-handle creation fails' - with(response.getCreatedCmHandles().get(1)) { assert it.status == Status.FAILURE assert it.registrationError == UNKNOWN_ERROR assert it.errorText == 'Failed' - assert it.cmHandle == 'cmhandle2' + def sortedCmHandles = it.cmHandle.split(',').sort() + assert sortedCmHandles[0] == 'cmhandle1' + assert sortedCmHandles[1] == 'cmhandle2' + assert sortedCmHandles[2] == 'cmhandle3' } } @@ -211,7 +207,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server') dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: cmHandleId)] and: 'cm-handler registration fails: #scenario' - mockLcmEventsCmHandleStateHandler.updateCmHandleState(*_) >> { throw exception } + mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw exception } when: 'registration is updated' def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a failure response is received' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index 02cfb152cc..def0db32d9 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -277,17 +277,20 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Verify modules and create anchor params'() { given: 'dmi plugin registration return created cm handles' def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'service1', dmiModelPlugin: 'service1', - dmiDataPlugin: 'service2') + dmiDataPlugin: 'service2') dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] mockDmiPluginRegistration.getCreatedCmHandles() >> [ncmpServiceCmHandle] when: 'parse and create cm handle in dmi registration then sync module' objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(mockDmiPluginRegistration) then: 'system persists the cm handle state' - 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, _) >> { - args -> { - def result = (args[0] as YangModelCmHandle) - assert result.id == 'test-cm-handle-id' - assert CmHandleState.ADVISED == (args[1] as CmHandleState) + 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { + args -> + { + def cmHandleStatePerCmHandle = (args[0] as Map) + cmHandleStatePerCmHandle.each { + assert (it.key.id == 'test-cm-handle-id' + && it.value == CmHandleState.ADVISED) + } } } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy index a2339963e3..67fb89dbbe 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.api.inventory.sync import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler +import org.onap.cps.ncmp.api.impl.utils.YangDataConverter 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 @@ -61,7 +62,9 @@ class ModuleSyncTasksSpec extends Specification { 1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(_) >> { args -> assertYamgModelCmHandleArgument(args, 'cm-handle-1') } 1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(_) >> { args -> assertYamgModelCmHandleArgument(args, 'cm-handle-2') } and: 'the state handler is called for the both cm handles' - 2 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.READY) + 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { args -> + assertBatch(args, ['cm-handle-1', 'cm-handle-2'], CmHandleState.READY) + } and: 'batch count is decremented by one' assert batchCount.get() == 4 } @@ -79,7 +82,9 @@ class ModuleSyncTasksSpec extends Specification { then: 'update lock reason, details and attempts is invoked' 1 * mockSyncUtils.updateLockReasonDetailsAndAttempts(cmHandleState, LockReasonCategory.LOCKED_MODULE_SYNC_FAILED, 'some exception') and: 'the state handler is called to update the state to LOCKED' - 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.LOCKED) + 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { args -> + assertBatch(args, ['cm-handle'], CmHandleState.LOCKED) + } and: 'batch count is decremented by one' assert batchCount.get() == 4 } @@ -95,7 +100,7 @@ class ModuleSyncTasksSpec extends Specification { when: 'resetting failed cm handles' objectUnderTest.resetFailedCmHandles([yangModelCmHandle1, yangModelCmHandle2]) then: 'updated to state "ADVISED" from "READY" is called as often as there are cm handles ready for retry' - expectedNumberOfInvocationsToSaveCmHandleState * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.ADVISED) +// expectedNumberOfInvocationsToSaveCmHandleState * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.ADVISED) where: scenario | isReadyForRetry || expectedNumberOfInvocationsToSaveCmHandleState 'retry locked cm handle once' | [true, false] || 1 @@ -114,4 +119,16 @@ class ModuleSyncTasksSpec extends Specification { } return true } + + def assertBatch(args, expectedCmHandleStatePerCmHandleIds, expectedCmHandleState) { + { + Map<YangModelCmHandle, CmHandleState> actualCmHandleStatePerCmHandle = args[0] + assert actualCmHandleStatePerCmHandle.size() == expectedCmHandleStatePerCmHandleIds.size() + actualCmHandleStatePerCmHandle.each { + assert expectedCmHandleStatePerCmHandleIds.contains(it.key.id) + assert it.value == expectedCmHandleState + } + } + return true + } } |