summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-10-10 16:05:53 +0100
committermpriyank <priyank.maheshwari@est.tech>2022-10-13 15:57:09 +0100
commit0165959c0218b4666a57d47d43a78fab1be6a894 (patch)
treed892c48adc8cd47708ed527e35a0514eb089851d /cps-ncmp-service/src/test/groovy/org
parent3a8d153b185c69827cb5d61c1724d03dc774eee7 (diff)
TTL for module and data sync
- Added configurable ttl parameters for module sync and data sync in the application yaml - Changing strategy to set the TTLs now. Its been set for each key at the inserting time only for both the maps. - Added test scenarios to verify the configs and the TTLs. Issue-ID: CPS-1288 Change-Id: I0a95cbd1a3e540ff15e23027e79e07e9a26f4c19 Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy35
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy7
2 files changed, 37 insertions, 5 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
index 4cfc02b9e..c16d6b69b 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
@@ -28,6 +28,7 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
import java.util.concurrent.BlockingQueue
+import java.util.concurrent.TimeUnit
@SpringBootTest
@ContextConfiguration(classes = [SynchronizationCacheConfig])
@@ -40,7 +41,7 @@ class SynchronizationCacheConfigSpec extends Specification {
private IMap<String, Object> moduleSyncStartedOnCmHandles
@Autowired
- private Map<String, Boolean> dataSyncSemaphores
+ private IMap<String, Boolean> dataSyncSemaphores
def 'Embedded (hazelcast) Caches for Module and Data Sync.'() {
expect: 'system is able to create an instance of the Module Sync Work Queue'
@@ -54,4 +55,36 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'they have the correct names (in any order)'
assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores' )
}
+
+ def 'Verify configs for Distributed objects'(){
+ given: 'the Module Sync Work Queue config'
+ def queueConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncWorkQueue').config.queueConfigs.get('defaultQueueConfig')
+ and: 'the Module Sync Started Cm Handle Map config'
+ def moduleSyncStartedOnCmHandlesConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncStartedOnCmHandles').config.mapConfigs.get('moduleSyncStartedConfig')
+ and: 'the Data Sync Semaphores Map config'
+ def dataSyncSemaphoresConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config.mapConfigs.get('dataSyncSemaphoresConfig')
+ expect: 'system created instance with correct config of Module Sync Work Queue'
+ assert queueConfig.backupCount == 3
+ assert queueConfig.asyncBackupCount == 3
+ and: 'Module Sync Started Cm Handle Map has the correct settings'
+ assert moduleSyncStartedOnCmHandlesConfig.backupCount == 3
+ assert moduleSyncStartedOnCmHandlesConfig.asyncBackupCount == 3
+ and: 'Data Sync Semaphore Map has the correct settings'
+ assert dataSyncSemaphoresConfig.backupCount == 3
+ assert dataSyncSemaphoresConfig.asyncBackupCount == 3
+ }
+
+ def 'Time to Live Verify for Module Sync and Data Sync Semaphore'() {
+ when: 'the keys are inserted with a TTL'
+ moduleSyncStartedOnCmHandles.put('testKeyModuleSync', 'toBeExpired' as Object, 1000, TimeUnit.MILLISECONDS)
+ dataSyncSemaphores.put('testKeyDataSync', Boolean.TRUE, 1000, TimeUnit.MILLISECONDS)
+ then: 'the entries are present in the map'
+ assert moduleSyncStartedOnCmHandles.get('testKeyModuleSync') != null
+ assert dataSyncSemaphores.get('testKeyDataSync') != null
+ and: 'we wait for the key expiration'
+ sleep(1500)
+ and: 'the keys should be expired as TTL elapsed'
+ assert moduleSyncStartedOnCmHandles.get('testKeyModuleSync') == null
+ assert dataSyncSemaphores.get('testKeyDataSync') == null
+ }
}
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 605381970..707f3ea3e 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
@@ -20,6 +20,7 @@
package org.onap.cps.ncmp.api.inventory.sync
+import com.hazelcast.map.IMap
import org.onap.cps.api.CpsDataService
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
@@ -27,8 +28,6 @@ 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 spock.lang.Specification
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.ConcurrentMap
class DataSyncWatchdogSpec extends Specification {
@@ -38,11 +37,11 @@ class DataSyncWatchdogSpec extends Specification {
def mockSyncUtils = Mock(SyncUtils)
- def stubbedMap = Stub(ConcurrentMap)
+ def mockDataSyncSemaphoreMap = Mock(IMap<String,Boolean>)
def jsonString = '{"stores:bookstore":{"categories":[{"code":"01"}]}}'
- def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils, stubbedMap as ConcurrentHashMap)
+ def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils, mockDataSyncSemaphoreMap)
def compositeState = getCompositeState()