summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-05-15 15:09:37 +0100
committerliamfallon <liam.fallon@est.tech>2020-05-15 15:16:18 +0100
commit1906e13ff902a096bcf1f7077122ca3eb811d02c (patch)
tree5a4c314c35f8cd5013b4ac605b6d2e31490a7a61 /core
parentc0b182649ee4ad6b963990ae15c3f3bcec2e09bc (diff)
Fix Web Socket server connection failure
In the Web Socket unit test, sometimes the server does not start quickly enough and is not available when the wek socket client connects. This review changes the unit test to wait for up to 2 seconds for the web socket server to come up. Issue-ID: POLICY-2571 Change-Id: I0c970783f368d691d07683bad0cdc28b681e5334 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'core')
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java9
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java22
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java6
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java2
4 files changed, 32 insertions, 7 deletions
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java
index 98bffdbc6..968ec97db 100644
--- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java
+++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.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.
@@ -135,4 +136,12 @@ public class WsStringMessageClient implements WsStringMessager {
wsStringMessageListener.receiveString(messageString);
}
}
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public boolean isStarted() {
+ return service.isStarted();
+ }
}
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
index 41fb82a9e..6b1dc6709 100644
--- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
+++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.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.
@@ -22,9 +22,11 @@
package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging;
import com.google.common.eventbus.Subscribe;
+
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
+
import org.onap.policy.apex.core.infrastructure.messaging.MessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
@@ -72,17 +74,15 @@ public class WsStringMessageServer implements WsStringMessager {
String lanaddress = "unknown";
try {
lanaddress = MessagingUtils.getLocalHostLanAddress().getHostAddress();
- }
- catch (final UnknownHostException ignore) {
- LOGGER.debug("Failed to find name of local address name",ignore);
+ } catch (final UnknownHostException ignore) {
+ LOGGER.debug("Failed to find name of local address name", ignore);
}
LOGGER.debug("web socket string message server LAN address=" + lanaddress);
String hostaddress = "unknown";
try {
hostaddress = InetAddress.getLocalHost().getHostAddress();
- }
- catch (final UnknownHostException ignore) {
- LOGGER.debug("Failed to find name of local address",ignore);
+ } catch (final UnknownHostException ignore) {
+ LOGGER.debug("Failed to find name of local address", ignore);
}
LOGGER.debug("web socket string message server host address=" + hostaddress);
}
@@ -145,4 +145,12 @@ public class WsStringMessageServer implements WsStringMessager {
wsStringMessageListener.receiveString(messageString);
}
}
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public boolean isStarted() {
+ return service.isStarted();
+ }
}
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java
index 2a731b0eb..c6db1ffc7 100644
--- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java
+++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.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.
@@ -48,4 +49,9 @@ public interface WsStringMessager {
* @param stringMessage the string message to send
*/
void sendString(String stringMessage);
+
+ /**
+ * Check if the string messager is started.
+ */
+ boolean isStarted();
}
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 5a1390163..35d348568 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
@@ -55,6 +55,8 @@ public class EndToEndStringMessagingTest {
assertNotNull(server);
server.start(new WsStringServerMessageListener());
+ await().atMost(2, TimeUnit.SECONDS).until(() -> server.isStarted());
+
try {
client = new WsStringMessageClient("localhost", 44441);
assertNotNull(client);