Merge "[Bug] Removing inner TaskExecutor to call DMI"
[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.apache.commons.lang3.StringUtils
24 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
25 import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncService
26 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter
27 import org.onap.cps.spi.FetchDescendantsOption
28 import org.onap.cps.spi.model.DataNode
29 import org.springframework.beans.factory.annotation.Autowired
30
31 import java.util.stream.Collectors
32 import org.onap.cps.api.CpsQueryService
33 import org.onap.cps.integration.ResourceMeter
34 import org.onap.cps.integration.performance.base.NcmpPerfTestBase
35
36 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
37 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
38
39 class CmHandleQueryPerfTest extends NcmpPerfTestBase {
40
41     static def MILLISECONDS = 0.001
42
43     CpsQueryService objectUnderTest
44     ResourceMeter resourceMeter = new ResourceMeter()
45
46     def setup() { objectUnderTest = cpsQueryService }
47
48     def 'JVM warmup.'() {
49         when: 'the JVM is warmed up'
50             def iterations = 2500 // set this to 15000 for very accurate results (but test takes much longer)
51             resourceMeter.start()
52             (1..iterations).forEach {
53                 cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
54                         '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS)
55                 objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
56                         '/dmi-registry/cm-handles[@alternate-id="alt-' + it + '"]', OMIT_DESCENDANTS)
57             }
58             resourceMeter.stop()
59         then: 'resource usage is as expected'
60             recordAndAssertResourceUsage('JVM warmup for CmHandleQueryPerfTest',
61                     30, resourceMeter.totalTimeInSeconds,
62                     300, resourceMeter.totalMemoryUsageInMB)
63     }
64
65     def 'Query CM Handle IDs by a property name and value.'() {
66         when: 'a cps-path query on name-value pair is performed (without getting descendants)'
67             resourceMeter.start()
68             def cpsPath = '//additional-properties[@name="neType" and @value="RadioNode"]/ancestor::cm-handles'
69             def dataNodes = objectUnderTest.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPath, OMIT_DESCENDANTS)
70         and: 'the ids of the result are extracted and converted to xpath'
71             def xpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
72         and: 'a single get is executed to get all the parent objects and their descendants'
73             def result = cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
74             resourceMeter.stop()
75             def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
76         then: 'the required operations are performed within required time'
77             recordAndAssertResourceUsage("CpsPath Registry attributes Query", 2, durationInSeconds, 300, resourceMeter.getTotalMemoryUsageInMB())
78         and: 'all nodes are returned'
79             result.size() == TOTAL_CM_HANDLES
80         and: 'the tree contains all the expected descendants too'
81             assert countDataNodesInTree(result) == 5 * TOTAL_CM_HANDLES
82     }
83
84     def 'CM-handle is looked up by id.'() {
85         when: 'CM-handles are looked up by cm-handle-id 100 times'
86             int count = 0
87             resourceMeter.start()
88             (1..100).each {
89                 count += cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
90                         '/dmi-registry/cm-handles[@id="cm-' + it + '"]', OMIT_DESCENDANTS).size()
91             }
92             resourceMeter.stop()
93         then:
94             assert count == 100
95         and: 'average performance is as expected'
96             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
97             recordAndAssertResourceUsage('Look up CM-handle by id',
98                     expectedAverageResponseTime, averageResponseTime,
99                     15, resourceMeter.totalMemoryUsageInMB)
100         where:
101             expectedAverageResponseTime = 1 * MILLISECONDS
102     }
103
104     def 'CM-handle is looked up by alternate-id.'() {
105         when: 'CM-handles are looked up by alternate-id 100 times'
106             int count = 0
107             resourceMeter.start()
108             (1..100).each {
109                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR,
110                         '/dmi-registry/cm-handles[@alternate-id="alt-' + it + '"]', OMIT_DESCENDANTS).size()
111             }
112             resourceMeter.stop()
113         then:
114             assert count == 100
115         and: 'average performance is as expected'
116             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
117             recordAndAssertResourceUsage('Look up CM-handle by alternate-id',
118                     expectedAverageResponseTime, averageResponseTime,
119                     15, resourceMeter.totalMemoryUsageInMB)
120         where:
121             expectedAverageResponseTime = 10 * MILLISECONDS
122     }
123
124     def 'A batch of CM-handles is looked up by alternate-id.'() {
125         given: 'a CPS Path Query to look up 100 alternate-ids in a single operation'
126             def cpsPathQuery = '/dmi-registry/cm-handles[' + (1..100).collect { "@alternate-id='alt-${it}'" }.join(' or ') + ']'
127         when: 'CM-handles are looked up by alternate-ids in a single query'
128             resourceMeter.start()
129             def count = cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
130             resourceMeter.stop()
131         then: 'expected amount of data was returned'
132             assert count == 100
133         then: 'average performance is as expected'
134             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
135             recordAndAssertResourceUsage('Batch look up CM-handle by alternate-id',
136                     expectedAverageResponseTime, averageResponseTime,
137                     15, resourceMeter.totalMemoryUsageInMB)
138         where:
139             expectedAverageResponseTime = 1 * MILLISECONDS
140     }
141
142     def 'Find any CM-handle given moduleSetTag when there are 20K READY handles with same moduleSetTag.'() {
143         given:
144             def cpsPathQuery = "/dmi-registry/cm-handles[@module-set-tag='my-module-set-tag']"
145         when: 'CM-handles are looked up by module-set-tag 100 times'
146             int count = 0
147             resourceMeter.start()
148             (1..100).each {
149                 count += cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPathQuery, OMIT_DESCENDANTS).size()
150             }
151             resourceMeter.stop()
152         then:
153             assert count == TOTAL_CM_HANDLES * 100
154         then: 'average performance is as expected'
155             def averageResponseTime = resourceMeter.totalTimeInSeconds / 100
156             recordAndAssertResourceUsage('Look up CM-handles by module-set-tag',
157                     expectedAverageResponseTime, averageResponseTime,
158                     500, resourceMeter.totalMemoryUsageInMB)
159         where:
160             expectedAverageResponseTime = 100 * MILLISECONDS
161     }
162
163 }