use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class BasicXaRecoveryTest method testBasicSendWithCommit.
public void testBasicSendWithCommit(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.start(xid, XAResource.TMNOFLAGS);
clientProducer.send(m1);
clientProducer.send(m2);
clientProducer.send(m3);
clientProducer.send(m4);
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
if (stopServer) {
stopAndRestartServer();
} else {
recreateClients();
}
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);
clientSession.commit(xid, 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");
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class BasicXaRecoveryTest method testMultipleTxSendWithRollback.
public void testMultipleTxSendWithRollback(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.rollback(xid2);
clientSession.start();
ClientMessage m = clientConsumer.receiveImmediate();
Assert.assertNull(m);
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class BasicXaRecoveryTest method testMultipleTxSameXidSendWithCommit.
public void testMultipleTxSameXidSendWithCommit(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");
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(xid, XAResource.TMNOFLAGS);
clientProducer2.send(m1);
clientProducer2.send(m2);
clientProducer2.send(m3);
clientProducer2.send(m4);
clientSession2.end(xid, XAResource.TMSUCCESS);
clientSession2.close();
clientSession.start(xid, XAResource.TMJOIN);
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, 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);
clientSession.commit(xid, 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.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
m = clientConsumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
m = clientConsumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
m = clientConsumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class XaTimeoutTest method testPreparedTransactionNotTimedOut.
@Test
public void testPreparedTransactionNotTimedOut() throws Exception {
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
ClientMessage m1 = createTextMessage(clientSession, "m1");
ClientMessage m2 = createTextMessage(clientSession, "m2");
ClientMessage m3 = createTextMessage(clientSession, "m3");
ClientMessage m4 = createTextMessage(clientSession, "m4");
ClientMessage m5 = createTextMessage(clientSession, "m5");
ClientMessage m6 = createTextMessage(clientSession, "m6");
ClientMessage m7 = createTextMessage(clientSession, "m7");
ClientMessage m8 = createTextMessage(clientSession, "m8");
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.setTransactionTimeout(2);
clientSession.start(xid, XAResource.TMNOFLAGS);
clientSession.start();
clientProducer.send(m5);
clientProducer.send(m6);
clientProducer.send(m7);
clientProducer.send(m8);
ClientMessage m = clientConsumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
m = clientConsumer.receive(500);
Assert.assertNotNull(m);
m.acknowledge();
Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
m = clientConsumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
m = clientConsumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
CountDownLatch latch = new CountDownLatch(1);
server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
Assert.assertFalse(latch.await(2600, TimeUnit.MILLISECONDS));
clientSession.commit(xid, false);
clientSession.setTransactionTimeout(0);
clientConsumer.close();
clientSession2 = sessionFactory.createSession(false, true, true);
ClientConsumer consumer = clientSession2.createConsumer(atestq);
clientSession2.start();
m = consumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
m = consumer.receive(500);
Assert.assertNotNull(m);
m.acknowledge();
Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
m = consumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
m = consumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
m = consumer.receiveImmediate();
Assert.assertNull(m);
clientSession2.close();
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class XaTimeoutTest method testChangingTimeoutGetsPickedUp.
@Test
public void testChangingTimeoutGetsPickedUp() throws Exception {
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
ClientMessage m1 = createTextMessage(clientSession, "m1");
ClientMessage m2 = createTextMessage(clientSession, "m2");
ClientMessage m3 = createTextMessage(clientSession, "m3");
ClientMessage m4 = createTextMessage(clientSession, "m4");
clientSession.start(xid, XAResource.TMNOFLAGS);
clientProducer.send(m1);
clientProducer.send(m2);
clientProducer.send(m3);
clientProducer.send(m4);
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.commit(xid, true);
clientSession.setTransactionTimeout(1);
clientSession.start(xid, XAResource.TMNOFLAGS);
CountDownLatch latch = new CountDownLatch(1);
server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
clientProducer.send(m1);
clientProducer.send(m2);
clientProducer.send(m3);
clientProducer.send(m4);
clientSession.end(xid, XAResource.TMSUCCESS);
Assert.assertTrue(latch.await(2600, TimeUnit.MILLISECONDS));
try {
clientSession.commit(xid, true);
} catch (XAException e) {
Assert.assertTrue(e.errorCode == XAException.XAER_NOTA);
}
clientSession.start();
ClientMessage m = clientConsumer.receiveImmediate();
Assert.assertNotNull(m);
m = clientConsumer.receiveImmediate();
Assert.assertNotNull(m);
m = clientConsumer.receiveImmediate();
Assert.assertNotNull(m);
m = clientConsumer.receiveImmediate();
Assert.assertNotNull(m);
m = clientConsumer.receiveImmediate();
Assert.assertNull(m);
}
Aggregations