use of javax.jms.XASession 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 javax.jms.XASession 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 javax.jms.XASession in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXASimple.
@Test
public void testXASimple() throws Exception {
XAConnection connection = xaFactory.createXAConnection();
Collection<Session> sessions = new LinkedList<>();
for (int i = 0; i < 10; i++) {
XASession session = connection.createXASession();
session.getXAResource().start(newXID(), XAResource.TMNOFLAGS);
sessions.add(session);
}
connection.close();
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class SimpleOpenWireTest method testCommitCloseConsumeXA.
@Test
public void testCommitCloseConsumeXA() throws Exception {
Queue queue;
{
connection.start();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue(queueName);
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
TextMessage msg = session.createTextMessage("testXX" + i);
msg.setStringProperty("count", "str " + i);
producer.send(msg);
}
session.commit();
}
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
xaconnection.start();
XASession xasession = xaconnection.createXASession();
Xid xid = newXID();
xasession.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageConsumer consumer = xasession.createConsumer(queue);
for (int i = 0; i < 5; i++) {
TextMessage txt = (TextMessage) consumer.receive(5000);
Assert.assertEquals("testXX" + i, txt.getText());
}
consumer.close();
xasession.getXAResource().end(xid, XAResource.TMSUCCESS);
xasession.getXAResource().prepare(xid);
xasession.getXAResource().commit(xid, false);
xaconnection.close();
}
{
connection.start();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
try (MessageConsumer consumer = session.createConsumer(queue)) {
for (int i = 5; i < 10; i++) {
TextMessage txt = (TextMessage) consumer.receive(5000);
Assert.assertEquals("testXX" + i, txt.getText());
}
}
}
}
use of javax.jms.XASession 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);
}
}
Aggregations