From 26208b76c768b02c145b00674048fcb91ed5f92c Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Thu, 9 Aug 2018 12:22:43 -0400 Subject: [PATCH] ARTEMIS-2021 NetworkHealthCheck should only restart servers after net outages --- .../core/server/NetworkHealthCheck.java | 6 ++++- .../artemis/utils/NetworkHealthTest.java | 25 +++++++++++++++++++ 2 files changed, 30 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 c8f0d4d7c6..75d823a6af 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 @@ -60,6 +60,8 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { // To be used on tests. As we use the loopback as a valid address on tests. private boolean ignoreLoopback = false; + private boolean ownShutdown = false; + /** * The timeout to be used on isReachable */ @@ -274,7 +276,7 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { if (healthy) { for (ActiveMQComponent component : componentList) { - if (!component.isStarted()) { + if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); @@ -282,6 +284,7 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } + ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { @@ -289,6 +292,7 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent { try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); + ownShutdown = true; } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } 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 de25525301..a654ff182c 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 @@ -142,6 +142,31 @@ public class NetworkHealthTest { Assert.assertTrue(check.check(address)); } + @Test + public void testAlreadyShutdown() throws Exception { + assumeTrue(purePingWorks(IPV6_LOCAL)); + ReusableLatch latch = new ReusableLatch(0); + NetworkHealthCheck check = addCheck(new NetworkHealthCheck(null, 100, 100) { + @Override + public void run() { + super.run(); + latch.countDown(); + System.out.println("Check"); + } + }); + check.addComponent(component); + InetAddress address = InetAddress.getByName("127.0.0.1"); + check.addAddress(address); + + component.stop(); + + latch.setCount(1); + Assert.assertTrue(latch.await(1, TimeUnit.MINUTES)); + + Assert.assertFalse("NetworkHealthCheck should have no business on restarting the component, the network was never down, hence no check needed!", component.isStarted()); + + } + @Test public void testParseSpaces() throws Exception { NetworkHealthCheck check = addCheck(new NetworkHealthCheck(null, 100, 100));