2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022-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.cps
23 import org.onap.cps.api.CpsModuleService
24 import org.onap.cps.integration.performance.base.CpsPerfTestBase
25 import org.onap.cps.spi.model.ModuleReference
26 import org.springframework.util.StopWatch
28 import java.util.concurrent.ThreadLocalRandom
30 class CpsModuleServicePerfTest extends CpsPerfTestBase {
32 def NEW_RESOURCE_CONTENT = 'module stores {\n' +
33 ' yang-version 1.1;\n' +
34 ' namespace "org:onap:ccsdk:sample";\n' +
36 ' prefix book-store;\n' +
38 ' revision "2020-09-15" {\n' +
40 ' "Sample Model";\n' +
44 CpsModuleService objectUnderTest
46 def setup() { objectUnderTest = cpsModuleService }
48 def 'Store new schema set with many modules'() {
49 when: 'a new schema set with 200 modules is stored'
50 def newYangResourcesNameToContentMap = [:]
53 def resourceName = "module${it}".toString()
54 def moduleName = "stores${it}"
55 def content = NEW_RESOURCE_CONTENT.replace('2020',String.valueOf(year)).replace('stores',moduleName)
56 newYangResourcesNameToContentMap.put(resourceName, content)
58 objectUnderTest.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, 'perfSchemaSet', newYangResourcesNameToContentMap)
59 then: 'the schema set is persisted correctly'
60 def result = cpsModuleService.getSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, 'perfSchemaSet')
61 result.moduleReferences.size() == 200
62 and: 'identification of new module resources is fast enough (1,000 executions less then 6,000 milliseconds)'
63 def stopWatch = new StopWatch()
65 def moduleReferencesToCheck = createModuleReferencesWithRandomMatchingExistingModuleReferences()
67 def newModuleReferences = objectUnderTest.identifyNewModuleReferences(moduleReferencesToCheck)
69 assert newModuleReferences.size() > 0 && newModuleReferences.size() < 300
71 assert stopWatch.getTotalTimeMillis() < 6000
74 def createModuleReferencesWithRandomMatchingExistingModuleReferences() {
75 def moduleReferences = []
77 def randomNumber = ThreadLocalRandom.current().nextInt(1, 300)
78 def year = 2000 + randomNumber
79 def moduleName = "stores${randomNumber}"
80 moduleReferences.add(new ModuleReference(moduleName, "${year}-09-15"))
82 return moduleReferences