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