CPS-NCMP: No yang resources stored during cmhandle discovery however cmhandles are...
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / WritePerfTest.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.cps
22
23 import java.time.OffsetDateTime
24 import org.onap.cps.integration.performance.base.CpsPerfTestBase
25
26 import java.util.concurrent.TimeUnit
27
28 class WritePerfTest extends CpsPerfTestBase {
29
30     def 'Writing openroadm data has linear time.'() {
31         given: 'an empty anchor exists for openroadm'
32             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'writeAnchor')
33         and: 'a list of device nodes to add'
34             def jsonData = generateOpenRoadData(totalNodes)
35         when: 'device nodes are added'
36             resourceMeter.start()
37             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', jsonData, OffsetDateTime.now())
38             resourceMeter.stop()
39             def durationInMillis = resourceMeter.getTotalTimeMillis()
40         then: 'the operation takes less than #expectedDuration and memory used is within limit'
41             recordAndAssertResourceUsage("Writing ${totalNodes} devices", TimeUnit.SECONDS.toMillis(expectedDurationInSeconds), durationInMillis, 400, resourceMeter.getTotalMemoryUsageInMB())
42         cleanup:
43             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
44             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
45         where:
46             totalNodes || expectedDurationInSeconds
47             50         ||   3
48             100        ||   5
49             200        ||  10
50             400        ||  20
51 //          800        ||  40
52 //          1600       ||  80
53 //          3200       || 160
54     }
55
56     def 'Writing bookstore data has exponential time.'() {
57         given: 'an anchor containing a bookstore with a single category'
58             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'writeAnchor')
59             def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
60             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', parentNodeData, OffsetDateTime.now())
61         and: 'a list of books to add'
62             def booksData = '{"books":[' + (1..totalBooks).collect {'{ "title": "' + it + '" }' }.join(',') + ']}'
63         when: 'books are added'
64             resourceMeter.start()
65             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
66             resourceMeter.stop()
67             def durationInMillis = resourceMeter.getTotalTimeMillis()
68         then: 'the operation takes less than #expectedDuration and memory used is within limit'
69             recordAndAssertResourceUsage("Writing ${totalBooks} books", expectedDuration, durationInMillis, 400, resourceMeter.getTotalMemoryUsageInMB())
70         cleanup:
71             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
72             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
73         where:
74             totalBooks || expectedDuration
75             400        || 200
76             800        || 500
77             1600       || TimeUnit.SECONDS.toMillis(1)
78             3200       || TimeUnit.SECONDS.toMillis(3)
79             6400       || TimeUnit.SECONDS.toMillis(10)
80 //          12800      || TimeUnit.SECONDS.toMillis(30)
81 //          25600      || TimeUnit.SECONDS.toMillis(120)
82 //          51200      || TimeUnit.SECONDS.toMillis(600)
83     }
84
85 }