ARTEMIS-2424 Testing functionality where we disable isReacheable if a ping custom command is used
This commit is contained in:
parent
90e4384a41
commit
60a15f3b50
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue