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
commit 60a15f3b5050fb7bfd2ae316f6ba6c1d280ec4a1 Author: Clebert Suconic <[email protected]> AuthorDate: Thu Aug 29 18:41:26 2019 -0400 ARTEMIS-2424 Testing functionality where we disable isReacheable if a ping custom command is used --- .../artemis/core/server/NetworkHealthCheck.java | 6 ++- .../activemq/artemis/utils/NetworkHealthTest.java | 58 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/NetworkHealthCheck.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/NetworkHealthCheck.java index 1d02a44..446e150 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/NetworkHealthCheck.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/NetworkHealthCheck.java @@ -331,7 +331,7 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { } try { - if (!hasCustomPingCommand() && address.isReachable(networkInterface, 0, networkTimeout)) { + if (!hasCustomPingCommand() && isReachable(address)) { if (logger.isTraceEnabled()) { logger.tracef(address + " OK"); } @@ -345,6 +345,10 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { } } + protected boolean isReachable(InetAddress address) throws IOException { + return address.isReachable(networkInterface, 0, networkTimeout); + } + public boolean purePing(InetAddress address) throws IOException, InterruptedException { long timeout = Math.max(1, TimeUnit.MILLISECONDS.toSeconds(networkTimeout)); // it did not work with a simple isReachable, it could be because there's no root access, so we will try ping executable diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java index 30e090c..221a97c 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java @@ -26,6 +26,7 @@ import java.net.URL; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -269,4 +270,61 @@ public class NetworkHealthTest { } + + @Test + public void testValidateCommand() throws Throwable { + AtomicInteger purePing = new AtomicInteger(0); + AtomicInteger isReacheable = new AtomicInteger(0); + NetworkHealthCheck myCheck = + new NetworkHealthCheck() { + @Override + protected boolean isReachable(InetAddress address) throws IOException { + isReacheable.incrementAndGet(); + return false; + } + + @Override + public boolean purePing(InetAddress address) throws IOException, InterruptedException { + purePing.incrementAndGet(); + return false; + } + }; + + myCheck.setIpv4Command("whatever"); + myCheck.setIpv6Command("whatever"); + + myCheck.check(InetAddress.getByName("127.0.0.1")); + + Assert.assertEquals(0, isReacheable.get()); + Assert.assertEquals(1, purePing.get()); + } + + @Test + public void testValidateIsReachable() throws Throwable { + AtomicInteger purePing = new AtomicInteger(0); + AtomicInteger isReacheable = new AtomicInteger(0); + NetworkHealthCheck myCheck = + new NetworkHealthCheck() { + @Override + protected boolean isReachable(InetAddress address) throws IOException { + isReacheable.incrementAndGet(); + return true; + } + + @Override + public boolean purePing(InetAddress address) throws IOException, InterruptedException { + purePing.incrementAndGet(); + return false; + } + }; + + //myCheck.setIpv4Command("whatever"); + //myCheck.setIpv6Command("whatever"); + + myCheck.check(InetAddress.getByName("127.0.0.1")); + + Assert.assertEquals(1, isReacheable.get()); + Assert.assertEquals(0, purePing.get()); + } + }
