2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022-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.performance
23 import org.onap.cps.spi.impl.CpsPersistencePerfSpecBase
24 import org.onap.cps.spi.CpsDataPersistenceService
25 import org.onap.cps.spi.repository.AnchorRepository
26 import org.onap.cps.spi.repository.DataspaceRepository
27 import org.onap.cps.spi.repository.FragmentRepository
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.test.context.jdbc.Sql
31 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
32 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
34 class CpsDataPersistenceServicePerfTest extends CpsPersistencePerfSpecBase {
37 CpsDataPersistenceService objectUnderTest
40 DataspaceRepository dataspaceRepository
43 AnchorRepository anchorRepository
46 FragmentRepository fragmentRepository
48 static def NUMBER_OF_CHILDREN = 200
49 static def NUMBER_OF_GRAND_CHILDREN = 50
51 @Sql([CLEAR_DATA, PERF_TEST_DATA])
52 def 'Create a node with many descendants (please note, subsequent tests depend on this running first).'() {
53 given: 'a node with a large number of descendants is created'
55 createLineage(objectUnderTest, NUMBER_OF_CHILDREN, NUMBER_OF_GRAND_CHILDREN, false)
57 def setupDurationInMillis = stopWatch.getTotalTimeMillis()
58 and: 'setup duration is under 10 seconds'
59 recordAndAssertPerformance('Setup', 10000, setupDurationInMillis)
62 def 'Update data nodes with descendants'() {
63 given: 'a list of xpaths to data nodes with descendants (xpath for each child)'
64 def xpaths = (1..20).collect {
65 "${PERF_TEST_PARENT}/perf-test-child-${it}".toString()
67 and: 'the correct number of data nodes are fetched'
68 def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(PERF_DATASPACE, PERF_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
69 assert dataNodes.size() == 20
70 assert countDataNodes(dataNodes) == 20 + 20 * 50
71 when: 'the fragment entities are updated by the data nodes'
73 objectUnderTest.updateDataNodesAndDescendants(PERF_DATASPACE, PERF_ANCHOR, dataNodes)
75 def updateDurationInMillis = stopWatch.getTotalTimeMillis()
76 then: 'update duration is under 600 milliseconds'
77 recordAndAssertPerformance('Update data nodes with descendants', 600, updateDurationInMillis)
80 def 'Update data nodes without descendants'() {
81 given: 'a list of xpaths to data nodes without descendants (xpath for each grandchild)'
83 for (int childIndex = 21; childIndex <= 40; childIndex++) {
84 xpaths.addAll((1..50).collect {
85 "${PERF_TEST_PARENT}/perf-test-child-${childIndex}/perf-test-grand-child-${it}".toString()
88 and: 'the correct number of data nodes are fetched'
89 def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(PERF_DATASPACE, PERF_ANCHOR, xpaths, OMIT_DESCENDANTS)
90 assert dataNodes.size() == 20 * 50
91 assert countDataNodes(dataNodes) == 20 * 50
92 when: 'the fragment entities are updated by the data nodes'
94 objectUnderTest.updateDataNodesAndDescendants(PERF_DATASPACE, PERF_ANCHOR, dataNodes)
96 def updateDurationInMillis = stopWatch.getTotalTimeMillis()
97 then: 'update duration is under 900 milliseconds'
98 recordAndAssertPerformance('Update data nodes without descendants', 900, updateDurationInMillis)