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.ncmp
24 import org.onap.cps.api.CpsQueryService
25 import org.onap.cps.integration.ResourceMeter
26 import org.onap.cps.integration.performance.base.NcmpPerfTestBase
28 import java.util.stream.Collectors
30 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
31 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
33 class CmHandleQueryPerfTest extends NcmpPerfTestBase {
35 static def MILLISECONDS = 0.001
37 CpsQueryService objectUnderTest
38 ResourceMeter resourceMeter = new ResourceMeter()
40 def setup() { objectUnderTest = cpsQueryService }
43 when: 'the JVM is warmed up'
44 def iterations = 2500 // set this to 15000 for very accurate results (but test takes much longer)
46 (1..iterations).forEach {
47 cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
48 '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS)
49 objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
50 '/dmi-registry/cm-handles[@alternate-id="alt-' + it + '"]', OMIT_DESCENDANTS)
53 then: 'resource usage is as expected'
54 recordAndAssertResourceUsage('JVM warmup for CmHandleQueryPerfTest',
55 30, resourceMeter.totalTimeInSeconds,
56 300, resourceMeter.totalMemoryUsageInMB)
59 def 'Query CM Handle IDs by a property name and value.'() {
60 when: 'a cps-path query on name-value pair is performed (without getting descendants)'
62 def cpsPath = '//additional-properties[@name="neType" and @value="RadioNode"]/ancestor::cm-handles'
63 def dataNodes = objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPath, OMIT_DESCENDANTS)
64 and: 'the ids of the result are extracted and converted to xpath'
65 def xpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
66 and: 'a single get is executed to get all the parent objects and their descendants'
67 def result = cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
69 def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
70 then: 'the required operations are performed within required time'
71 recordAndAssertResourceUsage("CpsPath Registry attributes Query", 3.4, durationInSeconds, 300, resourceMeter.getTotalMemoryUsageInMB())
72 and: 'all nodes are returned'
73 result.size() == TOTAL_CM_HANDLES
74 and: 'the tree contains all the expected descendants too'
75 assert countDataNodesInTree(result) == 5 * TOTAL_CM_HANDLES
78 def 'CM-handle is looked up by id.'() {
79 when: 'CM-handles are looked up by cm-handle-id 100 times'
83 count += cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
84 '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS).size()
89 and: 'average performance is as expected'
90 def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
91 recordAndAssertResourceUsage('Look up CM-handle by id',
92 expectedAverageResponseTime, averageResponseTime,
93 15, resourceMeter.totalMemoryUsageInMB)
95 expectedAverageResponseTime = 6 * MILLISECONDS
98 def 'CM-handle is looked up by alternate-id.'() {
99 when: 'CM-handles are looked up by alternate-id 100 times'
101 resourceMeter.start()
103 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
104 '/dmi-registry/cm-handles[@alternate-id="alt-' + it + '"]', OMIT_DESCENDANTS).size()
109 and: 'average performance is as expected'
110 def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
111 recordAndAssertResourceUsage('Look up CM-handle by alternate-id',
112 expectedAverageResponseTime, averageResponseTime,
113 15, resourceMeter.totalMemoryUsageInMB)
115 expectedAverageResponseTime = 20 * MILLISECONDS
118 def 'A batch of CM-handles is looked up by alternate-id.'() {
119 given: 'a CPS Path Query to look up 100 alternate-ids in a single operation'
120 def cpsPathQuery = '/dmi-registry/cm-handles[' + (1..100).collect { "@alternate-id='alt-${it}'" }.join(' or ') + ']'
121 when: 'CM-handles are looked up by alternate-ids in a single query'
122 resourceMeter.start()
123 def count = cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
125 then: 'expected amount of data was returned'
127 then: 'average performance is as expected'
128 def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
129 recordAndAssertResourceUsage('Batch look up CM-handle by alternate-id',
130 expectedAverageResponseTime, averageResponseTime,
131 15, resourceMeter.totalMemoryUsageInMB)
133 expectedAverageResponseTime = 1 * MILLISECONDS
136 def 'Find any CM-handle given moduleSetTag when there are 20K READY handles with same moduleSetTag.'() {
138 def cpsPathQuery = "/dmi-registry/cm-handles[@module-set-tag='my-module-set-tag']"
139 when: 'CM-handles are looked up by module-set-tag 100 times'
141 resourceMeter.start()
143 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
147 assert count == TOTAL_CM_HANDLES * 100
148 then: 'average performance is as expected'
149 def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
150 recordAndAssertResourceUsage('Look up CM-handles by module-set-tag',
151 expectedAverageResponseTime, averageResponseTime,
152 500, resourceMeter.totalMemoryUsageInMB)
154 expectedAverageResponseTime = 360 * MILLISECONDS