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