4a1178bcf14cdf6c3206cef73e6eb6b207098b2b
[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  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the 'License');
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an 'AS IS' BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.integration.performance.cps
23
24 import java.time.OffsetDateTime
25 import org.onap.cps.api.CpsDataService
26 import org.onap.cps.integration.performance.base.CpsPerfTestBase
27
28 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILD_ONLY
29 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
30
31 class CpsDataServiceLimitsPerfTest extends CpsPerfTestBase {
32
33     CpsDataService objectUnderTest
34
35     def setup() { objectUnderTest = cpsDataService }
36
37     def 'Create 33,000 books (note further tests depend on this running first).'() {
38         given: 'an anchor containing a bookstore with one category'
39             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'limitsAnchor')
40             def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
41             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', parentNodeData, OffsetDateTime.now())
42         when: '33,000 books are added'
43             stopWatch.start()
44             for (int i = 1; i <= 33_000; i+=100) {
45                 def booksData = '{"books":[' + (i..<i+100).collect {'{ "title": "' + it + '" }' }.join(',') + ']}'
46                 cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
47             }
48             stopWatch.stop()
49             def durationInMillis = stopWatch.getTotalTimeMillis()
50         then: 'the operation completes within 10 seconds'
51             recordAndAssertPerformance("Creating 33,000 books", 10_000, durationInMillis)
52     }
53
54     def 'Get data nodes from multiple xpaths 32K (2^15) limit exceeded.'() {
55         given: '33,000 xpaths'
56             def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
57         when: 'a single operation is executed to get all datanodes with given xpaths'
58             def results = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OMIT_DESCENDANTS)
59         then: '33,000 data nodes are returned'
60             assert results.size() == 33_000
61     }
62
63     def 'Delete multiple data nodes 32K (2^15) limit exceeded.'() {
64         given: 'existing data nodes'
65             def countOfDataNodesBeforeDelete = countDataNodes()
66         and: 'a list of 33,000 xpaths'
67             def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
68         when: 'a single operation is executed to delete all datanodes with given xpaths'
69             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OffsetDateTime.now())
70         then: '33,000 data nodes are deleted'
71             def countOfDataNodesAfterDelete = countDataNodes()
72             assert countOfDataNodesBeforeDelete - countOfDataNodesAfterDelete == 33_000
73     }
74
75     def 'Delete data nodes from multiple anchors 32K (2^15) limit exceeded.'() {
76         given: '33,000 anchor names'
77             def anchorNames = (1..33_000).collect { "size-of-this-name-does-not-matter-for-limit-" + it }
78         when: 'a single operation is executed to delete all datanodes in given anchors'
79             objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames, OffsetDateTime.now())
80         then: 'a database exception is not thrown'
81             noExceptionThrown()
82     }
83
84     def 'Clean up test data.'() {
85         when:
86             stopWatch.start()
87             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', OffsetDateTime.now())
88             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
89             stopWatch.stop()
90             def durationInMillis = stopWatch.getTotalTimeMillis()
91         then: 'test data is deleted in 10 seconds'
92             recordAndAssertPerformance("Deleting test data", 10_000, durationInMillis)
93     }
94
95     def countDataNodes() {
96         def results = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', DIRECT_CHILD_ONLY)
97         return results[0].childDataNodes.size()
98     }
99
100 }