27ec66f30d3719858fc2cf06a8a896be47ed1871
[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     static def MILLISECONDS = 0.001
35
36     CpsQueryService objectUnderTest
37     ResourceMeter resourceMeter = new ResourceMeter()
38
39     def setup() { objectUnderTest = cpsQueryService }
40
41     def 'JVM warmup.'() {
42         when: 'the JVM is warmed up'
43             def iterations = 2500 // set this to 15000 for very accurate results (but test takes much longer)
44             resourceMeter.start()
45             (1..iterations).forEach {
46                 cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS)
47                 objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@alternate-id="alt=' + it + '"]', OMIT_DESCENDANTS)
48             }
49             resourceMeter.stop()
50         then: 'resource usage is as expected'
51             recordAndAssertResourceUsage('JVM warmup for CmHandleQueryPerfTest', 60, resourceMeter.totalTimeInSeconds, 300, resourceMeter.totalMemoryUsageInMB)
52     }
53
54     def 'Query CM Handle IDs by a property name and value.'() {
55         when: 'a cps-path query on name-value pair is performed (without getting descendants)'
56             resourceMeter.start()
57             def cpsPath = '//additional-properties[@name="neType" and @value="RadioNode"]/ancestor::cm-handles'
58             def dataNodes = objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPath, OMIT_DESCENDANTS)
59         and: 'the ids of the result are extracted and converted to xpath'
60             def xpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
61         and: 'a single get is executed to get all the parent objects and their descendants'
62             def result = cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
63             resourceMeter.stop()
64             def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
65         then: 'the required operations are performed within required time'
66             recordAndAssertResourceUsage("CpsPath Registry attributes Query", 2.4, durationInSeconds, 400, resourceMeter.getTotalMemoryUsageInMB())
67         and: 'all nodes are returned'
68             result.size() == TOTAL_CM_HANDLES
69         and: 'the tree contains all the expected descendants too'
70             assert countDataNodesInTree(result) == 5 * TOTAL_CM_HANDLES
71     }
72
73     def 'CM-handle is looked up by id.'() {
74         when: 'CM-handles are looked up by cm-handle-id 100 times'
75             int count = 0
76             resourceMeter.start()
77             (1..100).each {
78                 count += cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
79                         '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS).size()
80             }
81             resourceMeter.stop()
82         then:
83             assert count == 100
84         and: 'average performance is as expected'
85             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
86             recordAndAssertResourceUsage('Look up CM-handle by id', 0.003, averageResponseTime, 15, resourceMeter.totalMemoryUsageInMB)
87     }
88
89     def 'CM-handle is looked up by alternate-id.'() {
90         when: 'CM-handles are looked up by alternate-id 1000 times'
91             int count = 0
92             resourceMeter.start()
93             (1..1000).each {
94                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
95                         '/dmi-registry/cm-handles[@alternate-id="alt=/a/b/c/d-' + it + '"]', OMIT_DESCENDANTS).size()
96             }
97             resourceMeter.stop()
98         then:
99             assert count == 1000
100         and: 'average performance is as expected'
101             def averageResponseTime = resourceMeter.totalTimeInSeconds / 1000
102             recordAndAssertResourceUsage('Look up CM-handle by alternate-id', 0.001, averageResponseTime, 15, resourceMeter.totalMemoryUsageInMB)
103     }
104
105     def 'A batch of CM-handles is looked up by alternate-id.'() {
106         given: 'a CPS Path Query to look up 100 alternate-ids in a single operation'
107             def cpsPathQuery = '/dmi-registry/cm-handles[' + (1..100).collect { "@alternate-id='alt=${it}'" }.join(' or ') + ']'
108         when: 'CM-handles are looked up by alternate-ids in a single query'
109             resourceMeter.start()
110             def count = cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
111             resourceMeter.stop()
112         then: 'expected amount of data was returned'
113             assert count == 100
114         then: 'average performance is as expected'
115             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
116             recordAndAssertResourceUsage('Batch look up CM-handle by alternate-id',
117                     expectedAverageResponseTime, averageResponseTime,
118                     15, resourceMeter.totalMemoryUsageInMB)
119         where:
120             expectedAverageResponseTime = 4 * MILLISECONDS
121     }
122
123     def 'Find any CM-handle given moduleSetTag when there are 20K READY handles with same moduleSetTag.'() {
124         given:
125             def cpsPathQuery = "/dmi-registry/cm-handles[@module-set-tag='my-module-set-tag']"
126         when: 'CM-handles are looked up by module-set-tag 100 times'
127             int count = 0
128             resourceMeter.start()
129             (1..100).each {
130                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
131             }
132             resourceMeter.stop()
133         then:
134             assert count == TOTAL_CM_HANDLES * 100
135         then: 'average performance is as expected'
136             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
137             recordAndAssertResourceUsage('Look up CM-handles by module-set-tag', 0.26, averageResponseTime, 500, resourceMeter.totalMemoryUsageInMB)
138     }
139
140 }