summaryrefslogtreecommitdiffstats
path: root/core/core-deployment
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 /core/core-deployment
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 'core/core-deployment')
-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
2 files changed, 10 insertions, 13 deletions
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;