aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServiceDeletePerfTest.groovy
blob: 428088135a3f36d01d21951916b760b186b00a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 *  ============LICENSE_START=======================================================
 *  Copyright (C) 2023 Nordix Foundation
 *  ================================================================================
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.onap.cps.spi.performance

import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.impl.CpsPersistencePerfSpecBase
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql

class CpsDataPersistenceServiceDeletePerfTest extends CpsPersistencePerfSpecBase {

    @Autowired
    CpsDataPersistenceService objectUnderTest

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Create a node with many descendants (please note, subsequent tests depend on this running first).'() {
        when: 'a node with a large number of descendants is created'
            stopWatch.start()
            createLineage(objectUnderTest, 150, 50, false)
            stopWatch.stop()
            def setupDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'setup duration is under 10 seconds'
            recordAndAssertPerformance('Setup', 10_000, setupDurationInMillis)
    }

    def 'Delete 10 children with grandchildren'() {
        when: 'child nodes are deleted'
            stopWatch.start()
            (1..10).each {
                def childPath = "${PERF_TEST_PARENT}/perf-test-child-${it}".toString()
                objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
            }
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete 10 children', 300, deleteDurationInMillis)
    }

    def 'Batch delete 100 children with grandchildren'() {
        given: 'a list of xpaths to delete'
            def xpathsToDelete = (11..110).collect {
                "${PERF_TEST_PARENT}/perf-test-child-${it}".toString()
            }
        when: 'child nodes are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpathsToDelete)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Batch delete 100 children', 300, deleteDurationInMillis)
    }

    def 'Delete 50 grandchildren (that have no descendants)'() {
        when: 'target nodes are deleted'
            stopWatch.start()
            (1..50).each {
                def grandchildPath = "${PERF_TEST_PARENT}/perf-test-child-111/perf-test-grand-child-${it}".toString()
                objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
            }
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 700 milliseconds'
            recordAndAssertPerformance('Delete 50 grandchildren', 700, deleteDurationInMillis)
    }

    def 'Batch delete 500 grandchildren (that have no descendants)'() {
        given: 'a list of xpaths to delete'
            def xpathsToDelete = []
            for (int childIndex = 0; childIndex < 10; childIndex++) {
                xpathsToDelete.addAll((1..50).collect {
                    "${PERF_TEST_PARENT}/perf-test-child-${112+childIndex}/perf-test-grand-child-${it}".toString()
                })
            }
        when: 'target nodes are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpathsToDelete)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 100 milliseconds'
            recordAndAssertPerformance('Batch delete 500 grandchildren', 100, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Create a node with many list elements (please note, subsequent tests depend on this running first).'() {
        when: 'a node with a large number of lists is created'
            stopWatch.start()
            createLineage(objectUnderTest, 150, 50, true)
            stopWatch.stop()
            def setupDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'setup duration is under 6 seconds'
            recordAndAssertPerformance('Setup lists', 6_000, setupDurationInMillis)
    }

    def 'Delete 10 whole lists'() {
        when: 'lists are deleted'
            stopWatch.start()
            (1..10).each {
                def childPath = "${PERF_TEST_PARENT}/perf-test-list-${it}".toString()
                objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, childPath)
            }
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete 10 whole lists', 300, deleteDurationInMillis)
    }

    def 'Batch delete 100 whole lists'() {
        given: 'a list of xpaths to delete'
            def xpathsToDelete = (11..110).collect {
                "${PERF_TEST_PARENT}/perf-test-list-${it}".toString()
            }
        when: 'lists are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpathsToDelete)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 600 milliseconds'
            recordAndAssertPerformance('Batch delete 100 whole lists', 600, deleteDurationInMillis)
    }

    def 'Delete 10 list elements'() {
        when: 'list elements are deleted'
            stopWatch.start()
            (1..10).each {
                def grandchildPath = "${PERF_TEST_PARENT}/perf-test-list-111[@key='${it}']".toString()
                objectUnderTest.deleteListDataNode(PERF_DATASPACE, PERF_ANCHOR, grandchildPath)
            }
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 200 milliseconds'
            recordAndAssertPerformance('Delete 10 lists elements', 200, deleteDurationInMillis)
    }

    def 'Batch delete 500 list elements'() {
        given: 'a list of xpaths to delete'
            def xpathsToDelete = []
            for (int childIndex = 0; childIndex < 10; childIndex++) {
                xpathsToDelete.addAll((1..50).collect {
                    "${PERF_TEST_PARENT}/perf-test-list-${112+childIndex}[@key='${it}']".toString()
                })
            }
        when: 'list elements are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpathsToDelete)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 100 milliseconds'
            recordAndAssertPerformance('Batch delete 500 lists elements', 100, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Delete 1 large data node'() {
        given: 'a node with a large number of descendants is created'
            createLineage(objectUnderTest, 50, 50, false)
            createLineage(objectUnderTest, 50, 50, true)
        when: 'parent node is deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete one large node', 300, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Batch delete 1 large data node'() {
        given: 'a node with a large number of descendants is created'
            createLineage(objectUnderTest, 50, 50, false)
            createLineage(objectUnderTest, 50, 50, true)
        when: 'parent node is batch deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR, [PERF_TEST_PARENT])
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Batch delete one large node', 300, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Delete root node with many descendants'() {
        given: 'a node with a large number of descendants is created'
            createLineage(objectUnderTest, 50, 50, false)
            createLineage(objectUnderTest, 50, 50, true)
        when: 'root node is deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNode(PERF_DATASPACE, PERF_ANCHOR, '/')
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete root node', 300, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Delete data nodes for an anchor'() {
        given: 'a node with a large number of descendants is created'
            createLineage(objectUnderTest, 50, 50, false)
            createLineage(objectUnderTest, 50, 50, true)
        when: 'data nodes are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, PERF_ANCHOR)
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete data nodes for anchor', 300, deleteDurationInMillis)
    }

    @Sql([CLEAR_DATA, PERF_TEST_DATA])
    def 'Delete data nodes for multiple anchors'() {
        given: 'a node with a large number of descendants is created'
            createLineage(objectUnderTest, 50, 50, false)
            createLineage(objectUnderTest, 50, 50, true)
        when: 'data nodes are deleted'
            stopWatch.start()
            objectUnderTest.deleteDataNodes(PERF_DATASPACE, [PERF_ANCHOR])
            stopWatch.stop()
            def deleteDurationInMillis = stopWatch.getTotalTimeMillis()
        then: 'delete duration is under 300 milliseconds'
            recordAndAssertPerformance('Delete data nodes for anchors', 300, deleteDurationInMillis)
    }

}