Search in sources :

Example 36 with XidImpl

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

the class XidCodecSupport method decodeXid.

public static Xid decodeXid(final ActiveMQBuffer in) {
    int formatID = in.readInt();
    byte[] bq = new byte[in.readInt()];
    in.readBytes(bq);
    byte[] gtxid = new byte[in.readInt()];
    in.readBytes(gtxid);
    Xid xid = new XidImpl(bq, formatID, gtxid);
    return xid;
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl)

Example 37 with XidImpl

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

the class FailoverTest method testTimeoutOnFailoverTransactionCommit.

// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionCommit() throws Exception {
    locator.setCallTimeout(5000).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 CountDownLatch connectionFailed = new CountDownLatch(1);
    session.addFailureListener(new SessionFailureListener() {

        @Override
        public void beforeReconnect(ActiveMQException exception) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed.countDown();
        }
    });
    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.commit(xid, false);
    } catch (XAException e) {
        // there is still an edge condition that we must deal with
        Assert.assertTrue(connectionFailed.await(10, TimeUnit.SECONDS));
        session.commit(xid, false);
    }
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    for (int i = 0; i < 500; i++) {
        ClientMessage m = consumer.receive(1000);
        Assert.assertNotNull(m);
        Assert.assertEquals(i, m.getIntProperty("counter").intValue());
    }
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) XAException(javax.transaction.xa.XAException) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) Xid(javax.transaction.xa.Xid) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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 38 with XidImpl

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

the class FailoverTest method testXAMessagesConsumedSoRollbackOnEnd2.

@Test(timeout = 120000)
public void testXAMessagesConsumedSoRollbackOnEnd2() throws Exception {
    createSessionFactory();
    ClientSession session1 = createSessionAndQueue();
    ClientProducer producer = session1.createProducer(FailoverTestBase.ADDRESS);
    for (int i = 0; i < NUM_MESSAGES; i++) {
        // some are durable, some are not!
        producer.send(createMessage(session1, i, true));
    }
    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);
    crash(session2);
    receiveMessages(consumer);
    try {
        session2.end(xid, XAResource.TMSUCCESS);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
    }
    // Since the end was not accepted, the messages should be redelivered
    receiveMessages(consumer);
}
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 39 with XidImpl

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

the class FailoverTest method testXAMessagesSentSoRollbackOnCommit.

// This might happen if 1PC optimisation kicks in
@Test(timeout = 120000)
public void testXAMessagesSentSoRollbackOnCommit() 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);
    session.end(xid, XAResource.TMSUCCESS);
    crash(session);
    try {
        session.commit(xid, false);
        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)

Example 40 with XidImpl

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

the class FailoverTest method testXAMessagesNotSentSoNoRollbackOnCommit.

@Test(timeout = 120000)
public void testXAMessagesNotSentSoNoRollbackOnCommit() 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);
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    session.commit(xid, false);
    crash(session);
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    Xid xid2 = new XidImpl("tfytftyf".getBytes(), 54654, "iohiuohiuhgiu".getBytes());
    session.start(xid2, XAResource.TMNOFLAGS);
    receiveDurableMessages(consumer);
    session.end(xid2, XAResource.TMSUCCESS);
    session.prepare(xid2);
    session.commit(xid2, false);
}
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) 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