c36ec834a7ffe0c0de856c6189a0d3d0f62aac5c
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / cps / WritePerfTest.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-2024 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 class WritePerfTest extends CpsPerfTestBase {
27
28     static final def WRITE_TEST_ANCHOR = 'writeTestAnchor'
29
30     def 'Writing openroadm data has linear time.'() {
31         given: 'an empty anchor exists for openroadm'
32             cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, WRITE_TEST_ANCHOR)
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, WRITE_TEST_ANCHOR, jsonData, OffsetDateTime.now())
38             resourceMeter.stop()
39         then: 'the operation takes less than #expectedDuration and memory used is within limit'
40             recordAndAssertResourceUsage("Writing ${totalNodes} devices",
41                     expectedDuration, resourceMeter.getTotalTimeInSeconds(),
42                     memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
43         cleanup:
44             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, OffsetDateTime.now())
45             cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR)
46         where:
47             totalNodes || expectedDuration | memoryLimit
48             50         || 2                | 100
49             100        || 4                | 200
50             200        || 7                | 400
51             400        || 14               | 500
52     }
53
54     def 'Writing bookstore data has exponential time.'() {
55         given: 'an anchor containing a bookstore with a single category'
56             cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, WRITE_TEST_ANCHOR)
57             def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
58             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, parentNodeData, OffsetDateTime.now())
59         and: 'a list of books to add'
60             def booksData = '{"books":[' + (1..totalBooks).collect {'{ "title": "' + it + '" }' }.join(',') + ']}'
61         when: 'books are added'
62             resourceMeter.start()
63             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
64             resourceMeter.stop()
65         then: 'the operation takes less than #expectedDuration and memory used is within limit'
66             recordAndAssertResourceUsage("Writing ${totalBooks} books",
67                     expectedDuration, resourceMeter.getTotalTimeInSeconds(),
68                     memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
69         cleanup:
70             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, OffsetDateTime.now())
71             cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR)
72         where:
73             totalBooks || expectedDuration | memoryLimit
74             800        || 0.5              | 50
75             1600       || 1.5              | 100
76             3200       || 6                | 150
77             6400       || 18               | 200
78     }
79
80     def 'Writing openroadm list data using saveListElements.'() {
81         given: 'an anchor and empty container node for openroadm'
82             cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, WRITE_TEST_ANCHOR)
83             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR,
84                     '{ "openroadm-devices": { "openroadm-device": []}}', now)
85         and: 'a list of device nodes to add'
86             def innerNode = readResourceDataFile('openroadm/innerNode.json')
87             def jsonListData = '{ "openroadm-device": [' +
88                     (1..totalNodes).collect { innerNode.replace('NODE_ID_HERE', it.toString()) }.join(',') +
89                     ']}'
90         when: 'device nodes are added'
91             resourceMeter.start()
92             cpsDataService.saveListElements(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, '/openroadm-devices', jsonListData, OffsetDateTime.now())
93             resourceMeter.stop()
94         then: 'the operation takes less than #expectedDuration and memory used is within limit'
95             recordAndAssertResourceUsage("Saving list of ${totalNodes} devices",
96                     expectedDuration, resourceMeter.getTotalTimeInSeconds(),
97                     memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
98         cleanup:
99             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR, OffsetDateTime.now())
100             cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, WRITE_TEST_ANCHOR)
101         where:
102             totalNodes || expectedDuration | memoryLimit
103             50         || 4                | 200
104             100        || 7                | 200
105             200        || 14               | 250
106             400        || 28               | 250
107     }
108
109 }