Merge "Clean up Dependencies"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / UpdatePerfTest.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.integration.performance.cps
22
23 import java.time.OffsetDateTime
24 import org.onap.cps.api.CpsDataService
25 import org.onap.cps.integration.performance.base.CpsPerfTestBase
26
27 import java.util.concurrent.TimeUnit
28
29 class UpdatePerfTest extends CpsPerfTestBase {
30
31     CpsDataService objectUnderTest
32     def now = OffsetDateTime.now()
33
34     def setup() { objectUnderTest = cpsDataService }
35
36     def 'Update 1 data node with descendants'() {
37         given: 'a list of data nodes to update as JSON'
38             def parentNodeXpath = "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-10']"
39             def jsonData = readResourceDataFile('openroadm/innerNode.json').replace('NODE_ID_HERE', '10')
40         when: 'the fragment entities are updated by the data nodes'
41             stopWatch.start()
42             objectUnderTest.updateDataNodeAndDescendants(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', parentNodeXpath, jsonData, now)
43             stopWatch.stop()
44             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
45         then: 'update completes within expected time'
46             recordAndAssertPerformance('Update 1 data node', 600, updateDurationInMillis)
47     }
48
49     def 'Batch update 100 data nodes with descendants'() {
50         given: 'a list of data nodes to update as JSON'
51             def innerNodeJson = readResourceDataFile('openroadm/innerNode.json')
52             def nodesJsonData = (1..100).collectEntries {[
53                 "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']",
54                 innerNodeJson.replace('NODE_ID_HERE', it.toString())
55             ]}
56         when: 'the fragment entities are updated by the data nodes'
57             stopWatch.start()
58             objectUnderTest.updateDataNodesAndDescendants(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', nodesJsonData, now)
59             stopWatch.stop()
60             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
61         then: 'update completes within expected time'
62             recordAndAssertPerformance('Update 100 data nodes', TimeUnit.SECONDS.toMillis(30), updateDurationInMillis)
63     }
64
65     def 'Update leaves for 1 data node (twice)'() {
66         given: 'Updated json for openroadm data'
67             def jsonDataUpdated  = "{'openroadm-device':{'device-id':'C201-7-1A-10','status':'fail','ne-state':'jeopardy'}}"
68             def jsonDataOriginal = "{'openroadm-device':{'device-id':'C201-7-1A-10','status':'success','ne-state':'inservice'}}"
69         when: 'update is performed for leaves'
70             stopWatch.start()
71             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', "/openroadm-devices", jsonDataUpdated, now)
72             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', "/openroadm-devices", jsonDataOriginal, now)
73             stopWatch.stop()
74             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
75         then: 'update completes within expected time'
76             recordAndAssertPerformance('Update leaves for 1 data node', 500, updateDurationInMillis)
77     }
78
79     def 'Batch update leaves for 100 data nodes (twice)'() {
80         given: 'Updated json for openroadm data'
81             def jsonDataUpdated  = "{'openroadm-device':[" + (1..100).collect { "{'device-id':'C201-7-1A-" + it + "','status':'fail','ne-state':'jeopardy'}" }.join(",") + "]}"
82             def jsonDataOriginal = "{'openroadm-device':[" + (1..100).collect { "{'device-id':'C201-7-1A-" + it + "','status':'success','ne-state':'inservice'}" }.join(",") + "]}"
83         when: 'update is performed for leaves'
84             stopWatch.start()
85             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', "/openroadm-devices", jsonDataUpdated, now)
86             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', "/openroadm-devices", jsonDataOriginal, now)
87             stopWatch.stop()
88             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
89         then: 'update completes within expected time'
90             recordAndAssertPerformance('Batch update leaves for 100 data nodes', TimeUnit.SECONDS.toMillis(1), updateDurationInMillis)
91     }
92
93 }