Merge "Add memory usage to integration tests [UPDATED]"
[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 import org.onap.cps.spi.PaginationOption
26 import java.util.concurrent.TimeUnit
27 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_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     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             resourceMeter.start()
39             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', cpsPath, INCLUDE_ALL_DESCENDANTS)
40             resourceMeter.stop()
41             def durationInMillis = resourceMeter.getTotalTimeMillis()
42         then: 'the expected number of nodes is returned'
43             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
44         and: 'all data is read within #durationLimit ms  and memory used is within limit'
45             recordAndAssertResourceUsage("Query 1 anchor ${scenario}", durationLimit, durationInMillis, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
46         where: 'the following parameters are used'
47             scenario                     | cpsPath                                                             || durationLimit                          | memoryLimit  | expectedNumberOfDataNodes
48             'top element'                | '/openroadm-devices'                                                || TimeUnit.SECONDS.toMillis(2)           | 300          | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
49             'leaf condition'             | '//openroadm-device[@ne-state="inservice"]'                         || TimeUnit.SECONDS.toMillis(3)           | 200          | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
50             'ancestors'                  | '//openroadm-device/ancestor::openroadm-devices'                    || TimeUnit.SECONDS.toMillis(2)           | 200          | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
51             'leaf condition + ancestors' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || TimeUnit.SECONDS.toMillis(2)           | 300          | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1
52     }
53
54     def 'Query complete data trees across all anchors with #scenario.'() {
55         when: 'query data nodes across all anchors'
56             resourceMeter.start()
57             def result = objectUnderTest.queryDataNodesAcrossAnchors(CPS_PERFORMANCE_TEST_DATASPACE, cpspath, INCLUDE_ALL_DESCENDANTS, PaginationOption.NO_PAGINATION)
58             resourceMeter.stop()
59             def durationInMillis = resourceMeter.getTotalTimeMillis()
60         then: 'the expected number of nodes is returned'
61             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
62         and: 'all data is read within #durationLimit ms and memory used is within limit'
63             recordAndAssertResourceUsage("Query across anchors ${scenario}", durationLimit, durationInMillis, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
64         where: 'the following parameters are used'
65             scenario                     | cpspath                                                             || durationLimit                 | memoryLimit   | expectedNumberOfDataNodes
66             'top element'                | '/openroadm-devices'                                                || TimeUnit.SECONDS.toMillis(6)  | 600           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
67             'leaf condition'             | '//openroadm-device[@ne-state="inservice"]'                         || TimeUnit.SECONDS.toMillis(6)  | 600           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE)
68             'ancestors'                  | '//openroadm-device/ancestor::openroadm-devices'                    || TimeUnit.SECONDS.toMillis(6)  | 800           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
69             'leaf condition + ancestors' | '//openroadm-device[@status="success"]/ancestor::openroadm-devices' || TimeUnit.SECONDS.toMillis(6)  | 600           | OPENROADM_ANCHORS * (OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE + 1)
70             'non-existing data'          | '/path/to/non-existing/node[@id="1"]'                               || 100                           | 3             | 0
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             resourceMeter.start()
76             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', '//openroadm-device[@status="success"]', fetchDescendantsOption)
77             resourceMeter.stop()
78             def durationInMillis = resourceMeter.getTotalTimeMillis()
79         then: 'the expected number of nodes is returned'
80             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
81         and: 'all data is read within #durationLimit ms and memory used is within limit'
82             recordAndAssertResourceUsage("Query with ${scenario}", durationLimit, durationInMillis, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
83         where: 'the following parameters are used'
84             scenario             | fetchDescendantsOption  || durationLimit                | memoryLimit   | expectedNumberOfDataNodes
85             'no descendants'     | OMIT_DESCENDANTS        || 100                          | 30            | OPENROADM_DEVICES_PER_ANCHOR
86             'direct descendants' | DIRECT_CHILDREN_ONLY    || 150                          | 30            | OPENROADM_DEVICES_PER_ANCHOR * 2
87             'all descendants'    | INCLUDE_ALL_DESCENDANTS || TimeUnit.SECONDS.toMillis(2) | 200           | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
88     }
89
90     def 'Query ancestors with #scenario.'() {
91         when: 'query data nodes (using a fresh anchor with identical data for each test)'
92             resourceMeter.start()
93             def result = objectUnderTest.queryDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm3', '//openroadm-device[@ne-state="inservice"]/ancestor::openroadm-devices', fetchDescendantsOption)
94             resourceMeter.stop()
95             def durationInMillis = resourceMeter.getTotalTimeMillis()
96         then: 'the expected number of nodes is returned'
97             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
98         and: 'all data is read within #durationLimit ms and memory used is within limit'
99             recordAndAssertResourceUsage("Query ancestors with ${scenario}", durationLimit, durationInMillis, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
100         where: 'the following parameters are used'
101             scenario             | fetchDescendantsOption  || durationLimit                | memoryLimit | expectedNumberOfDataNodes
102             'no descendants'     | OMIT_DESCENDANTS        || 100                          | 20          | 1
103             'direct descendants' | DIRECT_CHILDREN_ONLY    || 100                          | 20          | 1 + OPENROADM_DEVICES_PER_ANCHOR
104             'all descendants'    | INCLUDE_ALL_DESCENDANTS || TimeUnit.SECONDS.toMillis(2) | 200         | 1 + OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
105     }
106
107 }