5aae285d7b8291f20fbb65c728832c3ab0fb42b7
[cps.git] / cps-ri / src / test / groovy / org / onap / cps / spi / performance / CpsDataPersistenceServiceDeletePerfTest.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.spi.performance
22
23 import org.onap.cps.spi.CpsDataPersistenceService
24 import org.onap.cps.spi.impl.CpsPersistencePerfSpecBase
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.test.context.jdbc.Sql
27 import org.springframework.util.StopWatch
28
29 import java.util.concurrent.TimeUnit
30
31 class CpsDataPersistenceServiceDeletePerfTest extends CpsPersistencePerfSpecBase {
32
33     @Autowired
34     CpsDataPersistenceService objectUnderTest
35
36     static def NUMBER_OF_CHILDREN = 100
37     static def NUMBER_OF_GRAND_CHILDREN = 50
38     static def NUMBER_OF_LISTS = 100
39     static def NUMBER_OF_LIST_ELEMENTS = 50
40     static def ALLOWED_SETUP_TIME_MS = TimeUnit.SECONDS.toMillis(10)
41
42     def stopWatch = new StopWatch()
43
44     @Sql([CLEAR_DATA, PERF_TEST_DATA])
45     def 'Create a node with many descendants (please note, subsequent tests depend on this running first).'() {
46         given: 'a node with a large number of descendants is created'
47             stopWatch.start()
48             createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
49             stopWatch.stop()
50             def setupDurationInMillis = stopWatch.getTotalTimeMillis()
51         and: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
52             assert setupDurationInMillis < ALLOWED_SETUP_TIME_MS
53     }
54
55     def 'Delete 5 children with grandchildren'() {
56         when: 'child nodes are deleted'
57             stopWatch.start()
58             (1..5).each {
59                 def childPath = "${PERF_TEST_PARENT}/perf-test-child-${it}".toString();
60                 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
61             }
62             stopWatch.stop()
63             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
64         then: 'delete duration is under 6000 milliseconds'
65             assert deleteDurationInMillis < 6000
66     }
67
68     def 'Delete 50 grandchildren (that have no descendants)'() {
69         when: 'target nodes are deleted'
70             stopWatch.start()
71             (1..50).each {
72                 def grandchildPath = "${PERF_TEST_PARENT}/perf-test-child-6/perf-test-grand-child-${it}".toString();
73                 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
74             }
75             stopWatch.stop()
76             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
77         then: 'delete duration is under 500 milliseconds'
78             assert deleteDurationInMillis < 500
79     }
80
81     def 'Delete 1 large data node with many descendants'() {
82         when: 'parent node is deleted'
83             stopWatch.start()
84             objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT)
85             stopWatch.stop()
86             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
87         then: 'delete duration is under 2500 milliseconds'
88             assert deleteDurationInMillis < 2500
89     }
90
91     @Sql([CLEAR_DATA, PERF_TEST_DATA])
92     def 'Create a node with many list elements (please note, subsequent tests depend on this running first).'() {
93         given: 'a node with a large number of descendants is created'
94             stopWatch.start()
95             createLineage(objectUnderTest, NUMBER_OF_LISTS, NUMBER_OF_LIST_ELEMENTS, true)
96             stopWatch.stop()
97             def setupDurationInMillis = stopWatch.getTotalTimeMillis()
98         and: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
99             assert setupDurationInMillis < ALLOWED_SETUP_TIME_MS
100     }
101
102     def 'Delete 5 whole lists with many elements'() {
103         when: 'list nodes are deleted'
104             stopWatch.start()
105             (1..5).each {
106                 def childPath = "${PERF_TEST_PARENT}/perf-test-list-${it}".toString();
107                 objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
108             }
109             stopWatch.stop()
110             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
111         then: 'delete duration is under 4000 milliseconds'
112             assert deleteDurationInMillis < 4000
113     }
114
115     def 'Delete 10 list elements with keys'() {
116         when: 'list elements are deleted'
117             stopWatch.start()
118             (1..10).each {
119                 def key = it.toString()
120                 def grandchildPath = "${PERF_TEST_PARENT}/perf-test-list-6[@key='${key}']"
121                 objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
122             }
123             stopWatch.stop()
124             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
125         then: 'delete duration is under 6000 milliseconds'
126             assert deleteDurationInMillis < 6000
127     }
128
129     @Sql([CLEAR_DATA, PERF_TEST_DATA])
130     def 'Delete root node with many descendants'() {
131         given: 'a node with a large number of descendants is created'
132             createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
133         when: 'root node is deleted'
134             stopWatch.start()
135             objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, '/')
136             stopWatch.stop()
137             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
138         then: 'delete duration is under 250 milliseconds'
139             assert deleteDurationInMillis < 250
140     }
141
142     @Sql([CLEAR_DATA, PERF_TEST_DATA])
143     def 'Delete data nodes for an anchor'() {
144         given: 'a node with a large number of descendants is created'
145             createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
146         when: 'data nodes are deleted'
147             stopWatch.start()
148             objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR)
149             stopWatch.stop()
150             def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
151         then: 'delete duration is under 250 milliseconds'
152             assert deleteDurationInMillis < 250
153     }
154 }