diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index fe7792b400..72e23a7a6b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -2611,7 +2611,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active @Override public void run() { try { - server.fail(true); + server.stop(true, true); } catch (Throwable e) { logger.warn(e.getMessage(), e); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index cc53e9932b..78ebbb710c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -432,7 +432,7 @@ public interface ActiveMQServer extends ServiceComponent { void fail(boolean failoverOnServerShutdown) throws Exception; - void backToBackup(boolean failoverOnServerShutdown) throws Exception; + void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception; Queue updateQueue(String name, RoutingType routingType, diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index ea485e3ab1..d2ae179783 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -912,14 +912,10 @@ public class ActiveMQServerImpl implements ActiveMQServer { @Override public final void fail(boolean failoverOnServerShutdown) throws Exception { - stop(failoverOnServerShutdown, false, false, true); - } - - @Override - public final void backToBackup(boolean failoverOnServerShutdown) throws Exception { stop(failoverOnServerShutdown, false, false, false); } + @Override public final void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception { stop(failoverOnServerShutdown, false, false, isExit); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java index eaba72df3f..2e289b5acf 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java @@ -187,7 +187,7 @@ public class SharedNothingLiveActivation extends LiveActivation { clusterConnection.addClusterTopologyListener(listener1); if (listener1.waitForBackup()) { //if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup - activeMQServer.backToBackup(true); + activeMQServer.fail(true); ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback(); // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize()); activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java index 663904406d..814eb8b68d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java @@ -16,9 +16,15 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.failover; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.concurrent.TimeUnit; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.component.WebServerComponent; import org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration; @@ -27,6 +33,7 @@ import org.apache.activemq.artemis.core.server.ServiceComponent; import org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy; import org.apache.activemq.artemis.dto.AppDTO; import org.apache.activemq.artemis.dto.WebServerDTO; +import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; @@ -132,23 +139,45 @@ public class ReplicatedFailoverTest extends FailoverTest { @Test public void testReplicatedFailbackBackupFromLiveBackToBackup() throws Exception { - WebServerDTO wdto = new WebServerDTO(); - AppDTO appDTO = new AppDTO(); - appDTO.war = "console.war"; - appDTO.url = "console"; - wdto.apps = new ArrayList(); - wdto.apps.add(appDTO); - wdto.bind = "http://localhost:0"; - wdto.path = "console"; - WebServerComponent webServerComponent = new WebServerComponent(); - webServerComponent.configure(wdto, ".", "."); - webServerComponent.start(); - backupServer.getServer().addExternalComponent(webServerComponent); - // this is called when backup servers go from live back to backup - backupServer.getServer().backToBackup(true); - assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted()); - ((ServiceComponent)(backupServer.getServer().getExternalComponents().get(0))).stop(true); + InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8787); + HttpServer httpServer = HttpServer.create(address, 100); + httpServer.start(); + + try { + httpServer.createContext("/", new HttpHandler() { + @Override + public void handle(HttpExchange t) throws IOException { + String response = "This is a unit test"; + t.sendResponseHeaders(200, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } + }); + WebServerDTO wdto = new WebServerDTO(); + AppDTO appDTO = new AppDTO(); + appDTO.war = "console.war"; + appDTO.url = "console"; + wdto.apps = new ArrayList(); + wdto.apps.add(appDTO); + wdto.bind = "http://localhost:0"; + wdto.path = "console"; + WebServerComponent webServerComponent = new WebServerComponent(); + webServerComponent.configure(wdto, ".", "."); + webServerComponent.start(); + + backupServer.getServer().getNetworkHealthCheck().parseURIList("http://localhost:8787"); + Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted()); + backupServer.getServer().addExternalComponent(webServerComponent); + // this is called when backup servers go from live back to backup + backupServer.getServer().fail(true); + Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted()); + Assert.assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted()); + ((ServiceComponent) (backupServer.getServer().getExternalComponents().get(0))).stop(true); + } finally { + httpServer.stop(0); + } } @Override