package org.onap.cps.spi.performance
import org.onap.cps.spi.impl.CpsPersistencePerfSpecBase
-import org.springframework.util.StopWatch
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.DataspaceRepository
def 'Get data node with many descendants by xpath #scenario'() {
when: 'get parent is executed with all descendants'
stopWatch.start()
- def result = objectUnderTest.getDataNode(PERF_DATASPACE, PERF_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS)
+ def result = objectUnderTest.getDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS)
stopWatch.stop()
def readDurationInMillis = stopWatch.getTotalTimeMillis()
- then: 'read duration is under 500 milliseconds'
- recordAndAssertPerformance("Get ${scenario}", 500, readDurationInMillis)
+ then: 'read duration is under #allowedDuration milliseconds'
+ recordAndAssertPerformance("Get ${scenario}", allowedDuration, readDurationInMillis)
and: 'data node is returned with all the descendants populated'
- assert countDataNodes(result) == TOTAL_NUMBER_OF_NODES
+ assert countDataNodes(result[0]) == TOTAL_NUMBER_OF_NODES
where: 'the following xPaths are used'
- scenario || xpath
- 'parent' || PERF_TEST_PARENT
- 'root' || ''
+ scenario | xpath || allowedDuration
+ 'parent' | PERF_TEST_PARENT || 5000
+ 'root' | '' || 500
}
def 'Query parent data node with many descendants by cps-path'() {
when: 'we query for all grandchildren (except 1 for fun) with the new native method'
xpathsToAllGrandChildren.remove(0)
stopWatch.start()
- def result = objectUnderTest.getDataNodes(PERF_DATASPACE, PERF_ANCHOR, xpathsToAllGrandChildren, INCLUDE_ALL_DESCENDANTS)
+ def result = objectUnderTest.getDataNodesForMultipleXpaths(PERF_DATASPACE, PERF_ANCHOR, xpathsToAllGrandChildren, INCLUDE_ALL_DESCENDANTS)
stopWatch.stop()
def readDurationInMillis = stopWatch.getTotalTimeMillis()
then: 'the returned number of entities equal to the number of children * number of grandchildren'
assert result.size() == xpathsToAllGrandChildren.size()
- and: 'it took less then 4000ms'
- recordAndAssertPerformance('Find multiple xpaths', 4000, readDurationInMillis)
+ and: 'it took less then 5000ms'
+ recordAndAssertPerformance('Find multiple xpaths', 5000, readDurationInMillis)
}
def 'Query many descendants by cps-path with #scenario'() {
stopWatch.stop()
def readDurationInMillis = stopWatch.getTotalTimeMillis()
then: 'read duration is under #allowedDuration milliseconds'
- assert readDurationInMillis < allowedDuration
recordAndAssertPerformance("Query many descendants by cpspath (${scenario})", allowedDuration, readDurationInMillis)
and: 'data node is returned with all the descendants populated'
assert result.size() == NUMBER_OF_CHILDREN
'omit descendants ' | OMIT_DESCENDANTS || 150
'include descendants (although there are none)' | INCLUDE_ALL_DESCENDANTS || 150
}
+
+ def 'Update data nodes with descendants'() {
+ given: 'a list of xpaths to data nodes with descendants (xpath for each child)'
+ def xpaths = (1..20).collect {
+ "${PERF_TEST_PARENT}/perf-test-child-${it}".toString()
+ }
+ and: 'the correct number of data nodes are fetched'
+ def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(PERF_DATASPACE, PERF_ANCHOR, xpaths, INCLUDE_ALL_DESCENDANTS)
+ assert dataNodes.size() == 20
+ assert countDataNodes(dataNodes) == 20 + 20 * 50
+ when: 'the fragment entities are updated by the data nodes'
+ stopWatch.start()
+ objectUnderTest.updateDataNodesAndDescendants(PERF_DATASPACE, PERF_ANCHOR, dataNodes)
+ stopWatch.stop()
+ def updateDurationInMillis = stopWatch.getTotalTimeMillis()
+ then: 'update duration is under 900 milliseconds'
+ recordAndAssertPerformance('Update data nodes with descendants', 900, updateDurationInMillis)
+ }
+
+ def 'Update data nodes without descendants'() {
+ given: 'a list of xpaths to data nodes without descendants (xpath for each grandchild)'
+ def xpaths = []
+ for (int childIndex = 21; childIndex <= 40; childIndex++) {
+ xpaths.addAll((1..50).collect {
+ "${PERF_TEST_PARENT}/perf-test-child-${childIndex}/perf-test-grand-child-${it}".toString()
+ })
+ }
+ and: 'the correct number of data nodes are fetched'
+ def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(PERF_DATASPACE, PERF_ANCHOR, xpaths, OMIT_DESCENDANTS)
+ assert dataNodes.size() == 20 * 50
+ assert countDataNodes(dataNodes) == 20 * 50
+ when: 'the fragment entities are updated by the data nodes'
+ stopWatch.start()
+ objectUnderTest.updateDataNodesAndDescendants(PERF_DATASPACE, PERF_ANCHOR, dataNodes)
+ stopWatch.stop()
+ def updateDurationInMillis = stopWatch.getTotalTimeMillis()
+ then: 'update duration is under 900 milliseconds'
+ recordAndAssertPerformance('Update data nodes without descendants', 900, updateDurationInMillis)
+ }
}