use of javax.jms.XASession in project activemq-artemis by apache.
the class XATest method testMultipleSessionsOneTxRollbackSend.
@Test
public void testMultipleSessionsOneTxRollbackSend() throws Exception {
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
conn.start();
tm.begin();
// Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource();
XASession sess2 = conn.createXASession();
ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource();
res1.setForceNotSameRM(true);
res2.setForceNotSameRM(true);
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
// Send 2 messages - one from each session
MessageProducer prod1 = sess1.createProducer(queue1);
MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
// rollback
tm.rollback();
// Messages should not be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage) cons.receive(100);
Assert.assertNull(r1);
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class XATest method test2PCSendCommit1PCOptimization.
// Public --------------------------------------------------------
@Test
public void test2PCSendCommit1PCOptimization() throws Exception {
// Since both resources have same RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
prod.send(m);
m = sess.createTextMessage("XATest2");
prod.send(m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(1000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(1000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class SessionTest method testGetSession2.
@Test
public void testGetSession2() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
XAConnection conn = getXAConnectionFactory().createXAConnection();
XASession sess = conn.createXASession();
sess.getSession();
conn.close();
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class OutgoingConnectionTest method testSimpleMessageSendAndReceiveXA.
@Test
public void testSimpleMessageSendAndReceiveXA() throws Exception {
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection();
XASession s = queueConnection.createXASession();
XAResource resource = s.getXAResource();
resource.start(xid, XAResource.TMNOFLAGS);
Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
MessageProducer mp = s.createProducer(q);
MessageConsumer consumer = s.createConsumer(q);
Message message = s.createTextMessage("test");
mp.send(message);
queueConnection.start();
TextMessage textMessage = (TextMessage) consumer.receiveNoWait();
assertNull(textMessage);
resource.end(xid, XAResource.TMSUCCESS);
resource.commit(xid, true);
resource.start(xid, XAResource.TMNOFLAGS);
textMessage = (TextMessage) consumer.receiveNoWait();
resource.end(xid, XAResource.TMSUCCESS);
resource.commit(xid, true);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
// When I wrote this call, this method was doing an infinite loop.
// this is just to avoid such thing again
textMessage.getJMSDeliveryTime();
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class OutgoingConnectionTest method testOutgoingXAResourceWrapper.
@Test
public void testOutgoingXAResourceWrapper() throws Exception {
XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection();
XASession s = queueConnection.createXASession();
XAResource resource = s.getXAResource();
assertTrue(resource instanceof ActiveMQXAResourceWrapper);
ActiveMQXAResourceWrapperImpl xaResourceWrapper = (ActiveMQXAResourceWrapperImpl) resource;
assertTrue(xaResourceWrapper.getJndiName().equals("java://jmsXA NodeId:" + server.getNodeID()));
assertTrue(xaResourceWrapper.getProductVersion().equals(VersionLoader.getVersion().getFullVersion()));
assertTrue(xaResourceWrapper.getProductName().equals(ActiveMQResourceAdapter.PRODUCT_NAME));
}
Aggregations