summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2020-03-04 13:32:27 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-04 13:32:27 +0000
commita9b60303e7e3699cc4df904144592ea6a9b6c586 (patch)
tree1b710f2f899598d3032a6485db54c2e4a8cc92a2
parent9f17d75f75dd087a58822dcc5aa2821267aa2193 (diff)
parent153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (diff)
Merge "replace test sleep() with awaitality package"
-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
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java14
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java9
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java10
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java3
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java10
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java6
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java10
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java11
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java17
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java11
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java12
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java11
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java11
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java29
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java8
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java4
-rw-r--r--pom.xml5
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java48
23 files changed, 144 insertions, 147 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");
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java
index d5b34a054..f51b2337c 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.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.core.deployment;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -29,6 +31,7 @@ import static org.mockito.Matchers.anyObject;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,7 +44,6 @@ import org.onap.policy.apex.core.infrastructure.messaging.MessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingServiceFactory;
import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.core.protocols.Message;
import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus;
import org.onap.policy.apex.core.protocols.engdep.messages.Response;
@@ -81,7 +83,7 @@ public class DeploymentClientTest {
Thread clientThread = new Thread(deploymentClient);
clientThread.start();
- ThreadUtilities.sleep(100);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> deploymentClient.isStarted());
assertTrue(deploymentClient.isStarted());
assertTrue(clientThread.isAlive());
@@ -90,7 +92,6 @@ public class DeploymentClientTest {
GetEngineStatus getEngineStatus = new GetEngineStatus(engineKey);
deploymentClient.sendMessage(new GetEngineStatus(engineKey));
- ThreadUtilities.sleep(20);
Response response = new Response(engineKey, true, getEngineStatus);
List<Message> messageList = new ArrayList<>();
messageList.add(response);
@@ -105,8 +106,7 @@ public class DeploymentClientTest {
assertEquals("String mesages are not supported on the EngDep protocol", use.getMessage());
}
- ThreadUtilities.sleep(300);
- assertEquals(1, deploymentClient.getMessagesSent());
+ await().atMost(300, TimeUnit.MILLISECONDS).until(() -> deploymentClient.getMessagesReceived() == 2);
assertEquals(2, deploymentClient.getMessagesReceived());
deploymentClient.stopClient();
@@ -128,14 +128,12 @@ public class DeploymentClientTest {
Thread clientThread = new Thread(deploymentClient);
clientThread.start();
- ThreadUtilities.sleep(50);
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> !deploymentClient.isStarted());
assertFalse(deploymentClient.isStarted());
assertFalse(clientThread.isAlive());
assertEquals(0, deploymentClient.getReceiveQueue().size());
- ThreadUtilities.sleep(100);
-
deploymentClient.stopClient();
}
}
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
index 5bbe1812d..965013acb 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
@@ -26,8 +26,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.core.protocols.Message;
import org.onap.policy.apex.core.protocols.engdep.messages.EngineServiceInfoResponse;
import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineInfo;
@@ -42,6 +42,8 @@ import org.onap.policy.apex.core.protocols.engdep.messages.UpdateModel;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.common.utils.resources.TextFileUtils;
+import static org.awaitility.Awaitility.await;
+
/**
* Dummy deployment client.
*/
@@ -81,10 +83,7 @@ public class DummyDeploymentClient extends DeploymentClient implements Runnable
started = true;
// Loop forever, sending messages as they appear on the queue
- while (started && !thisThread.isInterrupted()) {
- ThreadUtilities.sleep(50);
- }
-
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> !(started && !thisThread.isInterrupted()));
// Thread has been interrupted
thisThread = null;
started = false;
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
index 2663dfc0d..f91b58bb9 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -22,6 +22,7 @@
package org.onap.policy.apex.core.engine.engine.impl;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -32,6 +33,8 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -312,8 +315,7 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.STOPPED, engine.getState());
}
}).start();
-
- Thread.sleep(50);
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING));
assertEquals(AxEngineState.EXECUTING, engine.getState());
assertFalse(engine.handleEvent(event));
@@ -343,7 +345,7 @@ public class ApexEngineImplTest {
}
}).start();
- Thread.sleep(50);
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING));
assertEquals(AxEngineState.EXECUTING, engine.getState());
try {
engine.stop();
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
index 9b6fc398c..178e16a43 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications 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.
@@ -41,7 +42,7 @@ public class DummySlowEnEventListener implements EnEventListener {
Thread.sleep(waitTime);
}
catch (InterruptedException ie) {
- // Do nothing
+ //Do nothing
}
}
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java
index c9d56ef2c..d9691f17e 100644
--- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.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.core.infrastructure.messaging;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -27,10 +29,11 @@ import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
+import java.util.concurrent.TimeUnit;
+
/**
* The Class EndToEndMessagingTest.
*
@@ -59,9 +62,8 @@ public class EndToEndStringMessagingTest {
client.sendString("Hello, client here");
- while (!finished) {
- ThreadUtilities.sleep(50);
- }
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> finished);
+
} finally {
if (client != null) {
client.stop();
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java
index 1471bf331..9cf99feb3 100644
--- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.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.
@@ -47,9 +48,8 @@ public class StringTestServer {
System.out.println("StringTestServer started on port " + port + " for " + timeToLive + " seconds");
- for (; timeToLive > 0; timeToLive--) {
- ThreadUtilities.sleep(1000);
- }
+ // convert to milliSeconds
+ ThreadUtilities.sleep(1000 * timeToLive);
server.stop();
System.out.println("StringTestServer completed");
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java
index 055a76fc5..23f458a67 100644
--- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.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,11 +21,13 @@
package org.onap.policy.apex.core.infrastructure.threading;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.slf4j.ext.XLogger;
@@ -77,10 +80,11 @@ public class ThreadingTest {
final Thread thread = threadFactory.newThread(runnable);
thread.start();
- }
+ if (i == 4) {
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> thread.isAlive());
+ }
- // Threads should need a little more than 300ms to count to 3
- ThreadUtilities.sleep(380);
+ }
for (int i = 0; i < 5; i++) {
threadList.get(i).interrupt();
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java
index b504780b7..a2c51539f 100644
--- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.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.
@@ -23,6 +24,8 @@ package org.onap.policy.apex.core.infrastructure.threading;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
+import java.util.concurrent.CountDownLatch;
+
/**
* The Class ThreadingTestThread.
*
@@ -39,7 +42,9 @@ public class ThreadingTestThread implements Runnable {
private String threadName;
- /**
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ /**
* {@inheritDoc}.
*/
@Override
@@ -54,11 +59,11 @@ public class ThreadingTestThread implements Runnable {
if (logger.isDebugEnabled()) {
logger.debug("in threading test thread \"" + threadName + "\", counter=" + counter + " . . .");
}
-
- if (!ThreadUtilities.sleep(50)) {
+ if(!ThreadUtilities.sleep(50)) {
interrupted = true;
}
}
+
if (logger.isDebugEnabled()) {
logger.debug("stopped threading test thread \"" + threadName + "\"");
}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java
index 03372d745..bca901e6b 100644
--- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.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.
@@ -22,10 +23,11 @@ package org.onap.policy.apex.examples.aadm;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.onap.policy.apex.core.engine.engine.EnEventListener;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+import static org.awaitility.Awaitility.await;
/**
* The listener interface for receiving testApexAction events. The class that is interested in processing a
@@ -55,9 +57,7 @@ public class TestApexActionListener implements EnEventListener {
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
@@ -66,12 +66,9 @@ public class TestApexActionListener implements EnEventListener {
*/
@Override
public void onEnEvent(final EnEvent actionEvent) {
- ThreadUtilities.sleep(100);
-
- if (actionEvent != null) {
- System.out.println("Action event from engine:" + actionEvent.getName());
- resultEvents.add(actionEvent);
- }
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> actionEvent != null);
+ System.out.println("Action event from engine:" + actionEvent.getName());
+ resultEvents.add(actionEvent);
}
/**
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
index 7ada6a795..d1b2aaae7 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -21,12 +21,15 @@
package org.onap.policy.apex.examples.adaptive;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -38,11 +41,11 @@ import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.core.engine.engine.ApexEngine;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters;
import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters;
@@ -149,7 +152,7 @@ public class AnomalyDetectionTslUseCaseTest {
assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
triggerEvent.clear();
result.clear();
- ThreadUtilities.sleep(1);
+ await().atLeast(1, TimeUnit.MILLISECONDS).until(() -> result.isEmpty());
apexEngine1.stop();
}
@@ -216,7 +219,7 @@ public class AnomalyDetectionTslUseCaseTest {
result.clear();
}
apexEngine1.stop();
- ThreadUtilities.sleep(1000);
+ await().atLeast(1000, TimeUnit.MILLISECONDS).until(() -> apexEngine1.getState().equals(AxEngineState.STOPPED));
}
/**
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
index d40dcc672..ab0bf303f 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -21,12 +21,14 @@
package org.onap.policy.apex.examples.adaptive;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Random;
+import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@@ -39,11 +41,11 @@ import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.core.engine.engine.ApexEngine;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters;
import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters;
@@ -148,7 +150,7 @@ public class AutoLearnTslUseCaseTest {
assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
triggerEvent.clear();
result.clear();
- ThreadUtilities.sleep(10);
+ await().atLeast(10, TimeUnit.MILLISECONDS).until(() -> triggerEvent.isEmpty() && result.isEmpty());
apexEngine1.stop();
}
@@ -236,11 +238,11 @@ public class AutoLearnTslUseCaseTest {
LOGGER.info("Iteration " + iteration + ": \tpreval\t" + prevval + "\tval\t" + val + "\tavval\t" + avval);
result.clear();
- ThreadUtilities.sleep(10);
+ await().atLeast(10, TimeUnit.MILLISECONDS).until(() -> !result.isEmpty());
}
apexEngine1.stop();
- ThreadUtilities.sleep(1000);
+ await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> apexEngine1.getState().equals(AxEngineState.STOPPED));
}
/**
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java
index cd1327123..28924728e 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.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.
@@ -22,10 +23,12 @@ package org.onap.policy.apex.examples.adaptive;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.onap.policy.apex.core.engine.engine.EnEventListener;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+
+import static org.awaitility.Awaitility.await;
/**
* The listener interface for receiving testApexAction events. The class that is interested in processing a
@@ -55,9 +58,7 @@ public class TestApexActionListener implements EnEventListener {
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
@@ -66,8 +67,6 @@ public class TestApexActionListener implements EnEventListener {
*/
@Override
public void onEnEvent(final EnEvent actionEvent) {
- ThreadUtilities.sleep(100);
-
if (actionEvent != null) {
System.out.println("Action event from engine:" + actionEvent.getName());
resultEvents.add(actionEvent);
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
index 3fce59c93..0169d14cb 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.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.
@@ -22,10 +23,12 @@ package org.onap.policy.apex.examples.myfirstpolicy;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.onap.policy.apex.core.engine.engine.EnEventListener;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+
+import static org.awaitility.Awaitility.await;
/**
* The listener interface for receiving SaleAuth events. The class that is interested in processing a SaleAuth event
@@ -57,9 +60,7 @@ public class TestSaleAuthListener implements EnEventListener {
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
@@ -68,8 +69,6 @@ public class TestSaleAuthListener implements EnEventListener {
*/
@Override
public void onEnEvent(final EnEvent saleauthEvent) {
- ThreadUtilities.sleep(100);
-
if (saleauthEvent != null) {
System.out.println("SaleAuth event from engine:" + saleauthEvent.getName());
resultEvents.add(saleauthEvent);
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
index 6face9e50..3341082c0 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -21,6 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -28,6 +29,7 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation.Builder;
@@ -39,7 +41,6 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
@@ -119,7 +120,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
@@ -127,7 +128,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
@@ -169,7 +170,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
@@ -214,14 +215,10 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
-
assertEquals(0, incomingEventReceiver.getEventCount());
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
}
@Test
@@ -261,7 +258,8 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
@@ -305,10 +303,9 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(
+ () -> incomingEventReceiver.getLastEvent().equals("This is an event"));
arcc.stop();
-
- assertEquals("This is an event", incomingEventReceiver.getLastEvent());
}
@Test
@@ -349,7 +346,7 @@ public class ApexRestClientConusmerTest {
try {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
} catch (Exception e) {
// test invalid status code
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
index 46390f9d6..0c6067a75 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -21,11 +21,13 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -126,7 +128,7 @@ public class ApexRestRequestorConsumerTest {
consumer.start();
ApexRestRequest request = new ApexRestRequest(123, null, EVENT_NAME, EVENT_BODY);
consumer.processRestRequest(request);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> consumer.getEventsReceived() == 0);
consumer.stop();
assertEquals(0, consumer.getEventsReceived());
}
@@ -152,7 +154,7 @@ public class ApexRestRequestorConsumerTest {
consumer.start();
ApexRestRequest request = new ApexRestRequest(123, properties, EVENT_NAME, EVENT_BODY);
consumer.processRestRequest(request);
- ThreadUtilities.sleep(2000);
+ await().atMost(2000, TimeUnit.MILLISECONDS).until(() -> consumer.getEventsReceived() == 0);
consumer.stop();
assertEquals(0, consumer.getEventsReceived());
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
index a650d796f..55baf3cf7 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -365,8 +365,6 @@ public class RestRequestorTest {
client.close();
assertEquals(Double.valueOf(8.0), getsSoFar);
-
- ThreadUtilities.sleep(1000);
}
/**
diff --git a/pom.xml b/pom.xml
index 4de73154c..95cee176e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.8.0-beta2</version>
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index 86ae99ec7..4b05c525c 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.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.service.engine.main;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -28,9 +30,10 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.parameters.ApexParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
@@ -57,11 +60,8 @@ public class ApexMainTest {
System.setOut(new PrintStream(outContent));
ApexMain.main(null);
- ThreadUtilities.sleep(200);
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Apex configuration file was not specified as an argument"));
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Apex configuration file was not specified as an argument"));
}
@Test
@@ -72,12 +72,9 @@ public class ApexMainTest {
String[] args = { "-whee" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("invalid command line arguments specified : Unrecognized option: -whee"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee"));
}
@Test
@@ -88,12 +85,9 @@ public class ApexMainTest {
String[] args = { "-h" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
}
@Test
@@ -104,12 +98,9 @@ public class ApexMainTest {
String[] args = { "-c", "src/test/resources/parameters/badParams.json" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("parameter group has status INVALID"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("parameter group has status INVALID"));
}
@Test
@@ -122,12 +113,9 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
assertEquals("MyApexEngine",
apexMain.getApexParametersMap().values().iterator().next().getEngineServiceParameters().getName());
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test
@@ -143,13 +131,9 @@ public class ApexMainTest {
assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore"));
assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword"));
- ThreadUtilities.sleep(200);
+ await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- ThreadUtilities.sleep(10000);
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test