ARTEMIS-2021 NetworkHealthCheck should only restart servers after net outages

This commit is contained in:
Clebert Suconic 2018-08-09 12:22:43 -04:00
parent d2063131f4
commit 26208b76c7
2 changed files with 30 additions and 1 deletions

View File

@ -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());
}

View File

@ -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));