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.spi.impl
23 import org.onap.cps.spi.model.DataNode
24 import org.onap.cps.spi.model.DataNodeBuilder
26 class CpsPersistencePerfSpecBase extends CpsPersistenceSpecBase {
28 static final String PERF_TEST_DATA = '/data/perf-test.sql'
29 static final String PERF_DATASPACE = 'PERF-DATASPACE'
30 static final String PERF_ANCHOR = 'PERF-ANCHOR'
31 static final String PERF_TEST_PARENT = '/perf-parent-1'
33 static def xpathsToAllGrandChildren = []
35 def createLineage(cpsDataPersistenceService, numberOfChildren, numberOfGrandChildren, createLists) {
36 xpathsToAllGrandChildren = []
37 (1..numberOfChildren).each {
39 def xpathFormat = "${PERF_TEST_PARENT}/perf-test-list-${it}[@key='%d']"
40 def listElements = goForthAndMultiply(xpathFormat, numberOfGrandChildren)
41 cpsDataPersistenceService.addListElements(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT, listElements)
43 def xpathFormat = "${PERF_TEST_PARENT}/perf-test-child-${it}/perf-test-grand-child-%d"
44 def grandChildren = goForthAndMultiply(xpathFormat, numberOfGrandChildren)
45 def child = new DataNodeBuilder()
46 .withXpath("${PERF_TEST_PARENT}/perf-test-child-${it}")
47 .withChildDataNodes(grandChildren)
49 cpsDataPersistenceService.addChildDataNode(PERF_DATASPACE, PERF_ANCHOR, PERF_TEST_PARENT, child)
54 def goForthAndMultiply(xpathFormat, numberOfGrandChildren) {
55 def grandChildren = []
56 (1..numberOfGrandChildren).each {
57 def xpath = String.format(xpathFormat as String, it)
58 def grandChild = new DataNodeBuilder().withXpath(xpath).build()
59 xpathsToAllGrandChildren.add(grandChild.xpath)
60 grandChildren.add(grandChild)
65 def countDataNodes(dataNodes) {
67 for (DataNode parent : dataNodes) {
68 for (DataNode child : parent.childDataNodes) {
69 nodeCount = nodeCount + (countDataNodes(child))