use of org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy in project activemq-artemis by apache.
the class HAPolicyConfigurationTest method colocatedTestNullBackup.
@Test
public void colocatedTestNullBackup() throws Exception {
Configuration configuration = createConfiguration("colocated-hapolicy-config-null-backup.xml");
ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
try {
server.start();
Activation activation = server.getActivation();
assertTrue(activation instanceof ColocatedActivation);
HAPolicy haPolicy = server.getHAPolicy();
assertTrue(haPolicy instanceof ColocatedPolicy);
ColocatedPolicy colocatedPolicy = (ColocatedPolicy) haPolicy;
ReplicatedPolicy livePolicy = (ReplicatedPolicy) colocatedPolicy.getLivePolicy();
assertNotNull(livePolicy);
assertEquals(livePolicy.getGroupName(), "purple");
assertTrue(livePolicy.isCheckForLiveServer());
assertEquals(livePolicy.getClusterName(), "abcdefg");
ReplicaPolicy backupPolicy = (ReplicaPolicy) colocatedPolicy.getBackupPolicy();
assertNotNull(backupPolicy);
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy in project activemq-artemis by apache.
the class HAPolicyConfigurationTest method colocatedTest.
@Test
public void colocatedTest() throws Exception {
Configuration configuration = createConfiguration("colocated-hapolicy-config.xml");
ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
try {
server.start();
Activation activation = server.getActivation();
assertTrue(activation instanceof ColocatedActivation);
HAPolicy haPolicy = server.getHAPolicy();
assertTrue(haPolicy instanceof ColocatedPolicy);
ColocatedPolicy colocatedPolicy = (ColocatedPolicy) haPolicy;
ReplicatedPolicy livePolicy = (ReplicatedPolicy) colocatedPolicy.getLivePolicy();
assertNotNull(livePolicy);
assertEquals(livePolicy.getGroupName(), "purple");
assertTrue(livePolicy.isCheckForLiveServer());
assertEquals(livePolicy.getClusterName(), "abcdefg");
ReplicaPolicy backupPolicy = (ReplicaPolicy) colocatedPolicy.getBackupPolicy();
assertNotNull(backupPolicy);
assertEquals(backupPolicy.getGroupName(), "tiddles");
assertEquals(backupPolicy.getMaxSavedReplicatedJournalsSize(), 22);
assertEquals(backupPolicy.getClusterName(), "33rrrrr");
assertFalse(backupPolicy.isRestartBackup());
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy in project activemq-artemis by apache.
the class FailoverTest method testFailBackLiveRestartsBackupIsGone.
@Test(timeout = 120000)
public void testFailBackLiveRestartsBackupIsGone() throws Exception {
locator.setFailoverOnInitialConnection(true);
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = addClientProducer(session.createProducer(FailoverTestBase.ADDRESS));
sendMessages(session, producer, NUM_MESSAGES);
producer.close();
session.commit();
SimpleString liveId = liveServer.getServer().getNodeID();
crash(session);
session.start();
ClientConsumer consumer = addClientConsumer(session.createConsumer(FailoverTestBase.ADDRESS));
receiveMessages(consumer);
assertNoMoreMessages(consumer);
consumer.close();
session.commit();
Assert.assertEquals("backup must be running with the same nodeID", liveId, backupServer.getServer().getNodeID());
sf.close();
backupServer.crash();
Thread.sleep(100);
Assert.assertFalse("backup is not running", backupServer.isStarted());
Assert.assertFalse("must NOT be a backup", liveServer.getServer().getHAPolicy() instanceof BackupPolicy);
adaptLiveConfigForReplicatedFailBack(liveServer);
beforeRestart(liveServer);
liveServer.start();
Assert.assertTrue("live initialized...", liveServer.getServer().waitForActivation(15, TimeUnit.SECONDS));
sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session2 = createSession(sf, false, false);
session2.start();
ClientConsumer consumer2 = session2.createConsumer(FailoverTestBase.ADDRESS);
boolean replication = liveServer.getServer().getHAPolicy() instanceof ReplicatedPolicy;
if (replication)
receiveMessages(consumer2, 0, NUM_MESSAGES, true);
assertNoMoreMessages(consumer2);
session2.commit();
}
use of org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy in project activemq-artemis by apache.
the class ReplicatedFailoverTest method testReplicatedFailback.
@Test(timeout = 120000)
public /*
* default maxSavedReplicatedJournalsSize is 2, this means the backup will fall back to replicated only twice, after this
* it is stopped permanently
*
* */
void testReplicatedFailback() throws Exception {
try {
beforeWaitForRemoteBackupSynchronization();
waitForRemoteBackupSynchronization(backupServer.getServer());
createSessionFactory();
ClientSession session = createSession(sf, true, true);
session.createQueue(ADDRESS, ADDRESS, null, true);
crash(session);
ReplicatedPolicy haPolicy = (ReplicatedPolicy) liveServer.getServer().getHAPolicy();
haPolicy.setCheckForLiveServer(true);
liveServer.start();
waitForRemoteBackupSynchronization(liveServer.getServer());
waitForRemoteBackupSynchronization(backupServer.getServer());
waitForServerToStart(liveServer.getServer());
session = createSession(sf, true, true);
crash(session);
ReplicatedPolicyConfiguration replicatedPolicyConfiguration = (ReplicatedPolicyConfiguration) liveServer.getServer().getConfiguration().getHAPolicyConfiguration();
replicatedPolicyConfiguration.setCheckForLiveServer(true);
liveServer.start();
waitForRemoteBackupSynchronization(liveServer.getServer());
waitForRemoteBackupSynchronization(backupServer.getServer());
waitForServerToStart(liveServer.getServer());
session = createSession(sf, true, true);
crash(session);
replicatedPolicyConfiguration = (ReplicatedPolicyConfiguration) liveServer.getServer().getConfiguration().getHAPolicyConfiguration();
replicatedPolicyConfiguration.setCheckForLiveServer(true);
liveServer.start();
waitForServerToStart(liveServer.getServer());
backupServer.getServer().waitForActivation(5, TimeUnit.SECONDS);
waitForRemoteBackupSynchronization(liveServer.getServer());
waitForServerToStart(backupServer.getServer());
assertTrue(backupServer.getServer().isStarted());
} finally {
if (sf != null) {
sf.close();
}
try {
liveServer.getServer().stop();
} catch (Throwable ignored) {
}
try {
backupServer.getServer().stop();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy in project activemq-artemis by apache.
the class FailoverTestBase method adaptLiveConfigForReplicatedFailBack.
protected final void adaptLiveConfigForReplicatedFailBack(TestableServer server) {
Configuration configuration = server.getServer().getConfiguration();
final TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
if (server.getServer().getHAPolicy().isSharedStore()) {
ClusterConnectionConfiguration cc = configuration.getClusterConfigurations().get(0);
Assert.assertNotNull("cluster connection configuration", cc);
Assert.assertNotNull("static connectors", cc.getStaticConnectors());
cc.getStaticConnectors().add(backupConnector.getName());
// backupConnector is only necessary for fail-back tests
configuration.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
return;
}
ReplicatedPolicy haPolicy = (ReplicatedPolicy) server.getServer().getHAPolicy();
haPolicy.setCheckForLiveServer(true);
}
Aggregations