Merge "Performance test of reading non-existing datanodes"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / DeletePerfTest.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 org.onap.cps.spi.exceptions.DataNodeNotFoundException
24
25 import java.time.OffsetDateTime
26 import org.onap.cps.api.CpsDataService
27 import org.onap.cps.integration.performance.base.CpsPerfTestBase
28
29 class DeletePerfTest extends CpsPerfTestBase {
30
31     CpsDataService objectUnderTest
32
33     def setup() { objectUnderTest = cpsDataService }
34
35     def 'Create test data (please note, subsequent tests depend on this running first).'() {
36         when: 'multiple anchors with a node with a large number of descendants is created'
37             stopWatch.start()
38             def data = generateOpenRoadData(50)
39             addAnchorsWithData(10, CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'delete', data)
40             stopWatch.stop()
41             def setupDurationInMillis = stopWatch.getTotalTimeMillis()
42         then: 'setup duration is under 40 seconds'
43             recordAndAssertPerformance('Delete test setup', 40_000, setupDurationInMillis)
44     }
45
46     def 'Delete 10 container nodes'() {
47         when: 'child nodes are deleted'
48             stopWatch.start()
49             (1..10).each {
50                 def childPath = "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']/org-openroadm-device"
51                 objectUnderTest.deleteDataNode(CPS_PERFORMANCE_TEST_DATASPACE, 'delete1', childPath, OffsetDateTime.now())
52             }
53             stopWatch.stop()
54             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
55         then: 'delete duration is under 300 milliseconds'
56             recordAndAssertPerformance('Delete 10 containers', 300, deleteDurationInMillis)
57     }
58
59     def 'Batch delete 50 container nodes'() {
60         given: 'a list of xpaths to delete'
61             def xpathsToDelete = (1..50).collect {
62                 "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']/org-openroadm-device"
63             }
64         when: 'child nodes are deleted'
65             stopWatch.start()
66             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'delete2', xpathsToDelete, OffsetDateTime.now())
67             stopWatch.stop()
68             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
69         then: 'delete duration is under 300 milliseconds'
70             recordAndAssertPerformance('Batch delete 50 containers', 300, deleteDurationInMillis)
71     }
72
73     def 'Delete 20 list elements'() {
74         when: 'list elements are deleted'
75             stopWatch.start()
76             (1..20).each {
77                 def listElementXpath = "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-1']/org-openroadm-device/degree[@degree-number=" + it + "]"
78                 objectUnderTest.deleteDataNode(CPS_PERFORMANCE_TEST_DATASPACE, 'delete3', listElementXpath, OffsetDateTime.now())
79             }
80             stopWatch.stop()
81             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
82         then: 'delete duration is under 300 milliseconds'
83             recordAndAssertPerformance('Delete 20 lists elements', 300, deleteDurationInMillis)
84     }
85
86     def 'Batch delete 1000 list elements'() {
87         given: 'a list of xpaths to delete'
88             def xpathsToDelete = []
89             for (int childIndex = 1; childIndex <= 50; childIndex++) {
90                 xpathsToDelete.addAll((1..20).collect {
91                     "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-${childIndex}']/org-openroadm-device/degree[@degree-number=${it}]".toString()
92                 })
93             }
94         when: 'list elements are deleted'
95             stopWatch.start()
96             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'delete4', xpathsToDelete, OffsetDateTime.now())
97             stopWatch.stop()
98             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
99         then: 'delete duration is under 300 milliseconds'
100             recordAndAssertPerformance('Batch delete 1000 lists elements', 300, deleteDurationInMillis)
101     }
102
103     def 'Delete 10 whole lists'() {
104         when: 'lists are deleted'
105             stopWatch.start()
106             (1..10).each {
107                 def childPath = "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']/org-openroadm-device/degree"
108                 objectUnderTest.deleteDataNode(CPS_PERFORMANCE_TEST_DATASPACE, 'delete5', childPath, OffsetDateTime.now())
109             }
110             stopWatch.stop()
111             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
112         then: 'delete duration is under 300 milliseconds'
113             recordAndAssertPerformance('Delete 10 whole lists', 300, deleteDurationInMillis)
114     }
115
116     def 'Batch delete 30 whole lists'() {
117         given: 'a list of xpaths to delete'
118             def xpathsToDelete = (1..30).collect {
119                 "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']/org-openroadm-device/degree"
120             }
121         when: 'lists are deleted'
122             stopWatch.start()
123             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'delete6', xpathsToDelete, OffsetDateTime.now())
124             stopWatch.stop()
125             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
126         then: 'delete duration is under 300 milliseconds'
127             recordAndAssertPerformance('Batch delete 30 whole lists', 300, deleteDurationInMillis)
128     }
129
130     def 'Delete 1 large data node'() {
131         when: 'parent node is deleted'
132             stopWatch.start()
133             objectUnderTest.deleteDataNode(CPS_PERFORMANCE_TEST_DATASPACE, 'delete7', '/openroadm-devices', OffsetDateTime.now())
134             stopWatch.stop()
135             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
136         then: 'delete duration is under 300 milliseconds'
137             recordAndAssertPerformance('Delete one large node', 300, deleteDurationInMillis)
138     }
139
140     def 'Delete root node with many descendants'() {
141         when: 'root node is deleted'
142             stopWatch.start()
143             objectUnderTest.deleteDataNode(CPS_PERFORMANCE_TEST_DATASPACE, 'delete8', '/', OffsetDateTime.now())
144             stopWatch.stop()
145             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
146         then: 'delete duration is under 300 milliseconds'
147             recordAndAssertPerformance('Delete root node', 300, deleteDurationInMillis)
148     }
149
150     def 'Delete data nodes for an anchor'() {
151         when: 'data nodes are deleted'
152             stopWatch.start()
153             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'delete9', OffsetDateTime.now())
154             stopWatch.stop()
155             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
156         then: 'delete duration is under 300 milliseconds'
157             recordAndAssertPerformance('Delete data nodes for anchor', 300, deleteDurationInMillis)
158     }
159
160     def 'Batch delete 100 non-existing nodes'() {
161         given: 'a list of xpaths to delete'
162             def xpathsToDelete = (1..100).collect { "/path/to/non-existing/node[@id='" + it + "']" }
163         when: 'child nodes are deleted'
164             stopWatch.start()
165             try {
166                 objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'delete10', xpathsToDelete, OffsetDateTime.now())
167             } catch (DataNodeNotFoundException ignored) {}
168             stopWatch.stop()
169             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
170         then: 'delete duration is under 300 milliseconds'
171             recordAndAssertPerformance('Batch delete 100 non-existing', 300, deleteDurationInMillis)
172     }
173
174     def 'Clean up test data'() {
175         given: 'a list of anchors to delete'
176             def anchorNames = (1..10).collect {'delete' + it}
177         when: 'data nodes are deleted'
178             stopWatch.start()
179             cpsAdminService.deleteAnchors(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames)
180             stopWatch.stop()
181             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
182         then: 'delete duration is under 1000 milliseconds'
183             recordAndAssertPerformance('Delete test cleanup', 1000, deleteDurationInMillis)
184     }
185
186 }