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