Fixed broken unittest in policy agent
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / ConcurrencyTestRunnable.java
index f8f7ca3..0ca5534 100644 (file)
@@ -34,6 +34,7 @@ import org.oransc.policyagent.utils.MockA1Client;
 import org.oransc.policyagent.utils.MockA1ClientFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.ResponseEntity;
 
 /**
  * Invoke operations over the NBI and start synchronizations in a separate
@@ -48,22 +49,38 @@ class ConcurrencyTestRunnable implements Runnable {
     private final MockA1ClientFactory a1ClientFactory;
     private final Rics rics;
     private final PolicyTypes types;
+    private boolean failed = false;
 
-    ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision, MockA1ClientFactory a1ClientFactory, Rics rics,
-        PolicyTypes types) {
+    ConcurrencyTestRunnable(AsyncRestClient webClient, RicSupervision supervision, MockA1ClientFactory a1ClientFactory,
+        Rics rics, PolicyTypes types) {
         this.count = nextCount.incrementAndGet();
         this.supervision = supervision;
         this.a1ClientFactory = a1ClientFactory;
         this.rics = rics;
         this.types = types;
-        this.webClient = new AsyncRestClient(baseUrl);
+        this.webClient = webClient;
+    }
+
+    private void printStatusInfo() {
+        try {
+            String url = "/actuator/metrics/jvm.threads.live";
+            ResponseEntity<String> result = webClient.getForEntity(url).block();
+            System.out.println(Thread.currentThread() + result.getBody());
+
+            url = "/rics";
+            result = webClient.getForEntity(url).block();
+            System.out.println(Thread.currentThread() + result.getBody());
+
+        } catch (Exception e) {
+            logger.error(Thread.currentThread() + "Concurrency test printStatusInfo exception " + e.toString());
+        }
     }
 
     @Override
     public void run() {
         try {
-            for (int i = 0; i < 100; ++i) {
-                if (i % 10 == 0) {
+            for (int i = 0; i < 500; ++i) {
+                if (i % 100 == 0) {
                     createInconsistency();
                     this.supervision.checkAllRics();
                 }
@@ -77,9 +94,15 @@ class ConcurrencyTestRunnable implements Runnable {
             }
         } catch (Exception e) {
             logger.error("Concurrency test exception " + e.toString());
+            printStatusInfo();
+            failed = true;
         }
     }
 
+    public boolean isFailed() {
+        return this.failed;
+    }
+
     private Policy createPolicyObject(String id) {
         Ric ric = this.rics.get("ric");
         PolicyType type = this.types.get("type1");
@@ -90,6 +113,7 @@ class ConcurrencyTestRunnable implements Runnable {
             .ric(ric) //
             .ownerServiceName("") //
             .lastModified("") //
+            .isTransient(false) //
             .build();
     }