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;
}
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));
}
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);
}
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);
}
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());
}
Aggregations