Add integration test for extending API: Get Module Definitions
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / performance / base / PerfTestBase.groovy
index 4afdabe..b455e69 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation
+ *  Copyright (C) 2023-2024 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the 'License');
  *  you may not use this file except in compliance with the License.
@@ -28,16 +28,14 @@ abstract class PerfTestBase extends CpsIntegrationSpecBase {
     static def LARGE_SCHEMA_SET = 'largeSchemaSet'
     static def PERFORMANCE_RECORD = []
 
-    def stopWatch = new StopWatch()
-
     def cleanupSpec() {
-        println('#############################################################################')
+        println('##################################################################################################')
         printTitle()
-        println('#############################################################################')
+        println('##################################################################################################')
         PERFORMANCE_RECORD.sort().each {
             println(it)
         }
-        println('#############################################################################')
+        println('##################################################################################################')
         PERFORMANCE_RECORD.clear()
     }
 
@@ -56,15 +54,16 @@ abstract class PerfTestBase extends CpsIntegrationSpecBase {
 
     abstract def createInitialData()
 
-    def recordAndAssertPerformance(String shortTitle, thresholdInMs, recordedTimeInMs) {
-        def pass = recordedTimeInMs <= thresholdInMs
+    def recordAndAssertResourceUsage(String shortTitle, double thresholdInSec, double recordedTimeInSec, memoryLimit, memoryUsageInMB) {
+        def pass = recordedTimeInSec <= thresholdInSec && memoryUsageInMB <= memoryLimit
         if (shortTitle.length() > 40) {
             shortTitle = shortTitle.substring(0, 40)
         }
-        def record = String.format('%2d.%-40s limit%,7d took %,7d ms ', PERFORMANCE_RECORD.size() + 1, shortTitle, thresholdInMs, recordedTimeInMs)
+        def record = String.format('%2d.%-40s limit %8.2f took %8.2f sec %,8.2f MB used ', PERFORMANCE_RECORD.size() + 1, shortTitle, thresholdInSec, recordedTimeInSec, memoryUsageInMB)
         record += pass ? 'PASS' : 'FAIL'
         PERFORMANCE_RECORD.add(record)
-        assert recordedTimeInMs <= thresholdInMs
+        assert recordedTimeInSec <= thresholdInSec
+        assert memoryUsageInMB <= memoryLimit
         return true
     }
 }