Merge "Clean up Dependencies"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / CpsDataServiceLimitsPerfTest.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 import java.util.concurrent.TimeUnit
28
29 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
30 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
31
32 class CpsDataServiceLimitsPerfTest extends CpsPerfTestBase {
33
34     CpsDataService objectUnderTest
35
36     def setup() { objectUnderTest = cpsDataService }
37
38     def 'Create 33,000 books (note further tests depend on this running first).'() {
39         given: 'an anchor containing a bookstore with one category'
40             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'limitsAnchor')
41             def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
42             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', parentNodeData, OffsetDateTime.now())
43         when: '33,000 books are added'
44             stopWatch.start()
45             for (int i = 1; i <= 33_000; i+=100) {
46                 def booksData = '{"books":[' + (i..<i+100).collect {'{ "title": "' + it + '" }' }.join(',') + ']}'
47                 cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
48             }
49             stopWatch.stop()
50             def durationInMillis = stopWatch.getTotalTimeMillis()
51         then: 'the operation completes within 25 seconds'
52             recordAndAssertPerformance("Creating 33,000 books", TimeUnit.SECONDS.toMillis(25), durationInMillis)
53     }
54
55     def 'Get data nodes from multiple xpaths 32K (2^15) limit exceeded.'() {
56         given: '33,000 xpaths'
57             def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
58         when: 'a single operation is executed to get all datanodes with given xpaths'
59             def results = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OMIT_DESCENDANTS)
60         then: '33,000 data nodes are returned'
61             assert results.size() == 33_000
62     }
63
64     def 'Delete multiple data nodes 32K (2^15) limit exceeded.'() {
65         given: 'existing data nodes'
66             def countOfDataNodesBeforeDelete = countDataNodes()
67         and: 'a list of 33,000 xpaths'
68             def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
69         when: 'a single operation is executed to delete all datanodes with given xpaths'
70             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OffsetDateTime.now())
71         then: '33,000 data nodes are deleted'
72             def countOfDataNodesAfterDelete = countDataNodes()
73             assert countOfDataNodesBeforeDelete - countOfDataNodesAfterDelete == 33_000
74     }
75
76     def 'Delete data nodes from multiple anchors 32K (2^15) limit exceeded.'() {
77         given: '33,000 anchor names'
78             def anchorNames = (1..33_000).collect { "size-of-this-name-does-not-matter-for-limit-" + it }
79         when: 'a single operation is executed to delete all datanodes in given anchors'
80             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames, OffsetDateTime.now())
81         then: 'a database exception is not thrown'
82             noExceptionThrown()
83     }
84
85     def 'Clean up test data.'() {
86         when:
87             stopWatch.start()
88             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', OffsetDateTime.now())
89             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
90             stopWatch.stop()
91             def durationInMillis = stopWatch.getTotalTimeMillis()
92         then: 'test data is deleted in 1 second'
93             recordAndAssertPerformance("Deleting test data", TimeUnit.SECONDS.toMillis(1), durationInMillis)
94     }
95
96     def countDataNodes() {
97         def results = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', DIRECT_CHILDREN_ONLY)
98         return results[0].childDataNodes.size()
99     }
100
101 }