ea5db69dc299c8b13b629ac227540aba76d339e9
[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  *  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.CpsDataService
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 GetPerfTest extends CpsPerfTestBase {
32
33     CpsDataService objectUnderTest
34
35     def setup() { objectUnderTest = cpsDataService }
36
37     def 'Read top-level node with #scenario.'() {
38         when: 'get data nodes from 1 anchor'
39             stopWatch.start()
40             def result = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchor, '/openroadm-devices', fetchDescendantsOption)
41             stopWatch.stop()
42             assert countDataNodesInTree(result) == expectedNumberOfDataNodes
43             def durationInMillis = stopWatch.getTotalTimeMillis()
44         then: 'all data is read within #durationLimit ms'
45             recordAndAssertPerformance("Read datatrees with ${scenario}", durationLimit, durationInMillis)
46         where: 'the following parameters are used'
47             scenario             | fetchDescendantsOption  | anchor       || durationLimit | expectedNumberOfDataNodes
48             'no descendants'     | OMIT_DESCENDANTS        | 'openroadm1' || 20            | 1
49             'direct descendants' | DIRECT_CHILD_ONLY       | 'openroadm2' || 100           | 1 + 50
50             'all descendants'    | INCLUDE_ALL_DESCENDANTS | 'openroadm3' || 200           | 1 + 50 * 86
51     }
52
53     def 'Read data trees for multiple xpaths'() {
54         given: 'a collection of xpaths to get'
55             def xpaths = (1..50).collect { "/openroadm-devices/openroadm-device[@device-id='C201-7-1A-" + it + "']" }
56         when: 'get data nodes from 1 anchor'
57             stopWatch.start()
58             def result = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm4', xpaths, INCLUDE_ALL_DESCENDANTS)
59             stopWatch.stop()
60             def durationInMillis = stopWatch.getTotalTimeMillis()
61         then: 'requested nodes and their descendants are returned'
62             assert countDataNodesInTree(result) == 50 * 86
63         and: 'all data is read within 200 ms'
64             recordAndAssertPerformance("Read datatrees for multiple xpaths", 200, durationInMillis)
65     }
66
67     def 'Read for multiple xpaths to non-existing datanodes'() {
68         given: 'a collection of xpaths to get'
69             def xpaths = (1..50).collect { "/path/to/non-existing/node[@id='" + it + "']" }
70         when: 'get data nodes from 1 anchor'
71             stopWatch.start()
72             def result = objectUnderTest.getDataNodesForMultipleXpaths(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm4', xpaths, INCLUDE_ALL_DESCENDANTS)
73             stopWatch.stop()
74             def durationInMillis = stopWatch.getTotalTimeMillis()
75         then: 'no data is returned'
76             assert result.isEmpty()
77         and: 'the operation completes within within 20 ms'
78             recordAndAssertPerformance("Read non-existing xpaths", 20, durationInMillis)
79     }
80
81     def 'Read complete data trees using #scenario.'() {
82         when: 'get data nodes for 5 anchors'
83             stopWatch.start()
84             (1..5).each {
85                 def result = objectUnderTest.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, anchorPrefix + it, xpath, INCLUDE_ALL_DESCENDANTS)
86                 assert countDataNodesInTree(result) == expectedNumberOfDataNodes
87             }
88             stopWatch.stop()
89             def durationInMillis = stopWatch.getTotalTimeMillis()
90         then: 'all data is read within #durationLimit ms'
91             recordAndAssertPerformance("Read datatrees using ${scenario}", durationLimit, durationInMillis)
92         where: 'the following xpaths are used'
93             scenario                | anchorPrefix | xpath                                  || durationLimit | expectedNumberOfDataNodes
94             'bookstore root'        | 'bookstore'  | '/'                                    || 200           | 78
95             'bookstore top element' | 'bookstore'  | '/bookstore'                           || 200           | 78
96             'openroadm root'        | 'openroadm'  | '/'                                    || 600           | 1 + 50 * 86
97             'openroadm top element' | 'openroadm'  | '/openroadm-devices'                   || 600           | 1 + 50 * 86
98             'openroadm whole list'  | 'openroadm'  | '/openroadm-devices/openroadm-device'  || 600           | 50 * 86
99     }
100
101 }