This closes #1945
This commit is contained in:
commit
2cc163da79
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -432,6 +432,8 @@ public interface ActiveMQServer extends ServiceComponent {
|
|||
|
||||
void fail(boolean failoverOnServerShutdown) throws Exception;
|
||||
|
||||
void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception;
|
||||
|
||||
Queue updateQueue(String name,
|
||||
RoutingType routingType,
|
||||
Integer maxConsumers,
|
||||
|
@ -472,6 +474,8 @@ public interface ActiveMQServer extends ServiceComponent {
|
|||
|
||||
void addExternalComponent(ActiveMQComponent externalComponent);
|
||||
|
||||
List<ActiveMQComponent> getExternalComponents();
|
||||
|
||||
boolean addClientConnection(String clientId, boolean unique);
|
||||
|
||||
void removeClientConnection(String clientId);
|
||||
|
|
|
@ -912,9 +912,10 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
|
||||
@Override
|
||||
public final void fail(boolean failoverOnServerShutdown) throws Exception {
|
||||
stop(failoverOnServerShutdown, false, false, true);
|
||||
stop(failoverOnServerShutdown, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception {
|
||||
stop(failoverOnServerShutdown, false, false, isExit);
|
||||
}
|
||||
|
@ -3124,4 +3125,9 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
public Set<ActivateCallback> getActivateCallbacks() {
|
||||
return activateCallbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActiveMQComponent> getExternalComponents() {
|
||||
return externalComponents;
|
||||
}
|
||||
}
|
|
@ -275,6 +275,12 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-web</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- DB Test Deps -->
|
||||
<dependency>
|
||||
|
|
|
@ -16,12 +16,24 @@
|
|||
*/
|
||||
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;
|
||||
import org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration;
|
||||
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;
|
||||
|
@ -125,6 +137,49 @@ 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";
|
||||
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
|
||||
protected void createConfigs() throws Exception {
|
||||
createReplicatedConfigs();
|
||||
|
|
Loading…
Reference in New Issue