2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the 'License');
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an 'AS IS' BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.integration.functional.ncmp
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.impl.inventory.sync.ModuleSyncWatchdog
26 import java.util.concurrent.Executors
28 class ModuleSyncWatchdogIntegrationSpec extends CpsIntegrationSpecBase {
30 ModuleSyncWatchdog objectUnderTest
32 def executorService = Executors.newFixedThreadPool(2)
33 def SYNC_SAMPLE_SIZE = 100
36 objectUnderTest = moduleSyncWatchdog
37 registerSequenceOfCmHandlesWithoutWaitForReady(DMI1_URL, NO_MODULE_SET_TAG, SYNC_SAMPLE_SIZE)
42 deregisterSequenceOfCmHandles(DMI1_URL, SYNC_SAMPLE_SIZE)
43 moduleSyncWorkQueue.clear()
45 executorService.shutdownNow()
49 def 'Watchdog is disabled for test.'() {
50 when: 'wait a while but less then the initial delay of 10 minutes'
52 then: 'the work queue remains empty'
53 assert moduleSyncWorkQueue.isEmpty()
56 def 'Populate module sync work queue simultaneously on two parallel threads (CPS-2403).'() {
57 // This test failed before bug https://lf-onap.atlassian.net/browse/CPS-2403 was fixed
58 given: 'the queue is empty at the start'
59 assert moduleSyncWorkQueue.isEmpty()
60 when: 'attempt to populate the queue on the main (test) and another parallel thread at the same time'
61 objectUnderTest.populateWorkQueueIfNeeded()
62 executorService.execute(populateQueueWithoutDelay)
63 and: 'wait a little (to give all threads time to complete their task)'
65 then: 'the queue size is exactly the sample size'
66 assert moduleSyncWorkQueue.size() == SYNC_SAMPLE_SIZE
69 def 'Populate module sync work queue on two parallel threads with a slight difference in start time.'() {
70 // This test proved that the issue in CPS-2403 did not arise if the the queue was populated and given time to be distributed
71 given: 'the queue is empty at the start'
72 assert moduleSyncWorkQueue.isEmpty()
73 when: 'attempt to populate the queue on the main (test) and another parallel thread a little later'
74 objectUnderTest.populateWorkQueueIfNeeded()
75 executorService.execute(populateQueueWithDelay)
76 and: 'wait a little (to give all threads time to complete their task)'
78 then: 'the queue size is exactly the sample size'
79 assert moduleSyncWorkQueue.size() == SYNC_SAMPLE_SIZE
82 def populateQueueWithoutDelay = () -> {
84 objectUnderTest.populateWorkQueueIfNeeded()
85 } catch (InterruptedException e) {
90 def populateQueueWithDelay = () -> {
93 objectUnderTest.populateWorkQueueIfNeeded()
94 } catch (InterruptedException e) {