Merge "Performance tests of alternate-id/module-set-tag lookup"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / base / NcmpPerfTestBase.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-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.base
22
23 import org.onap.cps.integration.ResourceMeter
24 import org.onap.cps.spi.FetchDescendantsOption
25
26 class NcmpPerfTestBase extends PerfTestBase {
27
28     def static NCMP_PERFORMANCE_TEST_DATASPACE = 'ncmpPerformance'
29     def static REGISTRY_ANCHOR = 'ncmp-registry'
30     def static REGISTRY_SCHEMA_SET = 'registrySchemaSet'
31     def static TOTAL_CM_HANDLES = 20_000
32     def static CM_DATA_SUBSCRIPTIONS_ANCHOR = 'cm-data-subscriptions'
33     def static CM_DATA_SUBSCRIPTIONS_SCHEMA_SET = 'cmDataSubscriptionsSchemaSet'
34
35     def datastore1cmHandlePlaceHolder = '{"datastores":{"datastore":[{"name":"ds-1","cm-handles":{"cm-handle":[]}}]}}'
36     def xPathForDataStore1CmHandles = '/datastores/datastore[@name="ds-1"]/cm-handles'
37     def numberOfCmDataSubscribers = 200
38     def numberOfFiltersPerCmHandle = 10
39     def numberOfCmHandlesPerCmDataSubscription = 200
40
41     ResourceMeter resourceMeter = new ResourceMeter()
42
43     def subscriberIdPrefix = 'some really long subscriber id to see if this makes any difference to the performance'
44     def xpathPrefix = 'some really long xpath/with/loads/of/children/grandchildren/and/whatever/else/I/can/think/of to see if this makes any difference to the performance'
45     def cmHandlePrefix = 'some really long cm handle id to see if this makes any difference to the performance'
46
47     def printTitle() {
48         println('##                  N C M P   P E R F O R M A N C E   T E S T   R E S U L T S                   ##')
49     }
50
51     def isInitialised() {
52         return dataspaceExists(NCMP_PERFORMANCE_TEST_DATASPACE)
53     }
54
55     def setupPerformanceInfraStructure() {
56         cpsDataspaceService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
57         createRegistrySchemaSet()
58         createCmDataSubscriptionsSchemaSet()
59     }
60
61     def createInitialData() {
62         addRegistryData()
63         addCmSubscriptionData()
64     }
65
66     def createRegistrySchemaSet() {
67         def modelAsString = readResourceDataFile('ncmp-registry/dmi-registry@2024-02-23.yang')
68         cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, [registry: modelAsString])
69     }
70
71     def addRegistryData() {
72         cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
73         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '{"dmi-registry": []}', now)
74         def innerNodeJsonTemplate = readResourceDataFile('ncmp-registry/innerNode.json')
75         def batchSize = 100
76         for (def i = 0; i < TOTAL_CM_HANDLES; i += batchSize) {
77             def data = '{ "cm-handles": [' + (1..batchSize).collect { innerNodeJsonTemplate.replace('CMHANDLE_ID_HERE', (it + i).toString()) }.join(',') + ']}'
78             cpsDataService.saveListElements(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/dmi-registry', data, now)
79         }
80     }
81
82     def createCmDataSubscriptionsSchemaSet() {
83         def modelAsString = readResourceDataFile('cm-data-subscriptions/cm-data-subscriptions@2023-09-21.yang')
84         cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, [registry: modelAsString])
85     }
86
87     def addCmSubscriptionData() {
88         cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
89         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, datastore1cmHandlePlaceHolder, now)
90         def subscribers = createLeafList('subscribers',numberOfCmDataSubscribers, subscriberIdPrefix)
91         def filters = '"filters":' + createJsonArray('filter',numberOfFiltersPerCmHandle,'xpath',xpathPrefix,subscribers)
92         def cmHandles = createJsonArray('cm-handle',numberOfCmHandlesPerCmDataSubscription,'id',cmHandlePrefix, filters)
93         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, xPathForDataStore1CmHandles, cmHandles, now)
94     }
95
96     def 'NCMP pre-load test data'() {
97         when: 'dummy get data nodes runs so that populating the DB does not get included in other test timings'
98             resourceMeter.start()
99             def result = cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/', FetchDescendantsOption.OMIT_DESCENDANTS)
100             resourceMeter.stop()
101         then: 'expected data exists'
102             assert result.xpath == ['/dmi-registry']
103         and: 'operation completes within expected time'
104             recordAndAssertResourceUsage('NCMP pre-load test data',
105                     15, resourceMeter.totalTimeInSeconds,
106                     600, resourceMeter.totalMemoryUsageInMB)
107     }
108
109 }