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.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 java.util.concurrent.TimeUnit
29 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
30 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
32 class CpsDataServiceLimitsPerfTest extends CpsPerfTestBase {
34 CpsDataService objectUnderTest
36 def setup() { objectUnderTest = cpsDataService }
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'
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())
50 def durationInMillis = resourceMeter.getTotalTimeMillis()
51 then: 'the operation completes within 25 seconds'
52 recordAndAssertResourceUsage("Creating 33,000 books", TimeUnit.SECONDS.toMillis(25), durationInMillis, 200, resourceMeter.getTotalMemoryUsageInMB())
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
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
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'
85 def 'Clean up test data.'() {
88 cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', OffsetDateTime.now())
89 cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
91 def durationInMillis = resourceMeter.getTotalTimeMillis()
92 then: 'test data is deleted in 1 second'
93 recordAndAssertResourceUsage("Deleting test data", TimeUnit.SECONDS.toMillis(1), durationInMillis, 200, resourceMeter.getTotalMemoryUsageInMB())
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()