You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/03/10 14:32:40 UTC

[activemq-artemis] branch master updated: ARTEMIS-1194 fix test

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cb3c96  ARTEMIS-1194 fix test
     new 1a3561b  This closes #3010
0cb3c96 is described below

commit 0cb3c96b3e16f9fc26edaea2342958e76fad752d
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Mon Mar 9 21:05:27 2020 -0500

    ARTEMIS-1194 fix test
---
 .../remoting/impl/netty/NettyConnectorTest.java    | 37 ++++++++++++++++++----
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
index d31f722..67eed00 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
@@ -17,6 +17,9 @@
 package org.apache.activemq.artemis.tests.unit.core.remoting.impl.netty;
 
 import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -25,7 +28,6 @@ import java.util.concurrent.ScheduledExecutorService;
 
 import io.netty.channel.ChannelPipeline;
 import io.netty.handler.proxy.Socks5ProxyHandler;
-
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
@@ -42,6 +44,7 @@ import org.apache.activemq.artemis.spi.core.remoting.Connection;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -399,13 +402,14 @@ public class NettyConnectorTest extends ActiveMQTestBase {
 
    @Test
    public void testSocksProxyHandlerAdded() throws Exception {
-      BufferHandler handler = new BufferHandler() {
-         @Override
-         public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
-         }
+      InetAddress address = getNonLoopbackAddress();
+      Assume.assumeTrue("Cannot find non-loopback address", address != null);
+
+      BufferHandler handler = (connectionID, buffer) -> {
       };
       Map<String, Object> params = new HashMap<>();
-      params.put(TransportConstants.HOST_PROP_NAME, InetAddress.getLocalHost().getHostAddress());
+
+      params.put(TransportConstants.HOST_PROP_NAME, address.getHostAddress());
       params.put(TransportConstants.PROXY_ENABLED_PROP_NAME, true);
       params.put(TransportConstants.PROXY_HOST_PROP_NAME, "localhost");
 
@@ -441,6 +445,27 @@ public class NettyConnectorTest extends ActiveMQTestBase {
       Assert.assertFalse(connector.isStarted());
    }
 
+   private InetAddress getNonLoopbackAddress() throws SocketException {
+      Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces();
+      InetAddress addr = null;
+      for (; n.hasMoreElements(); ) {
+         NetworkInterface e = n.nextElement();
+         Enumeration<InetAddress> a = e.getInetAddresses();
+         boolean found = false;
+         for (; a.hasMoreElements(); ) {
+            addr = a.nextElement();
+            if (!addr.isLoopbackAddress()) {
+               found = true;
+               break;
+            }
+         }
+         if (found) {
+            break;
+         }
+      }
+      return addr;
+   }
+
    @Test
    public void testSocksProxyHandlerNotAddedForLocalhost() throws Exception {
       BufferHandler handler = new BufferHandler() {