Skip to content

Commit

Permalink
ARTEMIS-1737 Fixing semantic of ServerControl.forceFailover
Browse files Browse the repository at this point in the history
This closes apache#1940
  • Loading branch information
clebertsuconic committed Mar 28, 2018
1 parent 94beb50 commit 521ccfc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
Expand Up @@ -2611,7 +2611,7 @@ public void forceFailover() throws Exception {
@Override
public void run() {
try {
server.fail(true);
server.stop(true, true);
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
Expand Down
Expand Up @@ -432,7 +432,7 @@ void destroyQueue(SimpleString queueName,

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,
Expand Down
Expand Up @@ -912,14 +912,10 @@ public void threadDump() {

@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);
}
Expand Down
Expand Up @@ -187,7 +187,7 @@ public void run() {
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());
Expand Down
Expand Up @@ -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;
Expand All @@ -27,6 +33,7 @@
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;
Expand Down Expand Up @@ -132,23 +139,45 @@ protected void beforeWaitForRemoteBackupSynchronization() {

@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<AppDTO>();
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 = "<html><body><b>This is a unit test</b></body></html>";
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<AppDTO>();
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
Expand Down

0 comments on commit 521ccfc

Please sign in to comment.