Search in sources :

Example 6 with XidImpl

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

the class SimpleOpenWireTest method testXAResourceCommitSuspendedNotRemoved.

@Test
public void testXAResourceCommitSuspendedNotRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        session.getXAResource().end(xid, XAResource.TMSUSPEND);
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        // amq5.x doesn't pass suspend flags to broker,
        // directly suspend the tx
        transaction.suspend();
        session.getXAResource().commit(xid, true);
    } catch (XAException ex) {
    // ignore
    } finally {
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        assertNotNull(transaction);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 7 with XidImpl

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

the class SimpleOpenWireTest method testXAResourceCommittedRemoved.

@Test
public void testXAResourceCommittedRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("xa message"));
        session.getXAResource().end(xid, XAResource.TMSUCCESS);
        session.getXAResource().commit(xid, true);
    }
    XidImpl xid1 = new XidImpl(xid);
    Transaction transaction = server.getResourceManager().getTransaction(xid1);
    assertNull(transaction);
}
Also used : Xid(javax.transaction.xa.Xid) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 8 with XidImpl

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

the class SimpleOpenWireTest method testXAResourceRolledBackSuspendedNotRemoved.

@Test
public void testXAResourceRolledBackSuspendedNotRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        session.getXAResource().end(xid, XAResource.TMSUSPEND);
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        // directly suspend the tx
        transaction.suspend();
        session.getXAResource().rollback(xid);
    } catch (XAException ex) {
    // ignore
    } finally {
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        assertNotNull(transaction);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 9 with XidImpl

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

the class FailoverTest method testXAMessagesConsumedSoRollbackOnEnd.

@Test(timeout = 120000)
public void testXAMessagesConsumedSoRollbackOnEnd() 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);
    crash(session2);
    try {
        session2.end(xid, XAResource.TMSUCCESS);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
        Assert.assertEquals(XAException.XAER_RMFAIL, e.errorCode);
    }
}
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 10 with XidImpl

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

the class FailoverTest method testXAMessagesSentSoRollbackOnEnd2.

@Test(timeout = 120000)
public // start a tx but sending messages after crash
void testXAMessagesSentSoRollbackOnEnd2() 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);
    crash(session);
    // sendMessagesSomeDurable(session, producer);
    producer.send(createMessage(session, 1, true));
    try {
        session.end(xid, XAResource.TMSUCCESS);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
    // Assert.assertEquals(XAException.XAER_NOTA, 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)

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