use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.
the class AsynchronousFailoverTest method doTestNonTransactional.
private void doTestNonTransactional(final TestRunner runner) throws Exception {
while (!runner.isFailed()) {
AsynchronousFailoverTest.log.info("looping");
ClientSession session = sf.createSession(true, true, 0);
listener = new CountDownSessionFailureListener(session);
session.addFailureListener(listener);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
boolean retry = false;
do {
try {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("message" + i);
message.putIntProperty("counter", i);
addPayload(message);
producer.send(message);
retry = false;
} catch (ActiveMQUnBlockedException ube) {
AsynchronousFailoverTest.log.info("exception when sending message with counter " + i);
ube.printStackTrace();
retry = true;
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
} while (retry);
}
// create the consumer with retry if failover occurs during createConsumer call
ClientConsumer consumer = null;
boolean retry = false;
do {
try {
consumer = session.createConsumer(FailoverTestBase.ADDRESS);
retry = false;
} catch (ActiveMQUnBlockedException ube) {
AsynchronousFailoverTest.log.info("exception when creating consumer");
retry = true;
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
} while (retry);
session.start();
List<Integer> counts = new ArrayList<>(1000);
int lastCount = -1;
boolean counterGap = false;
while (true) {
ClientMessage message = consumer.receive(500);
if (message == null) {
break;
}
// messages must remain ordered but there could be a "jump" if messages
// are missing or duplicated
int count = message.getIntProperty("counter");
counts.add(count);
if (count != lastCount + 1) {
if (counterGap) {
Assert.fail("got another counter gap at " + count + ": " + counts);
} else {
if (lastCount != -1) {
AsynchronousFailoverTest.log.info("got first counter gap at " + count);
counterGap = true;
}
}
}
lastCount = count;
message.acknowledge();
}
session.close();
this.listener = null;
}
}
use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.
the class FailBackAutoTest method testAutoFailbackThenFailover.
@Test
public void testAutoFailbackThenFailover() throws Exception {
createSessionFactory();
ClientSession session = sendAndConsume(sf, true);
CountDownSessionFailureListener listener = new CountDownSessionFailureListener(session);
session.addFailureListener(listener);
IntegrationTestLogger.LOGGER.info("Crashing live server...");
liveServer.crash(session);
ClientProducer producer = session.createProducer(ADDRESS);
ClientMessage message = session.createMessage(true);
setBody(0, message);
producer.send(message);
session.removeFailureListener(listener);
listener = new CountDownSessionFailureListener(session);
session.addFailureListener(listener);
log.info("restarting live node now");
liveServer.start();
assertTrue("expected a session failure 1", listener.getLatch().await(5, TimeUnit.SECONDS));
message = session.createMessage(true);
setBody(1, message);
producer.send(message);
session.removeFailureListener(listener);
listener = new CountDownSessionFailureListener(session);
session.addFailureListener(listener);
waitForBackup(sf, 10);
IntegrationTestLogger.LOGGER.info("Crashing live server again...");
liveServer.crash();
assertTrue("expected a session failure 2", listener.getLatch().await(5, TimeUnit.SECONDS));
session.close();
wrapUpSessionFactory();
}
use of org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener in project activemq-artemis by apache.
the class FailoverTest method testLiveAndBackupLiveComesBackNewFactory.
@Test(timeout = 120000)
public void testLiveAndBackupLiveComesBackNewFactory() 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();
// 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);
session.close();
sf.close();
createClientSessionFactory();
session = createSession(sf);
ClientConsumer cc = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
Assert.assertEquals("message0", cm.getBodyBuffer().readString());
}
Aggregations