From a096a7faa35b345c765102201a5a09cc03ef541a Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 20 Oct 2022 18:34:29 +0100 Subject: Read Performance Improvement - Using Native Query - Native query for FragmentExtracts - Convert FragmentExtracts to tree of FragmentEntity - Native Query now used for all Gets with descendants (orignal hibernate option only used when descendanst ommited) - Added error handling for not-found on native query - Ommit descendants by default on many udpate use-cases (this might have a signifcant perf. improvemnt impact too) - Improved legacy tests for delete use-cases - Corrected performace test expectation - Fix TTL test realizing TTL resolution is whole seconds! Issue-ID: CPS-1301 Signed-off-by: ToineSiebelink Change-Id: I658ac1b7b7036f01050f30bdf9e5bd175725ef1d --- .../SynchronizationCacheConfigSpec.groovy | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'cps-ncmp-service/src/test') 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 c16d6b69b6..868ee7a705 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 @@ -74,17 +74,30 @@ class SynchronizationCacheConfigSpec extends Specification { 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' + def 'Time to Live Verify for Module Sync Semaphore'() { + when: 'the key is inserted with a TTL of 1 second (Hazelcast TTL resolution is seconds!)' + moduleSyncStartedOnCmHandles.put('testKeyModuleSync', 'toBeExpired' as Object, 1, TimeUnit.SECONDS) + then: 'the entry is present in the map' assert moduleSyncStartedOnCmHandles.get('testKeyModuleSync') != null + and: 'the entry expires in less then 2 seconds' + waitMax2SecondsForKeyExpiration(moduleSyncStartedOnCmHandles, 'testKeyModuleSync') + } + + def 'Time to Live Verify for Data Sync Semaphore'() { + when: 'the key is inserted with a TTL of 1 second' + dataSyncSemaphores.put('testKeyDataSync', Boolean.TRUE, 1, TimeUnit.SECONDS) + then: 'the entry is present in the map' 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 + and: 'the entry expires in less then 2 seconds' + waitMax2SecondsForKeyExpiration(dataSyncSemaphores, 'testKeyDataSync') } + + def waitMax2SecondsForKeyExpiration(map, key) { + def count = 0 + while ( map.get(key)!=null && ++count <= 20 ) { + sleep(100) + } + return count < 20 // Should have expired in less the 20 x 100ms = 2 seconds! + } + } -- cgit 1.2.3-korg