aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java17
5 files changed, 42 insertions, 14 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);
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java
index 91b34e20c..9eaaeeef2 100644
--- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java
@@ -19,7 +19,9 @@
*/
package org.onap.policy.apex.core.infrastructure.messaging;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.InetAddress;
@@ -32,30 +34,31 @@ public class MessagingUtilsTest {
@Test
public void testCheckPort() throws UnknownHostException, IOException {
- assertEquals(1,MessagingUtils.checkPort(1));
- assertEquals(1,MessagingUtils.findPort(1));
+ assertEquals(1, MessagingUtils.checkPort(1));
+ assertEquals(1, MessagingUtils.findPort(1));
}
@Test(expected = IllegalArgumentException.class)
public void testIllegalArgumentException() {
- assertEquals(1,MessagingUtils.findPort(65536));
+ assertEquals(1, MessagingUtils.findPort(65536));
}
@Test
public void testGetHost() throws UnknownHostException {
InetAddress host = InetAddress.getLocalHost();
- assertEquals(host,MessagingUtils.getHost());
+ assertEquals(host, MessagingUtils.getHost());
}
@Test
public void testValidAllocateAddress() throws UnknownHostException {
assertNotNull(MessagingUtils.getLocalHostLanAddress());
- assertEquals(3306,MessagingUtils.allocateAddress(3306));
+ int allocatedPort = MessagingUtils.allocateAddress(3306);
+ assertTrue(allocatedPort >= 3306 && allocatedPort < 65536);
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidAllocateAddress() {
- assertEquals(1,MessagingUtils.allocateAddress(1));
+ assertEquals(1, MessagingUtils.allocateAddress(1));
}
@Test