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