Fix performance build output being lost
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / ncmp / CmHandleQueryByAlternateIdPerfTest.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 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 org.onap.cps.integration.ResourceMeter
24 import org.onap.cps.integration.performance.base.NcmpPerfTestBase
25 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
26
27 import java.util.stream.Collectors
28
29 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
30 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
31 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
32
33 class CmHandleQueryByAlternateIdPerfTest extends NcmpPerfTestBase {
34
35     InventoryPersistence objectUnderTest
36     ResourceMeter resourceMeter = new ResourceMeter()
37
38     def setup() { objectUnderTest = inventoryPersistence }
39
40     def 'Query cm handle by longest match alternate id'() {
41         when: 'an alternate id as cps path query'
42             resourceMeter.start()
43             def cpsPath = "/a/b/c/d-5/e/f/g/h/i"
44             def dataNodes = objectUnderTest.getCmHandleDataNodeByLongestMatchAlternateId(cpsPath, '/')
45         and: 'the ids of the result are extracted and converted to xpath'
46             def cpsXpaths = dataNodes.stream().map(dataNode -> "/dmi-registry/cm-handles[@id='${dataNode.leaves.id}']".toString() ).collect(Collectors.toSet())
47         and: 'a single get is executed to get all the parent objects and their descendants'
48             cpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsXpaths, OMIT_DESCENDANTS)
49             resourceMeter.stop()
50             def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
51             print 'Total time in seconds to query ch handle by alternate id: ' + durationInSeconds
52         then: 'the required operations are performed within required time and memory limit'
53             recordAndAssertResourceUsage('Look up cm-handle by longest match alternate-id', 1, durationInSeconds, 300, resourceMeter.getTotalMemoryUsageInMB())
54     }
55 }