78e0d01bcaa64d8d575e7cf14edec9ab9a6cf1e5
[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  *  ================================================================================
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.cps
22
23 import org.onap.cps.api.CpsQueryService
24 import org.onap.cps.integration.performance.base.CpsPerfTestBase
25
26 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
27 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
28 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
29
30 class QueryPerfTest extends CpsPerfTestBase {
31
32     CpsQueryService objectUnderTest
33
34     def setup() { objectUnderTest = cpsQueryService }
35
36     def 'Query complete data trees with #scenario.'() {
37         when: 'query data nodes (using a fresh anchor with identical data for each test)'
38             stopWatch.start()
39             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, cpsPath, INCLUDE_ALL_DESCENDANTS)
40             stopWatch.stop()
41             def durationInMillis = stopWatch.getTotalTimeMillis()
42         then: 'the expected number of nodes is returned'
43             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
44         and: 'all data is read within #durationLimit ms'
45             recordAndAssertPerformance("Query 1 anchor ${scenario}", durationLimit, durationInMillis)
46         where: 'the following parameters are used'
47             scenario                     | anchor       | cpsPath                                                             || durationLimit | expectedNumberOfDataNodes
48             'top element'                | 'openroadm1' | '/openroadm-devices'                                                || 120           | 50 * 86 + 1
49             'leaf condition'             | 'openroadm2' | '//openroadm-device[@ne-state="inservice"]'                         || 200           | 50 * 86
50             'ancestors'                  | 'openroadm3' | '//openroadm-device/ancestor::openroadm-devices'                    || 120           | 50 * 86 + 1
51             'leaf condition + ancestors' | 'openroadm4' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || 120           | 50 * 86 + 1
52             'non-existing data'          | 'openroadm1' | '/path/to/non-existing/node[@id="1"]'                               || 10            | 0
53     }
54
55     def 'Query complete data trees across all anchors with #scenario.'() {
56         when: 'query data nodes across all anchors'
57             stopWatch.start()
58             def result = objectUnderTest.queryDataNodesAcrossAnchors('cpsPerformanceDataspace', cpspath, INCLUDE_ALL_DESCENDANTS)
59             stopWatch.stop()
60             def durationInMillis = stopWatch.getTotalTimeMillis()
61         then: 'the expected number of nodes is returned'
62             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
63         and: 'all data is read within #durationLimit ms'
64             recordAndAssertPerformance("Query across anchors ${scenario}", durationLimit, durationInMillis)
65         where: 'the following parameters are used'
66             scenario                     | cpspath                                                             || durationLimit | expectedNumberOfDataNodes
67             'top element'                | '/openroadm-devices'                                                || 400           | 5 * (50 * 86 + 1)
68             'leaf condition'             | '//openroadm-device[@ne-state="inservice"]'                         || 700           | 5 * (50 * 86)
69             'ancestors'                  | '//openroadm-device/ancestor::openroadm-devices'                    || 400           | 5 * (50 * 86 + 1)
70             'leaf condition + ancestors' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || 400           | 5 * (50 * 86 + 1)
71     }
72
73     def 'Query with leaf condition and #scenario.'() {
74         when: 'query data nodes (using a fresh anchor with identical data for each test)'
75             stopWatch.start()
76             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, '//openroadm-device[@status="success"]', fetchDescendantsOption)
77             stopWatch.stop()
78             def durationInMillis = stopWatch.getTotalTimeMillis()
79         then: 'the expected number of nodes is returned'
80             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
81         and: 'all data is read within #durationLimit ms'
82             recordAndAssertPerformance("Query with ${scenario}", durationLimit, durationInMillis)
83         where: 'the following parameters are used'
84             scenario             | fetchDescendantsOption  | anchor       || durationLimit | expectedNumberOfDataNodes
85             'no descendants'     | OMIT_DESCENDANTS        | 'openroadm1' || 15            | 50
86             'direct descendants' | DIRECT_CHILDREN_ONLY    | 'openroadm2' || 60            | 50 * 2
87             'all descendants'    | INCLUDE_ALL_DESCENDANTS | 'openroadm3' || 150           | 50 * 86
88     }
89
90     def 'Query ancestors with #scenario.'() {
91         when: 'query data nodes (using a fresh anchor with identical data for each test)'
92             stopWatch.start()
93             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, '//openroadm-device[@ne-state="inservice"]/ancestor::openroadm-devices', fetchDescendantsOption)
94             stopWatch.stop()
95             def durationInMillis = stopWatch.getTotalTimeMillis()
96         then: 'the expected number of nodes is returned'
97             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
98         and: 'all data is read within #durationLimit ms'
99             recordAndAssertPerformance("Query ancestors with ${scenario}", durationLimit, durationInMillis)
100         where: 'the following parameters are used'
101             scenario             | fetchDescendantsOption  | anchor       || durationLimit | expectedNumberOfDataNodes
102             'no descendants'     | OMIT_DESCENDANTS        | 'openroadm1' || 15            | 1
103             'direct descendants' | DIRECT_CHILDREN_ONLY    | 'openroadm2' || 60            | 1 + 50
104             'all descendants'    | INCLUDE_ALL_DESCENDANTS | 'openroadm3' || 150           | 1 + 50 * 86
105     }
106
107 }