Search in sources :

Example 1 with ReplicatedPolicy

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();
    }
}
Also used : ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ReplicaPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy) ReplicatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Activation(org.apache.activemq.artemis.core.server.impl.Activation) SharedNothingLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation) SharedStoreLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation) SharedStoreBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation) LiveOnlyActivation(org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ColocatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ColocatedPolicy) Test(org.junit.Test)

Example 2 with ReplicatedPolicy

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();
    }
}
Also used : ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ReplicaPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy) ReplicatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Activation(org.apache.activemq.artemis.core.server.impl.Activation) SharedNothingLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation) SharedStoreLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation) SharedStoreBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation) LiveOnlyActivation(org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ColocatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ColocatedPolicy) Test(org.junit.Test)

Example 3 with ReplicatedPolicy

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();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ReplicatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) BackupPolicy(org.apache.activemq.artemis.core.server.cluster.ha.BackupPolicy) Test(org.junit.Test)

Example 4 with ReplicatedPolicy

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) {
        }
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ReplicatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) Test(org.junit.Test)

Example 5 with ReplicatedPolicy

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);
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ReplicatedPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Aggregations

ReplicatedPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy)6 Test (org.junit.Test)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)4 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)3 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)3 HAPolicy (org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy)3 Activation (org.apache.activemq.artemis.core.server.impl.Activation)3 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)3 ColocatedActivation (org.apache.activemq.artemis.core.server.impl.ColocatedActivation)3 LiveOnlyActivation (org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation)3 SharedNothingBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)3 SharedNothingLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation)3 SharedStoreBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation)3 SharedStoreLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ColocatedPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ColocatedPolicy)2 ReplicaPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1