use of javax.jms.XAConnection in project activemq-artemis by apache.
the class XATest method test2PCReceiveRollback1PCOptimization.
@Test
public void test2PCReceiveRollback1PCOptimization() throws Exception {
// Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
conn = xacf.createXAConnection();
conn.start();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.rollback();
// Message should be redelivered
// New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
TextMessage m3 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m3);
Assert.assertEquals("XATest1", m3.getText());
m3 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m3);
Assert.assertEquals("XATest2", m3.getText());
Assert.assertTrue(m3.getJMSRedelivered());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class ConnectionFactoryTest method testConnectionTypes.
@Test
public void testConnectionTypes() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
Connection genericConnection = null;
XAConnection xaConnection = null;
QueueConnection queueConnection = null;
TopicConnection topicConnection = null;
XAQueueConnection xaQueueConnection = null;
XATopicConnection xaTopicConnection = null;
ConnectionFactory genericFactory = (ConnectionFactory) ic.lookup("/ConnectionFactory");
genericConnection = genericFactory.createConnection();
assertConnectionType(genericConnection, "generic");
XAConnectionFactory xaFactory = (XAConnectionFactory) ic.lookup("/CF_XA_TRUE");
xaConnection = xaFactory.createXAConnection();
assertConnectionType(xaConnection, "xa");
QueueConnectionFactory queueCF = (QueueConnectionFactory) ic.lookup("/CF_QUEUE");
queueConnection = queueCF.createQueueConnection();
assertConnectionType(queueConnection, "queue");
TopicConnectionFactory topicCF = (TopicConnectionFactory) ic.lookup("/CF_TOPIC");
topicConnection = topicCF.createTopicConnection();
assertConnectionType(topicConnection, "topic");
XAQueueConnectionFactory xaQueueCF = (XAQueueConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
xaQueueConnection = xaQueueCF.createXAQueueConnection();
assertConnectionType(xaQueueConnection, "xa-queue");
XATopicConnectionFactory xaTopicCF = (XATopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
xaTopicConnection = xaTopicCF.createXATopicConnection();
assertConnectionType(xaTopicConnection, "xa-topic");
genericConnection.close();
xaConnection.close();
queueConnection.close();
topicConnection.close();
xaQueueConnection.close();
xaTopicConnection.close();
undeployConnectionFactory("ConnectionFactory");
undeployConnectionFactory("CF_QUEUE_XA_TRUE");
undeployConnectionFactory("CF_XA_TRUE");
undeployConnectionFactory("CF_QUEUE");
undeployConnectionFactory("CF_TOPIC");
undeployConnectionFactory("CF_TOPIC_XA_TRUE");
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class SessionTest method testGetXAResource2.
@Test
public void testGetXAResource2() throws Exception {
XAConnection conn = getXAConnectionFactory().createXAConnection();
XASession sess = conn.createXASession();
sess.getXAResource();
conn.close();
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class OutgoingConnectionTest method testInexistentUserOnCreateConnection.
@Test
public void testInexistentUserOnCreateConnection() throws Exception {
resourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
resourceAdapter.start(ctx);
ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
mcf.setResourceAdapter(resourceAdapter);
ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
Connection conn = null;
try {
conn = qraConnectionFactory.createConnection("IDont", "Exist");
fail("Exception was expected");
} catch (JMSSecurityException expected) {
}
conn = qraConnectionFactory.createConnection("testuser", "testpassword");
conn.close();
try {
XAConnection xaconn = qraConnectionFactory.createXAConnection("IDont", "Exist");
fail("Exception was expected");
} catch (JMSSecurityException expected) {
}
XAConnection xaconn = qraConnectionFactory.createXAConnection("testuser", "testpassword");
xaconn.close();
try {
TopicConnection topicconn = qraConnectionFactory.createTopicConnection("IDont", "Exist");
fail("Exception was expected");
} catch (JMSSecurityException expected) {
}
TopicConnection topicconn = qraConnectionFactory.createTopicConnection("testuser", "testpassword");
topicconn.close();
try {
QueueConnection queueconn = qraConnectionFactory.createQueueConnection("IDont", "Exist");
fail("Exception was expected");
} catch (JMSSecurityException expected) {
}
QueueConnection queueconn = qraConnectionFactory.createQueueConnection("testuser", "testpassword");
queueconn.close();
mcf.stop();
}
use of javax.jms.XAConnection in project tomee by apache.
the class TomEEManagedConnectionProxy method createXASession.
@Override
public XASession createXASession() throws JMSException {
XASession session = ((XAConnection) connection.getPhysicalConnection()).createXASession();
enlistInTransactionIfNeeded(session);
return session;
}
Aggregations