Merge "Patch # 3: Data operation response event (NCMP → Client App) to comply with...
[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 class UpdatePerfTest extends CpsPerfTestBase {
28
29     CpsDataService objectUnderTest
30     def now = OffsetDateTime.now()
31
32     def setup() { objectUnderTest = cpsDataService }
33
34     def 'Update 1 data node with descendants'() {
35         given: 'a list of data nodes to update as JSON'
36             def parentNodeXpath = "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-10']"
37             def jsonData = readResourceDataFile('openroadm/innerNode.json').replace('NODE_ID_HERE', '10')
38         when: 'the fragment entities are updated by the data nodes'
39             stopWatch.start()
40             objectUnderTest.updateDataNodeAndDescendants(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', parentNodeXpath, jsonData, now)
41             stopWatch.stop()
42             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
43         then: 'update duration is under 1000 milliseconds'
44             recordAndAssertPerformance('Update 1 data node', 600, updateDurationInMillis)
45     }
46
47     def 'Batch update 10 data nodes with descendants'() {
48         given: 'a list of data nodes to update as JSON'
49             def innerNodeJson = readResourceDataFile('openroadm/innerNode.json')
50             def nodesJsonData = (20..30).collectEntries {[
51                 "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']",
52                 innerNodeJson.replace('NODE_ID_HERE', it.toString())
53             ]}
54         when: 'the fragment entities are updated by the data nodes'
55             stopWatch.start()
56             objectUnderTest.updateDataNodesAndDescendants(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', nodesJsonData, now)
57             stopWatch.stop()
58             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
59         then: 'update duration is under 5000 milliseconds'
60             recordAndAssertPerformance('Update 10 data nodes', 4000, updateDurationInMillis)
61     }
62
63     def 'Update leaves for 1 data node'() {
64         given: 'Updated json for openroadm data'
65             def jsonDataUpdated  = "{'openroadm-device':{'device-id':'C201-7-1A-10','status':'fail','ne-state':'jeopardy'}}"
66             def jsonDataOriginal = "{'openroadm-device':{'device-id':'C201-7-1A-10','status':'success','ne-state':'inservice'}}"
67         when: 'update is performed for leaves'
68             stopWatch.start()
69             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm3', "/openroadm-devices", jsonDataUpdated, now)
70             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm3', "/openroadm-devices", jsonDataOriginal, now)
71             stopWatch.stop()
72             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
73         then: 'update duration is under 750 milliseconds'
74             recordAndAssertPerformance('Update leaves for 1 data node', 750, updateDurationInMillis)
75     }
76
77     def 'Batch update leaves for 50 data nodes'() {
78         given: 'Updated json for openroadm data'
79             def jsonDataUpdated  = "{'openroadm-device':[" + (1..50).collect { "{'device-id':'C201-7-1A-" + it + "','status':'fail','ne-state':'jeopardy'}" }.join(",") + "]}"
80             def jsonDataOriginal = "{'openroadm-device':[" + (1..50).collect { "{'device-id':'C201-7-1A-" + it + "','status':'success','ne-state':'inservice'}" }.join(",") + "]}"
81         when: 'update is performed for leaves'
82             stopWatch.start()
83             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm4', "/openroadm-devices", jsonDataUpdated, now)
84             objectUnderTest.updateNodeLeaves(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm4', "/openroadm-devices", jsonDataOriginal, now)
85             stopWatch.stop()
86             def updateDurationInMillis = stopWatch.getTotalTimeMillis()
87         then: 'update duration is under 3500 milliseconds'
88             recordAndAssertPerformance('Batch update leaves for 50 data nodes', 3500, updateDurationInMillis)
89     }
90
91 }