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