summaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
index b0e859dbf..3298d7bde 100644
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
+++ b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.m2.test;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertNotNull;
import static org.onap.policy.guard.Util.ONAP_KEY_PASS;
import static org.onap.policy.guard.Util.ONAP_KEY_URL;
@@ -32,9 +33,13 @@ import static org.onap.policy.m2.test.Util.json;
import com.google.gson.JsonObject;
import java.io.File;
+import java.time.Duration;
import java.util.Properties;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.awaitility.Durations;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -149,8 +154,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive active notification, and restart operation
- assertSubset(json("notification", "ACTIVE"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "ACTIVE"));
appcOperation(req, "Restart", 400, "Restart Successful");
@@ -159,8 +164,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive final success notification
- assertSubset(json("notification", "FINAL: SUCCESS"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "FINAL: SUCCESS"));
// sleep to allow DB update
Thread.sleep(1000);
@@ -177,8 +182,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// active notification, and restart 1 operation
- assertSubset(json("notification", "ACTIVE"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "ACTIVE"));
appcOperation(req, "Restart", 450, "Restart 1 Failed");
appcOperation(req, "Restart", 450, "Restart 2 Failed");
@@ -191,13 +196,25 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive final success notification
- assertSubset(json("notification", "FINAL: SUCCESS"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "FINAL: SUCCESS"));
// sleep to allow DB update
Thread.sleep(1000);
}
+ private void awaitAndAssert(int maxWaitSecond, Duration pollIntervalMilli, Input notification,
+ JsonObject jsonObj) {
+ AtomicReference<JsonObject> obj = new AtomicReference<>();
+ await().atMost(maxWaitSecond, TimeUnit.SECONDS)
+ .with().pollInterval(pollIntervalMilli)
+ .until(() -> {
+ obj.set(notification.poll());
+ return obj.get() != null;
+ });
+ assertSubset(jsonObj, obj.get());
+ }
+
private void appcOperation(Request req, String name, int responseCode, String responseMessage)
throws Exception {
String lcName = name.toLowerCase();