Merge "Clean up Dependencies"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / GetPerfTest.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.CpsDataService
24 import org.onap.cps.integration.performance.base.CpsPerfTestBase
25
26 import java.util.concurrent.TimeUnit
27
28 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
29 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
30 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
31
32 class GetPerfTest extends CpsPerfTestBase {
33
34     CpsDataService objectUnderTest
35
36     def setup() { objectUnderTest = cpsDataService }
37
38     def 'Read top-level node with #scenario.'() {
39         when: 'get data nodes from 1 anchor'
40             stopWatch.start()
41             def result = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', '/openroadm-devices', fetchDescendantsOption)
42             stopWatch.stop()
43             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
44             def durationInMillis = stopWatch.getTotalTimeMillis()
45         then: 'all data is read within #durationLimit ms'
46             recordAndAssertPerformance("Read datatrees with ${scenario}", durationLimit, durationInMillis)
47         where: 'the following parameters are used'
48             scenario             | fetchDescendantsOption  || durationLimit                | expectedNumberOfDataNodes
49             'no descendants'     | OMIT_DESCENDANTS        || 10                           | 1
50             'direct descendants' | DIRECT_CHILDREN_ONLY    || 50                           | 1 + OPENROADM_DEVICES_PER_ANCHOR
51             'all descendants'    | INCLUDE_ALL_DESCENDANTS || TimeUnit.SECONDS.toMillis(2) | 1 + OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
52     }
53
54     def 'Read data trees for multiple xpaths'() {
55         given: 'a collection of xpaths to get'
56             def xpaths = (1..OPENROADM_DEVICES_PER_ANCHOR).collect { "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']" }
57         when: 'get data nodes from 1 anchor'
58             stopWatch.start()
59             def result = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', xpaths, INCLUDE_ALL_DESCENDANTS)
60             stopWatch.stop()
61             def durationInMillis = stopWatch.getTotalTimeMillis()
62         then: 'requested nodes and their descendants are returned'
63             assert countDataNodesInTree(result) == OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
64         and: 'all data is read within expected time'
65             recordAndAssertPerformance("Read datatrees for multiple xpaths", TimeUnit.SECONDS.toMillis(3) , durationInMillis)
66     }
67
68     def 'Read for multiple xpaths to non-existing datanodes'() {
69         given: 'a collection of xpaths to get'
70             def xpaths = (1..50).collect { "/path/to/non-existing/node[@id='" + it + "']" }
71         when: 'get data nodes from 1 anchor'
72             stopWatch.start()
73             def result = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm2', xpaths, INCLUDE_ALL_DESCENDANTS)
74             stopWatch.stop()
75             def durationInMillis = stopWatch.getTotalTimeMillis()
76         then: 'no data is returned'
77             assert result.isEmpty()
78         and: 'the operation completes within within expected time'
79             recordAndAssertPerformance("Read non-existing xpaths", 10, durationInMillis)
80     }
81
82     def 'Read complete data trees using #scenario.'() {
83         when: 'get data nodes from 1 anchor'
84             stopWatch.start()
85             def result = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm3', xpath, INCLUDE_ALL_DESCENDANTS)
86             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
87             stopWatch.stop()
88             def durationInMillis = stopWatch.getTotalTimeMillis()
89         then: 'all data is read within expected time'
90             recordAndAssertPerformance("Read datatrees using ${scenario}", durationLimit, durationInMillis)
91         where: 'the following xpaths are used'
92             scenario                | xpath                                  || durationLimit                | expectedNumberOfDataNodes
93             'openroadm root'        | '/'                                    || TimeUnit.SECONDS.toMillis(2) | 1 + OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
94             'openroadm top element' | '/openroadm-devices'                   || TimeUnit.SECONDS.toMillis(2) | 1 + OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
95             'openroadm whole list'  | '/openroadm-devices/openroadm-device'  || TimeUnit.SECONDS.toMillis(3) | OPENROADM_DEVICES_PER_ANCHOR * OPENROADM_DATANODES_PER_DEVICE
96     }
97
98 }