Use Seconds as time unit for all performance tests
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / base / NcmpPerfTestBase.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.base
22
23 import java.time.OffsetDateTime
24 import org.onap.cps.integration.ResourceMeter
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 CM_DATA_SUBSCRIPTIONS_ANCHOR = 'cm-data-subscriptions'
32     def static CM_DATA_SUBSCRIPTIONS_SCHEMA_SET = 'cmDataSubscriptionsSchemaSet'
33
34     def datastore1cmHandlePlaceHolder = '{"datastores":{"datastore":[{"name":"ds-1","cm-handles":{"cm-handle":[]}}]}}'
35     def xPathForDataStore1CmHandles = '/datastores/datastore[@name="ds-1"]/cm-handles'
36     def numberOfCmDataSubscribers = 200
37     def numberOfFiltersPerCmHandle = 10
38     def numberOfCmHandlesPerCmDataSubscription = 200
39
40     ResourceMeter resourceMeter = new ResourceMeter()
41
42 // SHORT versions for easier debugging
43 //    def subscriberIdPrefix = 'sub'
44 //    def xpathPrefix = 'f'
45 //    def cmHandlePrefix = 'ch'
46
47
48 // LONG versions for performance testing
49     def subscriberIdPrefix = 'some really long subscriber id to see if this makes any difference to the performance'
50     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'
51     def cmHandlePrefix = 'some really long cm handle id to see if this makes any difference to the performance'
52
53     def printTitle() {
54         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     }
56
57     def isInitialised() {
58         return dataspaceExists(NCMP_PERFORMANCE_TEST_DATASPACE)
59     }
60
61     def setupPerformanceInfraStructure() {
62         cpsAdminService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
63         createRegistrySchemaSet()
64         createCmDataSubscriptionsSchemaSet()
65         addCmSubscriptionData()
66     }
67
68     def createInitialData() {
69         cpsAdminService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
70         def data = readResourceDataFile('ncmp-registry/1000-cmhandles.json')
71         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, data, OffsetDateTime.now())
72     }
73
74     def createRegistrySchemaSet() {
75         def modelAsString = readResourceDataFile('ncmp-registry/dmi-registry@2022-05-10.yang')
76         cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, [registry: modelAsString])
77     }
78
79     def createCmDataSubscriptionsSchemaSet() {
80         def modelAsString = readResourceDataFile('cm-data-subscriptions/cm-data-subscriptions@2023-09-21.yang')
81         cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, [registry: modelAsString])
82     }
83
84     def addCmSubscriptionData() {
85         cpsAdminService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
86         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, datastore1cmHandlePlaceHolder, now)
87         def subscribers = createLeafList('subscribers',numberOfCmDataSubscribers, subscriberIdPrefix)
88         def filters = '"filters":' + createJsonArray('filter',numberOfFiltersPerCmHandle,'xpath',xpathPrefix,subscribers)
89         def cmHandles = createJsonArray('cm-handle',numberOfCmHandlesPerCmDataSubscription,'id',cmHandlePrefix, filters)
90         cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, xPathForDataStore1CmHandles, cmHandles, now)
91     }
92 }