diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2020-07-29 10:42:43 +0100 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2020-07-29 16:28:18 +0100 |
commit | e35c91fe9dcbab415cffc100595f3c3ae59598e7 (patch) | |
tree | d7fd35b97a37d43bb5f0db65fc90bb2b05c6db00 /core/core-deployment | |
parent | 8ce1780bffcda97066a260ca4964dd1006fdb848 (diff) |
Fixing intermittent test failures in APEX
Here the intermittent test failures are fixed by providing a latch to
wait until the DeploymentClient is started. This may need improvement,
but all these deployment classes will be removed soon, hence not worth
the effort.
Change-Id: I1090e991c0448b42af1d9cbd16d96ae1cb5774fd
Issue-ID: POLICY-2654
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'core/core-deployment')
3 files changed, 18 insertions, 9 deletions
diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java index 9033ff423..c3246643e 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +27,12 @@ import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.apex.core.infrastructure.messaging.MessageHolder; import org.onap.policy.apex.core.infrastructure.messaging.MessageListener; import org.onap.policy.apex.core.infrastructure.messaging.MessagingService; @@ -71,6 +76,9 @@ public class DeploymentClient implements Runnable { // Number of messages processed private long messagesSent = 0; private long messagesReceived = 0; + @Getter + @Setter + private AtomicReference<CountDownLatch> countDownLatch = new AtomicReference<>(); /** * Instantiates a new deployment client. @@ -81,6 +89,7 @@ public class DeploymentClient implements Runnable { public DeploymentClient(final String host, final int port) { this.host = host; this.port = port; + countDownLatch.set(new CountDownLatch(1)); } /** @@ -102,6 +111,7 @@ public class DeploymentClient implements Runnable { service.startConnection(); started = true; + countDownLatch.get().countDown(); LOGGER.debug("engine<-->deployment client thread started"); } catch (final Exception e) { LOGGER.error("engine<-->deployment client thread exception", e); @@ -198,6 +208,7 @@ public class DeploymentClient implements Runnable { service.stopConnection(); } started = false; + countDownLatch.set(new CountDownLatch(1)); LOGGER.debug("engine<-->deployment test client stopped . . ."); } diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java index 1a09ffe56..7d70960de 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +27,6 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; 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; @@ -69,7 +69,6 @@ public class EngineServiceFacade { // The default message timeout and timeout increment (the amount of time between // polls) in // milliseconds - private static final int CLIENT_START_WAIT_INTERVAL = 100; private static final int REPLY_MESSAGE_TIMEOUT_DEFAULT = 10000; private static final int REPLY_MESSAGE_TIMEOUT_INCREMENT = 100; @@ -125,12 +124,8 @@ public class EngineServiceFacade { clientThread.start(); // Wait for the connection to come up - while (!client.isStarted()) { - if (clientThread.isAlive()) { - ThreadUtilities.sleep(CLIENT_START_WAIT_INTERVAL); - } else { - throw new ApexDeploymentException("could not handshake with server " + hostName + ":" + port); - } + if (!client.getCountDownLatch().get().await(5L, TimeUnit.SECONDS)) { + throw new ApexDeploymentException("could not handshake with server " + hostName + ":" + port); } LOGGER.debug("opened connection to server {}:{} . . .", hostName, port); 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 ffb3d2c63..553380944 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +28,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import lombok.Getter; @@ -84,7 +86,7 @@ public class DummyDeploymentClient extends DeploymentClient implements Runnable thisThread.setName(DeploymentClient.class.getName() + "-" + getHost() + ":" + getPort()); started = true; - + getCountDownLatch().get().countDown(); // Loop forever, sending messages as they appear on the queue await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> !(started && !thisThread.isInterrupted())); // Thread has been interrupted @@ -202,6 +204,7 @@ public class DummyDeploymentClient extends DeploymentClient implements Runnable thisThread.interrupt(); } started = false; + getCountDownLatch().set(new CountDownLatch(1)); } /** |