ARTEMIS-1737 Fixing semantic of ServerControl.forceFailover

This closes #1940
This commit is contained in:
Clebert Suconic 2018-03-08 16:24:38 -05:00
parent dc096f950d
commit 91c0452d60
5 changed files with 49 additions and 24 deletions

View File

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

View File

@ -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,

View File

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

View File

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

View File

@ -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,6 +139,22 @@ public class ReplicatedFailoverTest extends FailoverTest {
@Test
public void testReplicatedFailbackBackupFromLiveBackToBackup() throws Exception {
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";
@ -144,11 +167,17 @@ public class ReplicatedFailoverTest extends FailoverTest {
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().backToBackup(true);
assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted());
((ServiceComponent)(backupServer.getServer().getExternalComponents().get(0))).stop(true);
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