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.spi.performance
23 import org.onap.cps.spi.CpsModulePersistenceService
24 import org.onap.cps.spi.entities.SchemaSetEntity
25 import org.onap.cps.spi.impl.CpsPersistenceSpecBase
26 import org.onap.cps.spi.model.ModuleReference
27 import org.onap.cps.spi.repository.ModuleReferenceRepository
28 import org.onap.cps.spi.repository.SchemaSetRepository
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.test.context.jdbc.Sql
31 import org.springframework.util.StopWatch
33 import java.util.concurrent.ThreadLocalRandom
35 class CpsModuleReferenceRepositoryPerfTest extends CpsPersistenceSpecBase {
37 static final String PERF_TEST_DATA = '/data/perf-test.sql'
39 def NEW_RESOURCE_CONTENT = 'module stores {\n' +
40 ' yang-version 1.1;\n' +
41 ' namespace "org:onap:ccsdk:sample";\n' +
43 ' prefix book-store;\n' +
45 ' revision "2020-09-15" {\n' +
47 ' "Sample Model";\n' +
52 CpsModulePersistenceService objectUnderTest
55 SchemaSetRepository schemaSetRepository
58 ModuleReferenceRepository moduleReferenceRepository
60 @Sql([CLEAR_DATA, PERF_TEST_DATA])
61 def 'Store new schema set with many modules'() {
62 when: 'a new schema set with 200 modules is stored'
63 def newYangResourcesNameToContentMap = [:]
66 def resourceName = "module${it}".toString()
67 def moduleName = "stores${it}"
68 def content = NEW_RESOURCE_CONTENT.replace('2020',String.valueOf(year)).replace('stores',moduleName)
69 newYangResourcesNameToContentMap.put(resourceName, content)
71 objectUnderTest.storeSchemaSet('PERF-DATASPACE', 'perfSchemaSet', newYangResourcesNameToContentMap)
72 then: 'the schema set is persisted correctly'
73 def dataspaceEntity = dataspaceRepository.getByName('PERF-DATASPACE')
74 SchemaSetEntity result = schemaSetRepository.getByDataspaceAndName(dataspaceEntity, 'perfSchemaSet')
75 result.yangResources.size() == 200
76 and: 'identification of new module resources is fast enough (1,000 executions less then 6,000 milliseconds)'
77 def stopWatch = new StopWatch()
79 def moduleReferencesToCheck = createModuleReferencesWithRandomMatchingExistingModuleReferences()
81 def newModuleReferences = moduleReferenceRepository.identifyNewModuleReferences(moduleReferencesToCheck)
83 assert newModuleReferences.size() > 0 && newModuleReferences.size() < 300
85 assert stopWatch.getTotalTimeMillis() < 6000
88 def createModuleReferencesWithRandomMatchingExistingModuleReferences() {
89 def moduleReferences = []
91 def randomNumber = ThreadLocalRandom.current().nextInt(1, 300)
92 def year = 2000 + randomNumber
93 def moduleName = "stores${randomNumber}"
94 moduleReferences.add(new ModuleReference(moduleName, "${year}-09-15"))
96 return moduleReferences