Merge "Forward Subscription Information to DMI Plugin(s)"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / ncmp / CmHandleQueryPerfTest.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.ncmp
22
23 import java.util.stream.Collectors
24 import org.onap.cps.integration.performance.base.NcmpRegistryPerfTestBase
25 import org.springframework.dao.DataAccessResourceFailureException
26 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
27 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
28
29 class CmHandleQueryPerfTest extends NcmpRegistryPerfTestBase {
30
31     def objectUnderTest
32
33     def setup() { objectUnderTest = cpsQueryService }
34
35     def 'Query CM Handle IDs by a property name and value.'() {
36         when: 'a cps-path query on name-value pair is performed (without getting descendants)'
37             stopWatch.start()
38             def cpsPath = '//additional-properties[@name="neType" and @value="RadioNode"]/ancestor::cm-handles'
39             def dataNodes = cpsQueryService.queryDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, cpsPath, OMIT_DESCENDANTS)
40         and: 'the ids of the result are extracted and converted to xpath'
41             def xpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
42         and: 'a single get is executed to get all the parent objects and their descendants'
43             def result = cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
44             stopWatch.stop()
45             def durationInMillis = stopWatch.getTotalTimeMillis()
46         then: 'the required operations are performed within 3 seconds'
47             recordAndAssertPerformance("CpsPath Registry attributes Query", 3_000, durationInMillis)
48         and: 'all but 1 (other node) are returned'
49             result.size() == 999
50         and: 'the tree contains all the expected descendants too'
51             assert countDataNodesInTree(result) == 5 * 999
52     }
53
54     def 'Multiple get limit exceeded: 32,764 (~ 2^15) xpaths.'() {
55         given: 'more than 32,764 xpaths)'
56             def xpaths = (0..32_764).collect(i -> "/size/of/this/path/does/not/matter/for/limit[@id='" + i + "']")
57         when: 'single get is executed to get all the parent objects and their descendants'
58             cpsDataService.getDataNodesForMultipleXpaths(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
59         then: 'an exception is thrown'
60             thrown(DataAccessResourceFailureException.class)
61     }
62
63 }