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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.integration.performance.base
23 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
24 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
26 import org.onap.cps.integration.ResourceMeter
27 import org.onap.cps.spi.FetchDescendantsOption
29 class NcmpPerfTestBase extends PerfTestBase {
31 def static NCMP_PERFORMANCE_TEST_DATASPACE = 'ncmpPerformance'
32 def static REGISTRY_ANCHOR = 'ncmp-registry'
33 def static REGISTRY_SCHEMA_SET = 'registrySchemaSet'
34 def static TOTAL_CM_HANDLES = 20_000
35 def static CM_DATA_SUBSCRIPTIONS_ANCHOR = 'cm-data-subscriptions'
36 def static CM_DATA_SUBSCRIPTIONS_SCHEMA_SET = 'cmDataSubscriptionsSchemaSet'
38 def datastore1cmHandlePlaceHolder = '{"datastores":{"datastore":[{"name":"ds-1","cm-handles":{"cm-handle":[]}}]}}'
39 def xPathForDataStore1CmHandles = '/datastores/datastore[@name="ds-1"]/cm-handles'
40 def numberOfCmDataSubscribers = 200
41 def numberOfFiltersPerCmHandle = 10
42 def numberOfCmHandlesPerCmDataSubscription = 200
44 ResourceMeter resourceMeter = new ResourceMeter()
46 def subscriberIdPrefix = 'some really long subscriber id to see if this makes any difference to the performance'
47 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'
48 def cmHandlePrefix = 'some really long cm handle id to see if this makes any difference to the performance'
51 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 ##')
55 return dataspaceExists(NCMP_PERFORMANCE_TEST_DATASPACE)
58 def setupPerformanceInfraStructure() {
59 cpsDataspaceService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
60 createRegistrySchemaSet()
61 createCmDataSubscriptionsSchemaSet()
64 def createInitialData() {
66 addRegistryDataWithAlternateIdAsPath()
67 addCmSubscriptionData()
70 def createRegistrySchemaSet() {
71 def modelAsString = readResourceDataFile('ncmp-registry/dmi-registry@2024-02-23.yang')
72 cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, [registry: modelAsString])
75 def addRegistryData() {
76 cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
77 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '{"dmi-registry": []}', now)
78 def innerNodeJsonTemplate = readResourceDataFile('ncmp-registry/innerNode.json')
80 for (def i = 0; i < TOTAL_CM_HANDLES; i += batchSize) {
81 def data = '{ "cm-handles": [' + (1..batchSize).collect { innerNodeJsonTemplate.replace('CMHANDLE_ID_HERE', (it + i).toString()) }.join(',') + ']}'
82 cpsDataService.saveListElements(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/dmi-registry', data, now)
86 def addRegistryDataWithAlternateIdAsPath() {
87 def innerNodeJsonTemplate = readResourceDataFile('ncmp-registry/innerCmHandleNode.json')
89 for (def i = 0; i < TOTAL_CM_HANDLES; i += batchSize) {
90 def data = '{ "cm-handles": [' + (1..batchSize).collect {
91 innerNodeJsonTemplate.replace('CM_HANDLE_ID_HERE', (it + i).toString())
92 .replace('ALTERNATE_ID_AS_PATH', (it + i).toString())
94 cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry', data, now)
98 def createCmDataSubscriptionsSchemaSet() {
99 def modelAsString = readResourceDataFile('cm-data-subscriptions/cm-data-subscriptions@2023-09-21.yang')
100 cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, [registry: modelAsString])
103 def addCmSubscriptionData() {
104 cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
105 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, datastore1cmHandlePlaceHolder, now)
106 def subscribers = createLeafList('subscribers',numberOfCmDataSubscribers, subscriberIdPrefix)
107 def filters = '"filters":' + createJsonArray('filter',numberOfFiltersPerCmHandle,'xpath',xpathPrefix,subscribers)
108 def cmHandles = createJsonArray('cm-handle',numberOfCmHandlesPerCmDataSubscription,'id',cmHandlePrefix, filters)
109 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, xPathForDataStore1CmHandles, cmHandles, now)
112 def 'NCMP pre-load test data'() {
113 when: 'dummy get data nodes runs so that populating the DB does not get included in other test timings'
114 resourceMeter.start()
115 def result = cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/', FetchDescendantsOption.OMIT_DESCENDANTS)
117 then: 'expected data exists'
118 assert result.xpath == ['/dmi-registry']
119 and: 'operation completes within expected time'
120 recordAndAssertResourceUsage('NCMP pre-load test data',
121 15, resourceMeter.totalTimeInSeconds,
122 600, resourceMeter.totalMemoryUsageInMB)