Use constants for magic numbers in perf tests
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / QueryPerfTest.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 Nordix Foundation
4  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the 'License');
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an 'AS IS' BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.integration.performance.cps
23
24 import org.onap.cps.api.CpsQueryService
25 import org.onap.cps.integration.performance.base.CpsPerfTestBase
26
27 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILD_ONLY
28 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
29 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
30
31 class QueryPerfTest extends CpsPerfTestBase {
32
33     CpsQueryService objectUnderTest
34
35     def setup() { objectUnderTest = cpsQueryService }
36
37     def 'Query complete data trees with #scenario.'() {
38         when: 'query data nodes (using a fresh anchor with identical data for each test)'
39             stopWatch.start()
40             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, cpsPath, INCLUDE_ALL_DESCENDANTS)
41             stopWatch.stop()
42             def durationInMillis = stopWatch.getTotalTimeMillis()
43         then: 'the expected number of nodes is returned'
44             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
45         and: 'all data is read within #durationLimit ms'
46             recordAndAssertPerformance("Query 1 anchor ${scenario}", durationLimit, durationInMillis)
47         where: 'the following parameters are used'
48             scenario                     | anchor       | cpsPath                                                             || durationLimit | expectedNumberOfDataNodes
49             'top element'                | 'openroadm1' | '/openroadm-devices'                                                || 120           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
50             'leaf condition'             | 'openroadm2' | '//openroadm-device[@ne-state="inservice"]'                         || 200           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
51             'ancestors'                  | 'openroadm3' | '//openroadm-device/ancestor::openroadm-devices'                    || 120           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
52             'leaf condition + ancestors' | 'openroadm4' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || 120           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
53             'non-existing data'          | 'openroadm1' | '/path/to/non-existing/node[@id="1"]'                               || 10            | 0
54     }
55
56     def 'Query complete data trees across all anchors with #scenario.'() {
57         when: 'query data nodes across all anchors'
58             stopWatch.start()
59             def result = objectUnderTest.queryDataNodesAcrossAnchors('cpsPerformanceDataspace', cpspath, INCLUDE_ALL_DESCENDANTS)
60             stopWatch.stop()
61             def durationInMillis = stopWatch.getTotalTimeMillis()
62         then: 'the expected number of nodes is returned'
63             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
64         and: 'all data is read within #durationLimit ms'
65             recordAndAssertPerformance("Query across anchors ${scenario}", durationLimit, durationInMillis)
66         where: 'the following parameters are used'
67             scenario                     | cpspath                                                             || durationLimit | expectedNumberOfDataNodes
68             'top element'                | '/openroadm-devices'                                                || 400           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
69             'leaf condition'             | '//openroadm-device[@ne-state="inservice"]'                         || 700           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE)
70             'ancestors'                  | '//openroadm-device/ancestor::openroadm-devices'                    || 400           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
71             'leaf condition + ancestors' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || 400           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
72     }
73
74     def 'Query with leaf condition and #scenario.'() {
75         when: 'query data nodes (using a fresh anchor with identical data for each test)'
76             stopWatch.start()
77             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, '//openroadm-device[@status="success"]', fetchDescendantsOption)
78             stopWatch.stop()
79             def durationInMillis = stopWatch.getTotalTimeMillis()
80         then: 'the expected number of nodes is returned'
81             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
82         and: 'all data is read within #durationLimit ms'
83             recordAndAssertPerformance("Query with ${scenario}", durationLimit, durationInMillis)
84         where: 'the following parameters are used'
85             scenario             | fetchDescendantsOption  | anchor       || durationLimit | expectedNumberOfDataNodes
86             'no descendants'     | OMIT_DESCENDANTS        | 'openroadm1' || 15            | OPENROADM_DEVICES_PER_ANCHOR
87             'direct descendants' | DIRECT_CHILD_ONLY       | 'openroadm2' || 60            | OPENROADM_DEVICES_PER_ANCHOR * 2
88             'all descendants'    | INCLUDE_ALL_DESCENDANTS | 'openroadm3' || 150           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
89     }
90
91     def 'Query ancestors with #scenario.'() {
92         when: 'query data nodes (using a fresh anchor with identical data for each test)'
93             stopWatch.start()
94             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, '//openroadm-device[@ne-state="inservice"]/ancestor::openroadm-devices', fetchDescendantsOption)
95             stopWatch.stop()
96             def durationInMillis = stopWatch.getTotalTimeMillis()
97         then: 'the expected number of nodes is returned'
98             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
99         and: 'all data is read within #durationLimit ms'
100             recordAndAssertPerformance("Query ancestors with ${scenario}", durationLimit, durationInMillis)
101         where: 'the following parameters are used'
102             scenario             | fetchDescendantsOption  | anchor       || durationLimit | expectedNumberOfDataNodes
103             'no descendants'     | OMIT_DESCENDANTS        | 'openroadm1' || 15            | 1
104             'direct descendants' | DIRECT_CHILD_ONLY       | 'openroadm2' || 60            | 1 + OPENROADM_DEVICES_PER_ANCHOR
105             'all descendants'    | INCLUDE_ALL_DESCENDANTS | 'openroadm3' || 150           | 1 + OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
106     }
107
108 }