2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * Modifications Copyright (C) 2022 Bell Canada
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.ncmp.api.inventory.sync
24 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
26 import java.util.concurrent.ArrayBlockingQueue
27 import java.util.concurrent.BlockingQueue
28 import org.onap.cps.spi.model.DataNode
29 import spock.lang.Specification
31 class ModuleSyncWatchdogSpec extends Specification {
33 def mockSyncUtils = Mock(SyncUtils)
35 def static testQueueCapacity = 50 + 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE
37 BlockingQueue<DataNode> moduleSyncWorkQueue = new ArrayBlockingQueue(testQueueCapacity)
39 def moduleSyncStartedOnCmHandles = [:]
41 def mockModuleSyncTasks = Mock(ModuleSyncTasks)
43 def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, moduleSyncWorkQueue , moduleSyncStartedOnCmHandles, mockModuleSyncTasks)
45 def 'Module sync #scenario , #numberOfAdvisedCmHandles advised cm handles.'() {
46 given: 'sync utilities returns #numberOfAdvisedCmHandles advised cm handles'
47 mockSyncUtils.getAdvisedCmHandles() >> createDataNodes(numberOfAdvisedCmHandles)
48 when: ' module sync is started'
49 objectUnderTest.moduleSyncAdvisedCmHandles()
50 then: 'it performs #expectedNumberOfTaskExecutions tasks'
51 expectedNumberOfTaskExecutions * mockModuleSyncTasks.performModuleSync(_)
53 scenario | numberOfAdvisedCmHandles || expectedNumberOfTaskExecutions
54 'less then 1 batch' | 1 || 1
55 'exactly 1 batch' | ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 1
56 '2 batches' | 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 2
57 'queue capacity' | testQueueCapacity || 3
58 'over queue capacity' | testQueueCapacity + 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 3
61 def 'Reset failed cm handles.'() {
62 given: 'sync utilities returns failed cm handles'
63 def failedCmHandles = [new YangModelCmHandle()]
64 mockSyncUtils.getModuleSyncFailedCmHandles() >> failedCmHandles
65 when: ' reset failed cm handles is started'
66 objectUnderTest.resetPreviouslyFailedCmHandles()
67 then: 'it is delegated to the module sync task (service)'
68 1 * mockModuleSyncTasks.resetFailedCmHandles(failedCmHandles)
71 def createDataNodes(numberOfDataNodes) {
73 (1..numberOfDataNodes).each {dataNodes.add(new DataNode())}