X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Finventory%2Fsync%2FDataSyncWatchdogSpec.groovy;h=ed313a0ad8dd70e6a7248b01fca80fa59ea0ee4c;hb=21171253eb47349832e1e1d4952a42051c19be05;hp=707f3ea3ea5617bb911394885407b8f85f65cddd;hpb=0165959c0218b4666a57d47d43a78fab1be6a894;p=cps.git diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy index 707f3ea3e..ed313a0ad 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,17 @@ package org.onap.cps.ncmp.api.inventory.sync +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME + import com.hazelcast.map.IMap import org.onap.cps.api.CpsDataService +import org.onap.cps.ncmp.api.impl.inventory.sync.DataSyncWatchdog +import org.onap.cps.ncmp.api.impl.inventory.sync.SyncUtils 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.InventoryPersistence -import org.onap.cps.ncmp.api.inventory.DataStoreSyncState +import org.onap.cps.ncmp.api.impl.inventory.CmHandleState +import org.onap.cps.ncmp.api.impl.inventory.CompositeState +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence +import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState import spock.lang.Specification class DataSyncWatchdogSpec extends Specification { @@ -37,55 +41,65 @@ class DataSyncWatchdogSpec extends Specification { def mockSyncUtils = Mock(SyncUtils) - def mockDataSyncSemaphoreMap = Mock(IMap) + def mockDataSyncSemaphores = Mock(IMap) def jsonString = '{"stores:bookstore":{"categories":[{"code":"01"}]}}' - def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils, mockDataSyncSemaphoreMap) + def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils, mockDataSyncSemaphores) def compositeState = getCompositeState() - def yangModelCmHandle1 = createSampleYangModelCmHandle('some-cm-handle-1') + def yangModelCmHandle1 = createSampleYangModelCmHandle('cm-handle-1') - def yangModelCmHandle2 = createSampleYangModelCmHandle('some-cm-handle-2') + def yangModelCmHandle2 = createSampleYangModelCmHandle('cm-handle-2') - def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED'() { + def 'Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED.'() { given: 'sample resource data' def resourceData = jsonString - and: 'sync utilities return a cm handle twice' + and: 'sync utilities returns a cm handle twice' mockSyncUtils.getUnsynchronizedReadyCmHandles() >> [yangModelCmHandle1, yangModelCmHandle2] when: 'data sync poll is executed' objectUnderTest.executeUnSynchronizedReadyCmHandlePoll() then: 'the inventory persistence cm handle returns a composite state for the first cm handle' - 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle-1') >> compositeState + 1 * mockInventoryPersistence.getCmHandleState('cm-handle-1') >> compositeState and: 'the sync util returns first resource data' - 1 * mockSyncUtils.getResourceData('some-cm-handle-1') >> resourceData + 1 * mockSyncUtils.getResourceData('cm-handle-1') >> resourceData and: 'the cm-handle data is saved' - 1 * mockCpsDataService.saveData('NFP-Operational', 'some-cm-handle-1', jsonString, _) + 1 * mockCpsDataService.saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cm-handle-1', jsonString, _) and: 'the first cm handle operational sync state is updated' - 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-1', compositeState) + 1 * mockInventoryPersistence.saveCmHandleState('cm-handle-1', compositeState) then: 'the inventory persistence cm handle returns a composite state for the second cm handle' - 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle-2') >> compositeState + 1 * mockInventoryPersistence.getCmHandleState('cm-handle-2') >> compositeState and: 'the sync util returns first resource data' - 1 * mockSyncUtils.getResourceData('some-cm-handle-2') >> resourceData + 1 * mockSyncUtils.getResourceData('cm-handle-2') >> resourceData and: 'the cm-handle data is saved' - 1 * mockCpsDataService.saveData('NFP-Operational', 'some-cm-handle-2', jsonString, _) + 1 * mockCpsDataService.saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cm-handle-2', jsonString, _) and: 'the second cm handle operational sync state is updated from "UNSYNCHRONIZED" to "SYNCHRONIZED"' - 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState) + 1 * mockInventoryPersistence.saveCmHandleState('cm-handle-2', compositeState) } - def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED which return empty data from Node'() { - given: 'cm handles in an ready state and operational sync state in unsynchronized' - and: 'sync utilities return a cm handle twice' + def 'Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED without resource data.'() { + given: 'sync utilities returns a cm handle' mockSyncUtils.getUnsynchronizedReadyCmHandles() >> [yangModelCmHandle1] when: 'data sync poll is executed' objectUnderTest.executeUnSynchronizedReadyCmHandlePoll() then: 'the inventory persistence cm handle returns a composite state for the first cm handle' - 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle-1') >> compositeState - and: 'the sync util returns first resource data' - 1 * mockSyncUtils.getResourceData('some-cm-handle-1') >> null + 1 * mockInventoryPersistence.getCmHandleState('cm-handle-1') >> compositeState + and: 'the sync util returns no resource data' + 1 * mockSyncUtils.getResourceData('cm-handle-1') >> null and: 'the cm-handle data is not saved' - 0 * mockCpsDataService.saveData('NFP-Operational', 'some-cm-handle-1', jsonString, _) + 0 * mockCpsDataService.saveData(*_) + } + + def 'Data Sync for Cm Handle that is already being processed.'() { + given: 'sync utilities returns a cm handle' + mockSyncUtils.getUnsynchronizedReadyCmHandles() >> [yangModelCmHandle1] + and: 'the shared data sync semaphore indicate it is already being processed' + mockDataSyncSemaphores.putIfAbsent('cm-handle-1', _, _, _) >> 'something (not null)' + when: 'data sync poll is executed' + objectUnderTest.executeUnSynchronizedReadyCmHandlePoll() + then: 'it is NOT processed e.g. state is not requested' + 0 * mockInventoryPersistence.getCmHandleState(*_) } def createSampleYangModelCmHandle(cmHandleId) {