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