Search in sources :

Example 1 with ActiveMQTransactionRolledBackException

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));
}
Also used : ActiveMQTransactionOutcomeUnknownException(org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 2 with ActiveMQTransactionRolledBackException

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);
}
Also used : ActiveMQTransactionOutcomeUnknownException(org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) Test(org.junit.Test)

Example 3 with ActiveMQTransactionRolledBackException

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();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 4 with ActiveMQTransactionRolledBackException

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();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 5 with ActiveMQTransactionRolledBackException

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();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ActiveMQTransactionRolledBackException (org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException)8 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)8 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)7 Test (org.junit.Test)7 ActiveMQTransactionOutcomeUnknownException (org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException)4 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ArrayList (java.util.ArrayList)1 ActiveMQUnBlockedException (org.apache.activemq.artemis.api.core.ActiveMQUnBlockedException)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 CountDownSessionFailureListener (org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener)1 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)1