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.rest.utils.MultipartFileUtil
24 import org.onap.cps.spi.FetchDescendantsOption
25 import org.springframework.web.multipart.MultipartFile
27 class CpsPerfTestBase extends PerfTestBase {
29 static def CPS_PERFORMANCE_TEST_DATASPACE = 'cpsPerformanceDataspace'
32 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 ##')
36 return dataspaceExists(CPS_PERFORMANCE_TEST_DATASPACE)
39 def setupPerformanceInfraStructure() {
40 cpsAdminService.createDataspace(CPS_PERFORMANCE_TEST_DATASPACE)
41 def modelAsString = readResourceDataFile('bookstore/bookstore.yang')
42 cpsModuleService.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, [bookstore: modelAsString])
45 def createInitialData() {
47 createLargeBookstoresData()
52 def createWarmupData() {
53 def data = "{\"bookstore\":{}}"
55 addAnchorsWithData(1, CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'warmup', data)
57 def durationInMillis = stopWatch.getTotalTimeMillis()
58 recordAndAssertPerformance('Creating warmup anchor with tiny data tree', 500, durationInMillis)
61 def createLargeBookstoresData() {
62 def data = readResourceDataFile('bookstore/largeModelData.json')
64 addAnchorsWithData(5, CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'bookstore', data)
66 def durationInMillis = stopWatch.getTotalTimeMillis()
67 recordAndAssertPerformance('Creating bookstore anchors with large data tree', 3_000, durationInMillis)
70 def addOpenRoadModel() {
71 def file = new File('src/test/resources/data/openroadm/correctedModel.zip')
72 def multipartFile = Mock(MultipartFile)
73 multipartFile.getOriginalFilename() >> file.getName()
74 multipartFile.getInputStream() >> new FileInputStream(file)
75 cpsModuleService.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, MultipartFileUtil.extractYangResourcesMap(multipartFile))
78 def addOpenRoadData() {
79 def data = generateOpenRoadData(50)
81 addAnchorsWithData(5, CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'openroadm', data)
83 def durationInMillis = stopWatch.getTotalTimeMillis()
84 recordAndAssertPerformance('Creating openroadm anchors with large data tree', 25_000, durationInMillis)
87 def generateOpenRoadData(numberOfNodes) {
88 def innerNode = readResourceDataFile('openroadm/innerNode.json')
89 return '{ "openroadm-devices": { "openroadm-device": [' +
90 (1..numberOfNodes).collect { innerNode.replace('NODE_ID_HERE', it.toString()) }.join(',') +
94 def 'Warm the database'() {
95 when: 'get data nodes for warmup anchor'
97 def result = cpsDataService.getDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'warmup1', '/', FetchDescendantsOption.OMIT_DESCENDANTS)
98 assert countDataNodesInTree(result) == 1
100 def durationInMillis = stopWatch.getTotalTimeMillis()
101 then: 'all data is read within 25 seconds (warm up not critical)'
102 recordAndAssertPerformance("Warming database", 25_000, durationInMillis)