Search in sources :

Example 11 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class FailoverTest method testXAMessagesConsumedSoRollbackOnCommit.

// 1PC optimisation
@Test(timeout = 120000)
public void testXAMessagesConsumedSoRollbackOnCommit() throws Exception {
    createSessionFactory();
    ClientSession session1 = createSessionAndQueue();
    ClientProducer producer = session1.createProducer(FailoverTestBase.ADDRESS);
    sendMessagesSomeDurable(session1, producer);
    session1.commit();
    ClientSession session2 = createSession(sf, true, false, false);
    ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
    session2.start();
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session2.start(xid, XAResource.TMNOFLAGS);
    receiveMessages(consumer);
    session2.end(xid, XAResource.TMSUCCESS);
    // session2.prepare(xid);
    crash(session2);
    try {
        session2.commit(xid, false);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
        // it should be rolled back
        Assert.assertEquals(XAException.XAER_NOTA, e.errorCode);
    }
    session1.close();
    session2.close();
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 12 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class FailoverTest method testXAMessagesSentSoRollbackOnEnd.

@Test(timeout = 120000)
public void testXAMessagesSentSoRollbackOnEnd() throws Exception {
    createSessionFactory();
    ClientSession session = createSession(sf, true, false, false);
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    session.start(xid, XAResource.TMNOFLAGS);
    sendMessagesSomeDurable(session, producer);
    crash(session);
    try {
        session.end(xid, XAResource.TMSUCCESS);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
        Assert.assertEquals(XAException.XAER_RMFAIL, e.errorCode);
    }
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    ClientMessage message = consumer.receiveImmediate();
    Assert.assertNull(message);
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) 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 13 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class FailoverTest method testTimeoutOnFailoverTransactionRollback.

// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionRollback() throws Exception {
    locator.setCallTimeout(2000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
    if (nodeManager instanceof InVMNodeManager) {
        ((InVMNodeManager) nodeManager).failoverPause = 5000L;
    }
    ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
    final ClientSession session = createSession(sf1, true, false, false);
    session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
    final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session.start(xid, XAResource.TMNOFLAGS);
    for (int i = 0; i < 500; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("counter", i);
        producer.send(message);
    }
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    crash(true, session);
    try {
        session.rollback(xid);
    } catch (XAException e) {
        try {
            // there is still an edge condition that we must deal with
            session.rollback(xid);
        } catch (Exception ignored) {
            log.trace(ignored.getMessage(), ignored);
        }
    }
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNull(m);
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) 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) ActiveMQTransactionOutcomeUnknownException(org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDuplicateIdException(org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) XAException(javax.transaction.xa.XAException) Test(org.junit.Test)

Example 14 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class FailoverTest method testXAMessagesSentSoRollbackOnPrepare.

@Test(timeout = 120000)
public void testXAMessagesSentSoRollbackOnPrepare() throws Exception {
    createSessionFactory();
    final ClientSession session = createSession(sf, true, false, false);
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
    final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    session.start(xid, XAResource.TMNOFLAGS);
    sendMessagesSomeDurable(session, producer);
    session.end(xid, XAResource.TMSUCCESS);
    crash(session);
    try {
        session.prepare(xid);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
        Assert.assertEquals(XAException.XAER_RMFAIL, e.errorCode);
    // XXXX  session.rollback();
    }
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    ClientMessage message = consumer.receiveImmediate();
    Assert.assertNull(message);
    producer.close();
    consumer.close();
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) 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 15 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class ScheduledMessageTest method scheduledDelivery.

// Private -------------------------------------------------------
private void scheduledDelivery(final boolean tx) throws Exception {
    ActiveMQTestBase.forceGC();
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(tx, false, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientConsumer consumer = session.createConsumer(atestq);
    session.start();
    if (tx) {
        session.start(xid, XAResource.TMNOFLAGS);
    }
    // Send one scheduled
    long now = System.currentTimeMillis();
    ClientMessage tm1 = createDurableMessage(session, "testScheduled1");
    tm1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 7000);
    producer.send(tm1);
    // First send some non scheduled messages
    ClientMessage tm2 = createDurableMessage(session, "testScheduled2");
    producer.send(tm2);
    ClientMessage tm3 = createDurableMessage(session, "testScheduled3");
    producer.send(tm3);
    ClientMessage tm4 = createDurableMessage(session, "testScheduled4");
    producer.send(tm4);
    // Now send some more scheduled messages
    ClientMessage tm5 = createDurableMessage(session, "testScheduled5");
    tm5.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 5000);
    producer.send(tm5);
    ClientMessage tm6 = createDurableMessage(session, "testScheduled6");
    tm6.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 4000);
    producer.send(tm6);
    ClientMessage tm7 = createDurableMessage(session, "testScheduled7");
    tm7.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 3000);
    producer.send(tm7);
    ClientMessage tm8 = createDurableMessage(session, "testScheduled8");
    tm8.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 6000);
    producer.send(tm8);
    // And one scheduled with a -ve number
    ClientMessage tm9 = createDurableMessage(session, "testScheduled9");
    tm9.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, -3);
    producer.send(tm9);
    if (tx) {
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.commit(xid, false);
    } else {
        session.commit();
    }
    if (tx) {
        session.start(xid, XAResource.TMNOFLAGS);
    }
    ClientMessage rm1 = consumer.receive(250);
    Assert.assertNotNull(rm1);
    Assert.assertEquals("testScheduled2", rm1.getBodyBuffer().readString());
    ClientMessage rm2 = consumer.receive(250);
    Assert.assertNotNull(rm2);
    Assert.assertEquals("testScheduled3", rm2.getBodyBuffer().readString());
    ClientMessage rm3 = consumer.receive(250);
    Assert.assertNotNull(rm3);
    Assert.assertEquals("testScheduled4", rm3.getBodyBuffer().readString());
    // Now the one with a scheduled with a -ve number
    ClientMessage rm5 = consumer.receive(250);
    Assert.assertNotNull(rm5);
    Assert.assertEquals("testScheduled9", rm5.getBodyBuffer().readString());
    // Now the scheduled
    ClientMessage rm6 = consumer.receive(3250);
    Assert.assertNotNull(rm6);
    Assert.assertEquals("testScheduled7", rm6.getBodyBuffer().readString());
    long now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 3000);
    ClientMessage rm7 = consumer.receive(1250);
    Assert.assertNotNull(rm7);
    Assert.assertEquals("testScheduled6", rm7.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 4000);
    ClientMessage rm8 = consumer.receive(1250);
    Assert.assertNotNull(rm8);
    Assert.assertEquals("testScheduled5", rm8.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 5000);
    ClientMessage rm9 = consumer.receive(1250);
    Assert.assertNotNull(rm9);
    Assert.assertEquals("testScheduled8", rm9.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 6000);
    ClientMessage rm10 = consumer.receive(1250);
    Assert.assertNotNull(rm10);
    Assert.assertEquals("testScheduled1", rm10.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 7000);
    if (tx) {
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.commit(xid, false);
    }
    session.close();
    sessionFactory.close();
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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)

Aggregations

XidImpl (org.apache.activemq.artemis.core.transaction.impl.XidImpl)59 Xid (javax.transaction.xa.Xid)57 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)44 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)40 Test (org.junit.Test)39 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 XAException (javax.transaction.xa.XAException)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 CountDownLatch (java.util.concurrent.CountDownLatch)10 Queue (javax.jms.Queue)6 XASession (javax.jms.XASession)6 XAConnection (javax.jms.XAConnection)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)5 MessageProducer (javax.jms.MessageProducer)4 TemporaryQueue (javax.jms.TemporaryQueue)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3