Repository: activemq-artemis Updated Branches: refs/heads/master d2063131f -> 9c905a2b5
ARTEMIS-2021 NetworkHealthCheck should only restart servers after net outages Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/26208b76 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/26208b76 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/26208b76 Branch: refs/heads/master Commit: 26208b76c768b02c145b00674048fcb91ed5f92c Parents: d206313 Author: Clebert Suconic <clebertsuco...@apache.org> Authored: Thu Aug 9 12:22:43 2018 -0400 Committer: Clebert Suconic <clebertsuco...@apache.org> Committed: Thu Aug 9 19:08:02 2018 -0400 ---------------------------------------------------------------------- .../artemis/core/server/NetworkHealthCheck.java | 6 ++++- .../artemis/utils/NetworkHealthTest.java | 25 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26208b76/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/NetworkHealthCheck.java ---------------------------------------------------------------------- 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 c8f0d4d..75d823a 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()); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26208b76/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java ---------------------------------------------------------------------- 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 de25525..a654ff1 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 @@ -143,6 +143,31 @@ public class NetworkHealthTest { } @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));