Search in sources :

Example 1 with CountDownSessionFailureListener

use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.

the class SameProcessActiveMQServer method crash.

@Override
public CountDownLatch crash(boolean failover, boolean waitFailure, ClientSession... sessions) throws Exception {
    CountDownLatch latch = new CountDownLatch(sessions.length);
    CountDownSessionFailureListener[] listeners = new CountDownSessionFailureListener[sessions.length];
    for (int i = 0; i < sessions.length; i++) {
        listeners[i] = new CountDownSessionFailureListener(latch, sessions[i]);
        sessions[i].addFailureListener(listeners[i]);
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.flushExecutor();
    clusterManager.clear();
    Assert.assertTrue("server should be running!", server.isStarted());
    server.fail(failover);
    if (waitFailure) {
        // Wait to be informed of failure
        boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
        Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
    }
    return latch;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 2 with CountDownSessionFailureListener

use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.

the class SessionTest method testFailureListener.

@Test
public void testFailureListener() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = addClientSession(cf.createSession(false, true, true));
    CountDownSessionFailureListener listener = new CountDownSessionFailureListener(clientSession);
    clientSession.addFailureListener(listener);
    // Make sure failure listener is called if server is stopped without session being closed first
    server.stop();
    Assert.assertTrue(listener.getLatch().await(5, TimeUnit.SECONDS));
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) Test(org.junit.Test)

Example 3 with CountDownSessionFailureListener

use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.

the class FailoverTest method testBackupServerNotRemoved.

@Test(timeout = 120000)
public void testBackupServerNotRemoved() throws Exception {
    // HORNETQ-720 Disabling test for replicating backups.
    if (!(backupServer.getServer().getHAPolicy() instanceof SharedStoreSlavePolicy)) {
        return;
    }
    locator.setFailoverOnInitialConnection(true);
    createSessionFactory();
    ClientSession session = sendAndConsume(sf, true);
    CountDownSessionFailureListener listener = new CountDownSessionFailureListener(session);
    session.addFailureListener(listener);
    backupServer.stop();
    liveServer.crash();
    // To reload security or other settings that are read during startup
    beforeRestart(backupServer);
    backupServer.start();
    Assert.assertTrue("session failure listener", listener.getLatch().await(5, TimeUnit.SECONDS));
    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    ClientMessage message = session.createMessage(true);
    setBody(0, message);
    producer.send(message);
}
Also used : SharedStoreSlavePolicy(org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 4 with CountDownSessionFailureListener

use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.

the class FailoverTest method testLiveAndBackupLiveComesBack.

@Test(timeout = 120000)
public void testLiveAndBackupLiveComesBack() throws Exception {
    locator.setFailoverOnInitialConnection(true);
    createSessionFactory();
    final CountDownLatch latch = new CountDownLatch(1);
    ClientSession session = sendAndConsume(sf, true);
    session.addFailureListener(new CountDownSessionFailureListener(latch, session));
    backupServer.stop();
    liveServer.crash();
    beforeRestart(liveServer);
    // To reload security or other settings that are read during startup
    beforeRestart(liveServer);
    liveServer.start();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    ClientMessage message = session.createMessage(true);
    setBody(0, message);
    producer.send(message);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 5 with CountDownSessionFailureListener

use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.

the class FailBackManualTest method testNoAutoFailback.

@Test
public void testNoAutoFailback() throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true).setReconnectAttempts(15);
    ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
    ClientSession session = sendAndConsume(sf, true);
    CountDownSessionFailureListener listener = new CountDownSessionFailureListener(1, session);
    session.addFailureListener(listener);
    backupServer.stop();
    liveServer.crash();
    backupServer.start();
    assertTrue(listener.getLatch().await(5, TimeUnit.SECONDS));
    ClientProducer producer = session.createProducer(ADDRESS);
    ClientMessage message = session.createMessage(true);
    setBody(0, message);
    producer.send(message);
    session.removeFailureListener(listener);
    Thread t = new Thread(new ServerStarter(liveServer));
    t.start();
    waitForRemoteBackup(sf, 10, false, backupServer.getServer());
    assertTrue(backupServer.isStarted());
    backupServer.crash();
    waitForServerToStart(liveServer.getServer());
    assertTrue(liveServer.isStarted());
    sf.close();
    assertEquals(0, sf.numSessions());
    assertEquals(0, sf.numConnections());
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

CountDownSessionFailureListener (org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener)13 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)11 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 Test (org.junit.Test)9 CountDownLatch (java.util.concurrent.CountDownLatch)5 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)5 SharedStoreSlavePolicy (org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy)3 ArrayList (java.util.ArrayList)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ActiveMQUnBlockedException (org.apache.activemq.artemis.api.core.ActiveMQUnBlockedException)2 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 ActiveMQTransactionOutcomeUnknownException (org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException)1 ActiveMQTransactionRolledBackException (org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)1 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)1 ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)1 SharedStoreMasterPolicy (org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreMasterPolicy)1