Merge "Ajust time limits for performance tests"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / ncmp / CmHandleQueryPerfTest.groovy
1 /*
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
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
24 import org.onap.cps.api.CpsQueryService
25 import org.onap.cps.integration.ResourceMeter
26 import org.onap.cps.integration.performance.base.NcmpPerfTestBase
27
28 import java.util.stream.Collectors
29
30 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
31 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
32
33 class CmHandleQueryPerfTest extends NcmpPerfTestBase {
34
35     static def MILLISECONDS = 0.001
36
37     CpsQueryService objectUnderTest
38     ResourceMeter resourceMeter = new ResourceMeter()
39
40     def setup() { objectUnderTest = cpsQueryService }
41
42     def 'JVM warmup.'() {
43         when: 'the JVM is warmed up'
44             def iterations = 2500 // set this to 15000 for very accurate results (but test takes much longer)
45             resourceMeter.start()
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)
51             }
52             resourceMeter.stop()
53         then: 'resource usage is as expected'
54             recordAndAssertResourceUsage('JVM warmup for CmHandleQueryPerfTest',
55                     30, resourceMeter.totalTimeInSeconds,
56                     300, resourceMeter.totalMemoryUsageInMB)
57     }
58
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)'
61             resourceMeter.start()
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)
68             resourceMeter.stop()
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
76     }
77
78     def 'CM-handle is looked up by id.'() {
79         when: 'CM-handles are looked up by cm-handle-id 100 times'
80             int count = 0
81             resourceMeter.start()
82             (1..100).each {
83                 count += cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
84                         '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS).size()
85             }
86             resourceMeter.stop()
87         then:
88             assert count == 100
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)
94         where:
95             expectedAverageResponseTime = 6 * MILLISECONDS
96     }
97
98     def 'CM-handle is looked up by alternate-id.'() {
99         when: 'CM-handles are looked up by alternate-id 100 times'
100             int count = 0
101             resourceMeter.start()
102             (1..100).each {
103                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
104                         '/dmi-registry/cm-handles[@alternate-id="alt-' + it + '"]', OMIT_DESCENDANTS).size()
105             }
106             resourceMeter.stop()
107         then:
108             assert count == 100
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)
114         where:
115             expectedAverageResponseTime = 20 * MILLISECONDS
116     }
117
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()
124             resourceMeter.stop()
125         then: 'expected amount of data was returned'
126             assert count == 100
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)
132         where:
133             expectedAverageResponseTime = 1 * MILLISECONDS
134     }
135
136     def 'Find any CM-handle given moduleSetTag when there are 20K READY handles with same moduleSetTag.'() {
137         given:
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'
140             int count = 0
141             resourceMeter.start()
142             (1..100).each {
143                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
144             }
145             resourceMeter.stop()
146         then:
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)
153         where:
154             expectedAverageResponseTime = 360 * MILLISECONDS
155     }
156
157 }