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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations