From 69c227a9f1d91268fbd91471b012af38fba8b857 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 6 Apr 2020 15:41:28 +0100 Subject: Fix intermittent unit test failures WebSocket The Web Socket server is marked as started before the start process has complted. This change fixes that issue. Issue-ID: POLICY-1470 Change-Id: I5b5ef5832893d884a6551b0516df91cb71d6c622 Signed-off-by: liamfallon --- .../messaging/impl/ws/server/MessageServerImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java index 3844b9254..5b2167e75 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.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,7 @@ package org.onap.policy.apex.core.infrastructure.messaging.impl.ws.server; import java.io.IOException; import java.net.InetSocketAddress; import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; import org.java_websocket.WebSocket; import org.onap.policy.apex.core.infrastructure.messaging.MessageHolder; @@ -47,7 +49,7 @@ public class MessageServerImpl extends InternalMessageBusServer { private final String connectionUri; // Indicates if the web socket server is started or not - private boolean isStarted = false; + private final AtomicBoolean isStarted = new AtomicBoolean(false); /** * Instantiates a new web socket messaging server for Apex. @@ -73,7 +75,6 @@ public class MessageServerImpl extends InternalMessageBusServer { public void startConnection() { // Start reception of connections on the web socket start(); - isStarted = true; } /** @@ -98,7 +99,7 @@ public class MessageServerImpl extends InternalMessageBusServer { Thread.currentThread().interrupt(); // This can happen in normal operation so ignore } - isStarted = false; + isStarted.set(false); } /** @@ -141,11 +142,12 @@ public class MessageServerImpl extends InternalMessageBusServer { */ @Override public boolean isStarted() { - return isStarted; + return isStarted.get(); } @Override public void onStart() { + isStarted.set(true); LOGGER.debug("started deployment server on URI: {}", connectionUri); } } -- cgit 1.2.3-korg