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
28 import spock.lang.Shared
30 import java.util.concurrent.TimeUnit
32 class CpsDataPersistenceServiceDeletePerfTest extends CpsPersistencePerfSpecBase {
35 CpsDataPersistenceService objectUnderTest
37 static def NUMBER_OF_CHILDREN = 100
38 static def NUMBER_OF_GRAND_CHILDREN = 50
39 static def NUMBER_OF_LISTS = 100
40 static def NUMBER_OF_LIST_ELEMENTS = 50
41 static def ALLOWED_SETUP_TIME_MS = TimeUnit.SECONDS.toMillis(10)
43 def stopWatch = new StopWatch()
45 @Sql([CLEAR_DATA, PERF_TEST_DATA])
46 def 'Create a node with many descendants (please note, subsequent tests depend on this running first).'() {
47 when: 'a node with a large number of descendants is created'
49 createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
51 def setupDurationInMillis = stopWatch.getTotalTimeMillis()
52 then: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
53 recordAndAssertPerformance('Setup',ALLOWED_SETUP_TIME_MS, setupDurationInMillis)
56 def 'Delete 5 children with grandchildren'() {
57 when: 'child nodes are deleted'
60 def childPath = "${PERF_TEST_PARENT}/perf-test-child-${it}".toString();
61 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
64 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
65 then: 'delete duration is under 300 milliseconds'
66 recordAndAssertPerformance('Delete 5 children', 300, deleteDurationInMillis)
69 def 'Delete 50 grandchildren (that have no descendants)'() {
70 when: 'target nodes are deleted'
73 def grandchildPath = "${PERF_TEST_PARENT}/perf-test-child-6/perf-test-grand-child-${it}".toString();
74 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
77 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
78 then: 'delete duration is under 350 milliseconds'
79 recordAndAssertPerformance('Delete 50 grandchildren', 350, deleteDurationInMillis)
82 def 'Delete 1 large data node with many descendants'() {
83 when: 'parent node is deleted'
85 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT)
87 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
88 then: 'delete duration is under 250 milliseconds'
89 recordAndAssertPerformance('Delete one large node', 250, deleteDurationInMillis)
92 @Sql([CLEAR_DATA, PERF_TEST_DATA])
93 def 'Create a node with many list elements (please note, subsequent tests depend on this running first).'() {
94 given: 'a node with a large number of descendants is created'
96 createLineage(objectUnderTest, NUMBER_OF_LISTS, NUMBER_OF_LIST_ELEMENTS, true)
98 def setupDurationInMillis = stopWatch.getTotalTimeMillis()
99 and: 'setup duration is under #ALLOWED_SETUP_TIME_MS milliseconds'
100 recordAndAssertPerformance('Create node with many list elements', ALLOWED_SETUP_TIME_MS, setupDurationInMillis)
103 def 'Delete 5 whole lists with many elements'() {
104 when: 'list nodes are deleted'
107 def childPath = "${PERF_TEST_PARENT}/perf-test-list-${it}".toString();
108 objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
111 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
112 then: 'delete duration is under 1000 milliseconds'
113 recordAndAssertPerformance('Delete 5 whole lists', 1500, deleteDurationInMillis)
116 def 'Delete 10 list elements with keys'() {
117 when: 'list elements are deleted'
120 def key = it.toString()
121 def grandchildPath = "${PERF_TEST_PARENT}/perf-test-list-6[@key='${key}']"
122 objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
125 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
126 then: 'delete duration is under 1200 milliseconds'
127 recordAndAssertPerformance('Delete 10 lists elements', 1500, deleteDurationInMillis)
130 @Sql([CLEAR_DATA, PERF_TEST_DATA])
131 def 'Delete root node with many descendants'() {
132 given: 'a node with a large number of descendants is created'
133 createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
134 when: 'root node is deleted'
136 objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, '/')
138 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
139 then: 'delete duration is under 250 milliseconds'
140 recordAndAssertPerformance('Delete root node', 250, deleteDurationInMillis)
143 @Sql([CLEAR_DATA, PERF_TEST_DATA])
144 def 'Delete data nodes for an anchor'() {
145 given: 'a node with a large number of descendants is created'
146 createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
147 when: 'data nodes are deleted'
149 objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR)
151 def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
152 then: 'delete duration is under 250 milliseconds'
153 recordAndAssertPerformance('Delete data nodes for anchor', 250, deleteDurationInMillis)