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
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 org.onap.cps.integration.ResourceMeter
24 import org.onap.cps.rest.utils.MultipartFileUtil
25 import org.onap.cps.spi.FetchDescendantsOption
26 import org.springframework.web.multipart.MultipartFile
28 import java.util.concurrent.TimeUnit
30 class CpsPerfTestBase extends PerfTestBase {
32 static final def CPS_PERFORMANCE_TEST_DATASPACE = 'cpsPerformanceDataspace'
33 static final def OPENROADM_ANCHORS = 3
34 static final def OPENROADM_DEVICES_PER_ANCHOR = 1000
35 static final def OPENROADM_DATANODES_PER_DEVICE = 86
37 ResourceMeter resourceMeter = new ResourceMeter()
40 println('## C P S P E R F O R M A N C E T E S T R E S U L T S ##')
44 return dataspaceExists(CPS_PERFORMANCE_TEST_DATASPACE)
47 def setupPerformanceInfraStructure() {
48 cpsAdminService.createDataspace(CPS_PERFORMANCE_TEST_DATASPACE)
49 def modelAsString = readResourceDataFile('bookstore/bookstore.yang')
50 cpsModuleService.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, [bookstore: modelAsString])
53 def createInitialData() {
58 def addOpenRoadModel() {
59 def file = new File('src/test/resources/data/openroadm/correctedModel.zip')
60 def multipartFile = Mock(MultipartFile)
61 multipartFile.getOriginalFilename() >> file.getName()
62 multipartFile.getInputStream() >> new FileInputStream(file)
63 cpsModuleService.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, MultipartFileUtil.extractYangResourcesMap(multipartFile))
66 def addOpenRoadData() {
67 def data = generateOpenRoadData(OPENROADM_DEVICES_PER_ANCHOR)
69 addAnchorsWithData(OPENROADM_ANCHORS, CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'openroadm', data)
71 def durationInMillis = resourceMeter.getTotalTimeMillis()
72 recordAndAssertResourceUsage('Creating openroadm anchors with large data tree', TimeUnit.SECONDS.toMillis(200), durationInMillis, 200, resourceMeter.getTotalMemoryUsageInMB())
75 def generateOpenRoadData(numberOfNodes) {
76 def innerNode = readResourceDataFile('openroadm/innerNode.json')
77 return '{ "openroadm-devices": { "openroadm-device": [' +
78 (1..numberOfNodes).collect { innerNode.replace('NODE_ID_HERE', it.toString()) }.join(',') +
82 def 'Warm the database'() {
83 when: 'dummy get data nodes runs so that populating the DB does not get included in other test timings'
85 def result = cpsDataService.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'openroadm1', '/', FetchDescendantsOption.OMIT_DESCENDANTS)
86 assert countDataNodesInTree(result) == 1
88 def durationInMillis = resourceMeter.getTotalTimeMillis()
89 then: 'memory used is within #peakMemoryUsage'
90 assert resourceMeter.getTotalMemoryUsageInMB() <= 30
91 and: 'all data is read within expected time'
92 recordAndAssertResourceUsage("Warming database", TimeUnit.SECONDS.toMillis(200), durationInMillis, 200, resourceMeter.getTotalMemoryUsageInMB())