aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorHenry.Sun <henry.a.sun@est.tech>2020-03-02 15:47:09 +0800
committerHenry.Sun <henry.a.sun@est.tech>2020-03-04 12:02:42 +0800
commit153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (patch)
tree00f973c22492c89633723dcb5f09b448973e9ba4 /client
parent27dcbd57cc04c45ba85ff6f4008ef2c1d8f7c050 (diff)
replace test sleep() with awaitality package
Signed-off-by: Henry.Sun <henry.a.sun@est.tech> Change-Id: I305771ddef42bd3032ad52f4c5ecd55b01ed5a1a Issue-ID: POLICY-1914 Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
Diffstat (limited to 'client')
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java10
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java10
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java26
-rw-r--r--client/client-full/src/test/java/org/onap/policy/apex/client/full/rest/ServicesRestMainTest.java9
-rw-r--r--client/client-monitoring/src/test/java/org/onap/policy/apex/client/monitoring/rest/MonitoringRestMainTest.java7
5 files changed, 31 insertions, 31 deletions
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java
index 12fe8e528..245900d7d 100644
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java
+++ b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,14 +23,16 @@ package org.onap.policy.apex.client.deployment.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.awaitility.Awaitility.await;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
@@ -193,10 +195,10 @@ public class DeploymentRestMainTest {
assertThatCode(() -> {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(2, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexDeploymentRestMain.ServicesState.RUNNING));
monRestMain.shutdown();
}).doesNotThrowAnyException();
-
}
@After
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java
index 54e40ae77..ac1c60553 100644
--- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +21,14 @@
package org.onap.policy.apex.client.editor.rest;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.onap.policy.apex.client.editor.rest.ApexEditorMain.EditorState;
@@ -444,11 +447,8 @@ public class ApexEditorStartupTest {
}
};
new Thread(testThread).start();
- while (editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)) {
- Thread.sleep(100);
- }
-
+ await().atMost(15000, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)));
editorMain.shutdown();
final String outString = outBaStream.toString();
System.out.println(outString);
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
index 260a898df..c95a04a76 100644
--- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.client.editor.rest;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -27,6 +29,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -87,16 +90,11 @@ public class RestInterfaceTest {
};
new Thread(testThread).start();
// wait until editorMain is in state RUNNING
- final long startwait = System.currentTimeMillis();
- while (editorMain.getState().equals(EditorState.STOPPED) || editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)) {
- if (editorMain.getState().equals(EditorState.STOPPED)) {
- Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
- }
- if (System.currentTimeMillis() - startwait > MAX_WAIT) {
- Assert.fail("Rest endpoint (" + editorMain + ") for test failed to start fast enough");
- }
- Thread.sleep(100);
+ await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)));
+
+ if (editorMain.getState().equals(EditorState.STOPPED)) {
+ Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
}
// create the client
@@ -124,13 +122,7 @@ public class RestInterfaceTest {
public static void cleanUpStreams() throws IOException, InterruptedException {
editorMain.shutdown();
// wait until editorMain is in state STOPPED
- final long startwait = System.currentTimeMillis();
- while (!editorMain.getState().equals(EditorState.STOPPED)) {
- if (System.currentTimeMillis() - startwait > MAX_WAIT) {
- Assert.fail("Rest endpoint (" + editorMain + ") for test failed to shutdown fast enough");
- }
- Thread.sleep(50);
- }
+ await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> editorMain.getState().equals(EditorState.STOPPED));
System.setIn(SYSIN);
}
diff --git a/client/client-full/src/test/java/org/onap/policy/apex/client/full/rest/ServicesRestMainTest.java b/client/client-full/src/test/java/org/onap/policy/apex/client/full/rest/ServicesRestMainTest.java
index 1c5c440b4..3e21ee595 100644
--- a/client/client-full/src/test/java/org/onap/policy/apex/client/full/rest/ServicesRestMainTest.java
+++ b/client/client-full/src/test/java/org/onap/policy/apex/client/full/rest/ServicesRestMainTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,14 +23,16 @@ package org.onap.policy.apex.client.full.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.awaitility.Awaitility.await;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
@@ -189,7 +191,8 @@ public class ServicesRestMainTest {
assertThatCode(() -> {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(6, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexServicesRestMain.EditorState.RUNNING));
monRestMain.shutdown();
}).doesNotThrowAnyException();
}
diff --git a/client/client-monitoring/src/test/java/org/onap/policy/apex/client/monitoring/rest/MonitoringRestMainTest.java b/client/client-monitoring/src/test/java/org/onap/policy/apex/client/monitoring/rest/MonitoringRestMainTest.java
index 0c929f534..71ca21d2e 100644
--- a/client/client-monitoring/src/test/java/org/onap/policy/apex/client/monitoring/rest/MonitoringRestMainTest.java
+++ b/client/client-monitoring/src/test/java/org/onap/policy/apex/client/monitoring/rest/MonitoringRestMainTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.client.monitoring.rest;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -27,9 +29,9 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
@@ -231,7 +233,8 @@ public class MonitoringRestMainTest {
try {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(6, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexMonitoringRestMain.ServicesState.RUNNING));
monRestMain.shutdown();
} catch (Exception ex) {
fail("test should not throw an exception");