Add write performance tests
[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 class WritePerfTest extends CpsPerfTestBase {
27
28     def 'Writing openroadm data has linear time.'() {
29         given: 'an empty anchor exists for openroadm'
30             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'writeAnchor')
31         and: 'a list of device nodes to add'
32             def jsonData = generateOpenRoadData(totalNodes)
33         when: 'device nodes are added'
34             stopWatch.start()
35             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', jsonData, OffsetDateTime.now())
36             stopWatch.stop()
37             def durationInMillis = stopWatch.getTotalTimeMillis()
38         then: 'the operation takes less than #expectedDuration'
39             recordAndAssertPerformance("Writing ${totalNodes} devices", expectedDuration, durationInMillis)
40         cleanup:
41             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
42             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
43         where:
44             totalNodes || expectedDuration
45             50         ||   2_500
46             100        ||   4_000
47             200        ||   8_000
48             400        ||  16_000
49 //          800        ||  32_000
50 //          1600       ||  64_000
51 //          3200       || 128_000
52     }
53
54     def 'Writing bookstore data has exponential time.'() {
55         given: 'an anchor containing a bookstore with a single category'
56             cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'writeAnchor')
57             def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
58             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', 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             stopWatch.start()
63             cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', '/bookstore/categories[@code=1]', booksData, OffsetDateTime.now())
64             stopWatch.stop()
65             def durationInMillis = stopWatch.getTotalTimeMillis()
66         then: 'the operation takes less than #expectedDuration'
67             recordAndAssertPerformance("Writing ${totalBooks} books", expectedDuration, durationInMillis)
68         cleanup:
69             cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
70             cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
71         where:
72             totalBooks || expectedDuration
73             400        ||     200
74             800        ||     500
75             1600       ||   1_000
76             3200       ||   2_500
77             6400       ||  10_000
78 //          12800      ||  30_000
79 //          25600      || 120_000
80 //          51200      || 600_000
81     }
82
83 }