Search in sources :

Example 1 with BackupPolicy

use of org.apache.activemq.artemis.core.server.cluster.ha.BackupPolicy 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)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 BackupPolicy (org.apache.activemq.artemis.core.server.cluster.ha.BackupPolicy)1 ReplicatedPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy)1 Test (org.junit.Test)1