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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.spi.performance
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
29 import java.util.concurrent.TimeUnit
31 class CpsDataPersistenceServiceDeletePerfTest extends CpsPersistencePerfSpecBase {
34 CpsDataPersistenceService objectUnderTest
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)
42 def stopWatch = new StopWatch()
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'
48 createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
50 def setupDurationInMillis = stopWatch.getTotalTimeMillis()
51 and: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
52 assert setupDurationInMillis < ALLOWED_SETUP_TIME_MS
55 def 'Delete 5 children with grandchildren'() {
56 when: 'child nodes are deleted'
59 def childPath = "${PERF_TEST_PARENT}/perf-test-child-${it}".toString();
60 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
63 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
64 then: 'delete duration is under 6000 milliseconds'
65 assert deleteDurationInMillis < 6000
68 def 'Delete 50 grandchildren (that have no descendants)'() {
69 when: 'target nodes are deleted'
72 def grandchildPath = "${PERF_TEST_PARENT}/perf-test-child-6/perf-test-grand-child-${it}".toString();
73 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
76 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
77 then: 'delete duration is under 500 milliseconds'
78 assert deleteDurationInMillis < 500
81 def 'Delete 1 large data node with many descendants'() {
82 when: 'parent node is deleted'
84 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT)
86 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
87 then: 'delete duration is under 2500 milliseconds'
88 assert deleteDurationInMillis < 2500
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'
95 createLineage(objectUnderTest, NUMBER_OF_LISTS, NUMBER_OF_LIST_ELEMENTS, true)
97 def setupDurationInMillis = stopWatch.getTotalTimeMillis()
98 and: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
99 assert setupDurationInMillis < ALLOWED_SETUP_TIME_MS
102 def 'Delete 5 whole lists with many elements'() {
103 when: 'list nodes are deleted'
106 def childPath = "${PERF_TEST_PARENT}/perf-test-list-${it}".toString();
107 objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
110 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
111 then: 'delete duration is under 4000 milliseconds'
112 assert deleteDurationInMillis < 4000
115 def 'Delete 10 list elements with keys'() {
116 when: 'list elements are deleted'
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)
124 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
125 then: 'delete duration is under 6000 milliseconds'
126 assert deleteDurationInMillis < 6000
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'
135 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, '/')
137 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
138 then: 'delete duration is under 250 milliseconds'
139 assert deleteDurationInMillis < 250
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'
148 objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR)
150 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
151 then: 'delete duration is under 250 milliseconds'
152 assert deleteDurationInMillis < 250