use of org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException in project activemq-artemis by apache.
the class BMFailoverTest method testFailoverOnReceiveCommit.
@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnReceiveCommit() throws Exception {
serverToStop = liveServer;
locator = getServerLocator().setFailoverOnInitialConnection(true);
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientSession sendSession = createSession(sf, true, true);
ClientProducer producer = addClientProducer(sendSession.createProducer(FailoverTestBase.ADDRESS));
sendMessages(sendSession, producer, 10);
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < 10; i++) {
ClientMessage m = consumer.receive(500);
assertNotNull(m);
m.acknowledge();
}
try {
session.commit();
fail("should have thrown an exception");
} catch (ActiveMQTransactionOutcomeUnknownException e) {
// pass
} catch (ActiveMQTransactionRolledBackException e1) {
// pass
}
Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable();
assertEquals(10, getMessageCount(bindable));
}
use of org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException in project activemq-artemis by apache.
the class FailoverTest method testCommitDidNotOccurUnblockedAndResend.
@Test(timeout = 120000)
public void testCommitDidNotOccurUnblockedAndResend() throws Exception {
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(300).setRetryInterval(100);
sf = createSessionFactoryAndWaitForTopology(locator, 2);
final ClientSession session = createSession(sf, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessages(session, producer, NUM_MESSAGES);
class Committer extends Thread {
@Override
public void run() {
Interceptor interceptor = new DelayInterceptor3();
try {
liveServer.addInterceptor(interceptor);
session.commit();
} catch (ActiveMQTransactionRolledBackException trbe) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQTransactionOutcomeUnknownException toue) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQException e) {
// ignore
}
}
volatile boolean failed = true;
}
Committer committer = new Committer();
committer.start();
crash(session);
committer.join();
Assert.assertFalse("commiter failed should be false", committer.failed);
session.close();
ClientSession session2 = createSession(sf, false, false);
producer = session2.createProducer(FailoverTestBase.ADDRESS);
// We now try and resend the messages since we get a transaction rolled back exception
sendMessages(session2, producer, NUM_MESSAGES);
session2.commit();
ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
session2.start();
receiveMessages(consumer);
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull("expecting null message", message);
}
use of org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException in project activemq-artemis by apache.
the class FailoverTest method testConsumeTransacted.
@Test(timeout = 120000)
public void testConsumeTransacted() throws Exception {
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 10;
sendMessages(session, producer, numMessages);
session.commit();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull("Just crashed? " + (i == 6) + " " + i, message);
message.acknowledge();
if (i == 5) {
crash(session);
}
}
try {
session.commit();
Assert.fail("session must have rolled back on failover");
} catch (ActiveMQTransactionRolledBackException trbe) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
consumer.close();
consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull("Expecting message #" + i, message);
message.acknowledge();
}
session.commit();
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException in project activemq-artemis by apache.
the class FailoverTest method testTransactedMessagesSentSoRollback.
@Test(timeout = 120000)
public void testTransactedMessagesSentSoRollback() throws Exception {
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessagesSomeDurable(session, producer);
crash(session);
Assert.assertTrue(session.isRollbackOnly());
try {
session.commit();
Assert.fail("Should throw exception");
} catch (ActiveMQTransactionRolledBackException trbe) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull("message should be null! Was: " + message, message);
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException in project activemq-artemis by apache.
the class FailoverTest method testTransactedMessagesSentSoRollbackAndContinueWork.
/**
* Test that once the transacted session has throw a TRANSACTION_ROLLED_BACK exception,
* it can be reused again
*/
@Test(timeout = 120000)
public void testTransactedMessagesSentSoRollbackAndContinueWork() throws Exception {
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessagesSomeDurable(session, producer);
crash(session);
Assert.assertTrue(session.isRollbackOnly());
try {
session.commit();
Assert.fail("Should throw exception");
} catch (ActiveMQTransactionRolledBackException trbe) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
ClientMessage message = session.createMessage(false);
int counter = RandomUtil.randomInt();
message.putIntProperty("counter", counter);
producer.send(message);
// session is working again
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
message = consumer.receive(1000);
Assert.assertNotNull("expecting a message", message);
Assert.assertEquals(counter, message.getIntProperty("counter").intValue());
session.close();
}
Aggregations