use of javax.jms.XASession in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAConsumer.
@Test
public void testXAConsumer() throws Exception {
Queue queue;
try (Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE)) {
queue = session.createQueue(queueName);
System.out.println("Queue:" + queue);
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
TextMessage msg = session.createTextMessage("test" + i);
msg.setStringProperty("myobj", "test" + i);
producer.send(msg);
}
session.close();
}
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
Xid xid = newXID();
XASession session = xaconnection.createXASession();
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageConsumer consumer = session.createConsumer(queue);
xaconnection.start();
for (int i = 0; i < 5; i++) {
TextMessage message = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("test" + i, message.getText());
}
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().rollback(xid);
consumer.close();
xaconnection.close();
}
try (Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
for (int i = 0; i < 10; i++) {
TextMessage message = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(message);
// Assert.assertEquals("test" + i, message.getText());
System.out.println("Message " + message.getText());
}
checkDuplicate(consumer);
System.out.println("Queue:" + queue);
session.close();
}
System.err.println("Done!!!");
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceRolledBackRemoved.
@Test
public void testXAResourceRolledBackRemoved() 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().rollback(xid);
}
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 ConnectionTest method testXAInstanceof.
@Test
public void testXAInstanceof() throws Exception {
conn = cf.createConnection();
assertFalse(conn instanceof XAConnection);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertFalse(sess instanceof XASession);
}
Aggregations