Search in sources :

Example 21 with XidImpl

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

the class BasicXaRecoveryTest method testMultipleTxSendWithCommitAndRollback.

public void testMultipleTxSendWithCommitAndRollback(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientMessage m5 = createTextMessage("m5");
    ClientMessage m6 = createTextMessage("m6");
    ClientMessage m7 = createTextMessage("m7");
    ClientMessage m8 = createTextMessage("m8");
    ClientSession clientSession2 = sessionFactory.createSession(true, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 2);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.commit(xid2, false);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}
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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 22 with XidImpl

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

the class BasicXaRecoveryTest method testBasicReceiveWithRollback.

public void testBasicReceiveWithRollback(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    BasicXaRecoveryTest.log.info("stopping and restarting");
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    BasicXaRecoveryTest.log.info("Restarted");
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(1, xids.length);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.start();
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}
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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 23 with XidImpl

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

the class BasicXaRecoveryTest method testMultipleTxReceiveWithRollback.

public void testMultipleTxReceiveWithRollback(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientMessage m5 = createTextMessage("m5");
    ClientMessage m6 = createTextMessage("m6");
    ClientMessage m7 = createTextMessage("m7");
    ClientMessage m8 = createTextMessage("m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    SimpleString anewtestq = new SimpleString("anewtestq");
    clientSession.createQueue(anewtestq, anewtestq, null, true);
    ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientProducer3.send(m5);
    clientProducer3.send(m6);
    clientProducer3.send(m7);
    clientProducer3.send(m8);
    clientSession2.close();
    clientSession2 = sessionFactory.createSession(true, false, false);
    ClientConsumer clientConsumer2 = clientSession2.createConsumer(anewtestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientSession2.start();
    ClientMessage m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer2.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession2 = null;
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.start();
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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)

Example 24 with XidImpl

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

the class BasicXaRecoveryTest method testMultipleTxReceiveWithCommit.

public void testMultipleTxReceiveWithCommit(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientMessage m5 = createTextMessage("m5");
    ClientMessage m6 = createTextMessage("m6");
    ClientMessage m7 = createTextMessage("m7");
    ClientMessage m8 = createTextMessage("m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    SimpleString anewtestq = new SimpleString("anewtestq");
    clientSession.createQueue(anewtestq, anewtestq, null, true);
    ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientProducer3.send(m5);
    clientProducer3.send(m6);
    clientProducer3.send(m7);
    clientProducer3.send(m8);
    clientSession2.close();
    clientSession2 = sessionFactory.createSession(true, false, false);
    ClientConsumer clientConsumer2 = clientSession2.createConsumer(anewtestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientSession2.start();
    ClientMessage m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer2.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession2 = null;
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.start();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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)

Example 25 with XidImpl

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

the class BasicXaRecoveryTest method testNonPersistent.

public void testNonPersistent(final boolean commit) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1", false);
    ClientMessage m2 = createTextMessage("m2", false);
    ClientMessage m3 = createTextMessage("m3", false);
    ClientMessage m4 = createTextMessage("m4", false);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m1);
    clientProducer.send(m2);
    clientProducer.send(m3);
    clientProducer.send(m4);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    stopAndRestartServer();
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 1);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    if (commit) {
        clientSession.commit(xid, false);
    } else {
        clientSession.rollback(xid);
    }
    xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 0);
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage)

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