aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-editor/src
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/client-editor/src
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/client-editor/src')
-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
2 files changed, 14 insertions, 22 deletions
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);
}