2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2024 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.integration.performance.cps
23 import java.time.OffsetDateTime
24 import org.onap.cps.api.CpsDataService
25 import org.onap.cps.integration.performance.base.CpsPerfTestBase
27 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
28 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
30 class CpsDataServiceLimitsPerfTest extends CpsPerfTestBase {
32 CpsDataService objectUnderTest
34 def setup() { objectUnderTest = cpsDataService }
36 def 'Create 33,000 books (note further tests depend on this running first).'() {
37 given: 'an anchor containing a bookstore with one category'
38 cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'limitsAnchor')
39 def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
40 cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', parentNodeData, OffsetDateTime.now())
41 when: '33,000 books are added'
43 for (int i = 1; i <= 33_000; i+=100) {
44 def booksData = '{"books":[' + (i..<i+100).collect {'{ "title": "' + it + '" }' }.join(',') + ']}'
45 cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
48 def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
49 then: 'the operation completes within 12 seconds'
50 recordAndAssertResourceUsage("Creating 33,000 books", 16, durationInSeconds, 150, resourceMeter.getTotalMemoryUsageInMB())
53 def 'Get data nodes from multiple xpaths 32K (2^15) limit exceeded.'() {
54 given: '33,000 xpaths'
55 def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
56 when: 'a single operation is executed to get all datanodes with given xpaths'
57 def results = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OMIT_DESCENDANTS)
58 then: '33,000 data nodes are returned'
59 assert results.size() == 33_000
62 def 'Delete multiple data nodes 32K (2^15) limit exceeded.'() {
63 given: 'existing data nodes'
64 def countOfDataNodesBeforeDelete = countDataNodes()
65 and: 'a list of 33,000 xpaths'
66 def xpaths = (1..33_000).collect { "/bookstore/categories[@code=1]/books[@title='${it}']".toString() }
67 when: 'a single operation is executed to delete all datanodes with given xpaths'
68 objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', xpaths, OffsetDateTime.now())
69 then: '33,000 data nodes are deleted'
70 def countOfDataNodesAfterDelete = countDataNodes()
71 assert countOfDataNodesBeforeDelete - countOfDataNodesAfterDelete == 33_000
74 def 'Delete data nodes from multiple anchors 32K (2^15) limit exceeded.'() {
75 given: '33,000 anchor names'
76 def anchorNames = (1..33_000).collect { "size-of-this-name-does-not-matter-for-limit-" + it }
77 when: 'a single operation is executed to delete all datanodes in given anchors'
78 objectUnderTest.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames, OffsetDateTime.now())
79 then: 'a database exception is not thrown'
83 def 'Clean up test data.'() {
86 cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', OffsetDateTime.now())
87 cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
89 def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
90 then: 'test data is deleted in 1 second'
91 recordAndAssertResourceUsage("Deleting test data", 0.1, durationInSeconds, 3, resourceMeter.getTotalMemoryUsageInMB())
94 def countDataNodes() {
95 def results = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', '/bookstore/categories[@code=1]', DIRECT_CHILDREN_ONLY)
96 return results[0].childDataNodes.size()