e4379180c5bb96d602cf170588067d281817d79b
[cps.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.integration.performance.ncmp
22
23 import org.onap.cps.api.CpsQueryService
24 import org.onap.cps.integration.ResourceMeter
25 import org.onap.cps.integration.performance.base.NcmpPerfTestBase
26
27 import java.util.stream.Collectors
28
29 import static org.onap.cps.api.parameters.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
30 import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS
31
32 class CmHandleQueryPerfTest extends NcmpPerfTestBase {
33
34     CpsQueryService objectUnderTest
35     ResourceMeter resourceMeter = new ResourceMeter()
36
37     def setup() { objectUnderTest = cpsQueryService }
38
39     def 'JVM warmup.'() {
40         when: 'the JVM is warmed up'
41             def iterations = TOTAL_CM_HANDLES * 0.1
42             resourceMeter.start()
43             (1..iterations).forEach {
44                 cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@id='cm-${it}']", OMIT_DESCENDANTS)
45                 objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@alternate-id='alt-${it}']", OMIT_DESCENDANTS)
46             }
47             resourceMeter.stop()
48         then: 'resource usage is as expected'
49             recordAndAssertResourceUsage('NCMP:JVM warmup for CmHandleQueryPerfTest', 'JVM warmup for CmHandleQueryPerfTest', 60, resourceMeter.totalTimeInSeconds, 300, resourceMeter.totalMemoryUsageInMB)
50     }
51
52     def 'Query CM Handle IDs by a property name and value.'() {
53         when: 'a cps-path query on name-value pair is performed (without getting descendants)'
54             resourceMeter.start()
55             def cpsPath = '//additional-properties[@name="neType" and @value="RadioNode"]/ancestor::cm-handles'
56             def dataNodes = objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPath, OMIT_DESCENDANTS)
57         and: 'the ids of the result are extracted and converted to xpath'
58             def xpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
59         and: 'a single get is executed to get all the parent objects and their descendants'
60             def result = cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
61             resourceMeter.stop()
62             def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
63         then: 'the required operations are performed within required time'
64             recordAndAssertResourceUsage('NCMP:CpsPath Registry attributes Query', "CpsPath Registry attributes Query", 3, durationInSeconds, 400, resourceMeter.getTotalMemoryUsageInMB(), REFERENCE_GRAPH)
65         and: 'all nodes are returned'
66             result.size() == TOTAL_CM_HANDLES
67         and: 'the tree contains all the expected descendants too'
68             assert countDataNodesInTree(result) == 5 * TOTAL_CM_HANDLES
69     }
70
71     def 'CM-handle is looked up by id.'() {
72         when: 'CM-handles are looked up by cm-handle-id 100 times'
73             int count = 0
74             resourceMeter.start()
75             (1..100).each {
76                 count += cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
77                         '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS).size()
78             }
79             resourceMeter.stop()
80         then: '100 data node have been found'
81             assert count == 100
82         and: 'average performance is as expected'
83             recordAndAssertResourceUsage('NCMP:Look up CM-handle by id', 'Look up CM-handle by id', 0.58, resourceMeter.totalTimeInSeconds, 15, resourceMeter.totalMemoryUsageInMB)
84     }
85
86     def 'CM-handle is looked up by alternate id.'() {
87         when: 'CM-handles are looked up by alternate id 100 times'
88             int count = 0
89             resourceMeter.start()
90             (1..100).each {
91                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
92                         "/dmi-registry/cm-handles[@alternate-id='alt-${it}']", OMIT_DESCENDANTS).size()
93             }
94             resourceMeter.stop()
95         then: 'all alternate ids are resolved correctly'
96             assert count == 100
97         and: 'average performance is as expected'
98             recordAndAssertResourceUsage('NCMP:Look up CM-handle by alternate-id', 'Look up CM-handle by alternate-id', 1.75, resourceMeter.totalTimeInSeconds, 15, resourceMeter.totalMemoryUsageInMB, REFERENCE_GRAPH)
99     }
100
101     def 'A batch of CM-handles is looked up by alternate id.'() {
102         given: 'a CPS Path Query to look up 100 alternate ids in a single operation'
103             def cpsPathQuery = '/dmi-registry/cm-handles[' + (1..100).collect { "@alternate-id='alt-${it}'" }.join(' or ') + ']'
104         when: 'CM-handles are looked up by alternate ids in a single query'
105             resourceMeter.start()
106             def count = cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
107             resourceMeter.stop()
108         then: 'expected amount of data was returned'
109             assert count == 100
110         then: 'average performance is as expected'
111             recordAndAssertResourceUsage('NCMP:Batch look up CM-handle by alternate-id', 'Batch look up CM-handle by alternate-id', 0.4, resourceMeter.totalTimeInSeconds, 15, resourceMeter.totalMemoryUsageInMB)
112     }
113
114     def 'Find any CM-handle given moduleSetTag when there are 20K READY handles with same moduleSetTag.'() {
115         given:
116             def cpsPathQuery = "/dmi-registry/cm-handles[@module-set-tag='my-module-set-tag']"
117         when: 'CM-handles are looked up by module-set-tag 100 times'
118             int count = 0
119             resourceMeter.start()
120             (1..100).each {
121                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
122             }
123             resourceMeter.stop()
124         then:
125             assert count == TOTAL_CM_HANDLES * 100
126         then: 'average performance is as expected'
127             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
128             recordAndAssertResourceUsage('NCMP:Look up CM-handles by module-set-tag', 'Look up CM-handles by module-set-tag', 0.25, averageResponseTime, 500, resourceMeter.totalMemoryUsageInMB)
129     }
130
131 }