[jboss-cvs] JBoss Messaging SVN: r1656 - branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 29 21:00:49 EST 2006
Author: juha at jboss.org
Date: 2006-11-29 21:00:47 -0500 (Wed, 29 Nov 2006)
New Revision: 1656
Modified:
branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java
Log:
no changes
Modified: branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java 2006-11-30 01:55:01 UTC (rev 1655)
+++ branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java 2006-11-30 02:00:47 UTC (rev 1656)
@@ -46,6 +46,7 @@
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
*
* $Id$
*/
@@ -83,13 +84,20 @@
initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
- if (!ServerManagement.isRemote()) tm = TransactionManagerLocator.getInstance().locate();
-
+ if (!ServerManagement.isRemote())
+ {
+ tm = TransactionManagerLocator.getInstance().locate();
+ }
+
ServerManagement.undeployQueue("Queue");
ServerManagement.deployQueue("Queue");
queue = (Destination)initialContext.lookup("/queue/Queue");
-
- if (!ServerManagement.isRemote()) suspendedTx = tm.suspend();
+
+
+ if (!ServerManagement.isRemote())
+ {
+ suspendedTx = tm.suspend();
+ }
}
public void tearDown() throws Exception
@@ -177,42 +185,44 @@
}
}
-
+
+
+
public void test2PCSendCommit() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
-
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+
+ MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
XAResource res2 = new DummyXAResource();
-
+
//To prevent 1PC optimization being used
res.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
prod.send(queue, m);
m = sess.createTextMessage("XATest2");
prod.send(queue, m);
-
+
tx.commit();
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -237,47 +247,47 @@
}
}
-
-
+
+
public void test2PCSendRollback1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
Connection conn2 = null;
try
{
conn = cf.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(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue, m);
m = sess.createTextMessage("XATest2");
prod.send(queue, m);
-
+
tx.rollback();
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue);
Message m2 = cons.receive(1000);
assertNull(m2);
-
+
}
finally
{
@@ -291,59 +301,59 @@
}
}
}
-
-
+
+
public void test2PCSendFailOnPrepare() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
try
{
conn = cf.createXAConnection();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-
+
//prevent 1Pc optimisation
res.setPreventJoining(true);
-
+
XAResource res2 = new DummyXAResource(true);
XAResource res3 = new DummyXAResource();
XAResource res4 = new DummyXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
tx.enlistResource(res3);
tx.enlistResource(res4);
-
+
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue, m);
m = sess.createTextMessage("XATest2");
prod.send(queue, m);
-
+
try
{
- tx.commit();
+ tx.commit();
}
catch (Exception e)
{
//We should expect this
}
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue);
Message m2 = cons.receive(1000);
assertNull(m2);
-
+
}
finally
{
@@ -357,47 +367,47 @@
}
}
}
-
+
public void test2PCSendRollback() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
try
{
conn = cf.createXAConnection();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-
+
//prevent 1Pc optimisation
res.setPreventJoining(true);
-
+
XAResource res2 = new DummyXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue, m);
m = sess.createTextMessage("XATest2");
prod.send(queue, m);
-
+
tx.rollback();
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue);
Message m2 = cons.receive(1000);
assertNull(m2);
-
+
}
finally
{
@@ -415,12 +425,12 @@
public void test2PCReceiveCommit1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -431,49 +441,49 @@
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
+
conn = cf.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(queue);
-
+
TextMessage m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
-
+
m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.commit();
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
Message m3 = cons.receive(1000);
-
+
assertNull(m3);
-
+
tm.commit();
-
+
}
finally
{
@@ -486,16 +496,16 @@
conn2.close();
}
}
-
+
}
-
+
public void test2PCReceiveCommit() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -506,50 +516,50 @@
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
+
conn = cf.createXAConnection();
conn.start();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
res.setPreventJoining(true);
-
+
XAResource res2 = new DummyXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
MessageConsumer cons = sess.createConsumer(queue);
-
+
TextMessage m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
-
+
m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.commit();
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
Message m3 = cons.receive(1000);
-
+
assertNull(m3);
-
+
tm.commit();
-
+
}
finally
{
@@ -562,18 +572,18 @@
conn2.close();
}
}
-
+
}
-
+
public void test2PCReceiveRollback1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -581,54 +591,54 @@
MessageProducer prod = sessProducer.createProducer(queue);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
-
+
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ 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(queue);
-
- TextMessage m2 = (TextMessage)cons.receive(1000);
+
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(1000);
+ m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.rollback();
-
+
//Message should be redelivered
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
- TextMessage m3 = (TextMessage)cons.receive(1000);
+
+ TextMessage m3 = (TextMessage)cons.receive(1000);
assertNotNull(m3);
assertEquals("XATest1", m3.getText());
- m3 = (TextMessage)cons.receive(1000);
+ m3 = (TextMessage)cons.receive(1000);
assertNotNull(m3);
assertEquals("XATest2", m3.getText());
-
+
assertTrue(m3.getJMSRedelivered());
-
+
tm.commit();
}
@@ -643,16 +653,16 @@
conn2.close();
}
}
-
+
}
-
+
public void test2PCReceiveRollback() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -660,55 +670,55 @@
MessageProducer prod = sessProducer.createProducer(queue);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
-
+
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
res.setPreventJoining(true);
-
+
XAResource res2 = new DummyXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
+
MessageConsumer cons = sess.createConsumer(queue);
-
- TextMessage m2 = (TextMessage)cons.receive(1000);
+
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(1000);
+ m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.rollback();
-
+
//Message should be redelivered
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
-
- TextMessage m3 = (TextMessage)cons.receive(1000);
+
+ TextMessage m3 = (TextMessage)cons.receive(1000);
assertNotNull(m3);
assertEquals("XATest1", m3.getText());
- m3 = (TextMessage)cons.receive(1000);
+ m3 = (TextMessage)cons.receive(1000);
assertNotNull(m3);
assertEquals("XATest2", m3.getText());
-
+
assertTrue(m3.getJMSRedelivered());
-
+
tm.commit();
}
@@ -723,41 +733,41 @@
conn2.close();
}
}
-
+
}
-
-
+
+
public void test1PCSendCommit() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
-
-
+
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
-
+
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
prod.send(queue, m);
m = sess.createTextMessage("XATest2");
prod.send(queue, m);
-
+
tx.commit();
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -782,20 +792,20 @@
}
}
-
-
+
+
public void test1PCSendRollback() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
try
{
conn = cf.createXAConnection();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
@@ -805,19 +815,19 @@
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
-
+ prod.send(queue, m);
+
tx.rollback();
-
+
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue);
Message m2 = cons.receive(1000);
assertNull(m2);
-
+
}
finally
{
@@ -835,10 +845,10 @@
public void test1PCReceiveCommit() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -849,44 +859,44 @@
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
+
conn = cf.createXAConnection();
conn.start();
-
+
tm.begin();
-
+
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
-
+
MessageConsumer cons = sess.createConsumer(queue);
-
+
TextMessage m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.commit();
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
-
+
Message m3 = cons.receive(1000);
-
+
assertNull(m3);
-
+
tm.commit();
-
+
}
finally
{
@@ -899,16 +909,16 @@
conn2.close();
}
}
-
+
}
-
+
public void test1PCReceiveRollback() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
conn2 = cf.createConnection();
@@ -918,53 +928,53 @@
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
MessageConsumer cons = sess.createConsumer(queue);
-
+
TextMessage m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
-
+
m2 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m2);
assertEquals("XATest2", m2.getText());
-
+
tx.rollback();
-
+
//Message should be redelivered
-
+
//New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
-
+
TextMessage m3 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m3);
assertEquals("XATest1", m3.getText());
-
+
m3 = (TextMessage)cons.receive(1000);
-
+
assertNotNull(m3);
assertEquals("XATest2", m3.getText());
-
+
assertTrue(m3.getJMSRedelivered());
-
+
tm.commit();
}
@@ -979,18 +989,18 @@
conn2.close();
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
try
{
//First send 2 messages
@@ -1001,50 +1011,50 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
XAResource res2 = sess2.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
//Receive the messages, one on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue);
TextMessage r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
cons1.close();
-
+
MessageConsumer cons2 = sess2.createConsumer(queue);
TextMessage r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
-
- //commit
+
+ //commit
tx.commit();
-
+
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r3 = (TextMessage)cons.receive(1000);
assertNull(r3);
-
-
+
+
}
finally
{
@@ -1057,16 +1067,16 @@
conn2.close();
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
try
{
//First send 2 messages
@@ -1077,13 +1087,13 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
@@ -1091,36 +1101,36 @@
MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
res1.setPreventJoining(true);
res2.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
//Receive the messages, one on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue);
TextMessage r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
cons1.close();
-
+
MessageConsumer cons2 = sess2.createConsumer(queue);
TextMessage r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
-
- //commit
+
+ //commit
tx.commit();
-
+
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r3 = (TextMessage)cons.receive(1000);
assertNull(r3);
-
+
}
finally
{
@@ -1133,19 +1143,19 @@
conn2.close();
}
}
-
+
}
-
-
+
+
public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
try
{
//First send 2 messages
@@ -1160,75 +1170,75 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
//Receive the messages, two on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue);
TextMessage r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish2", r1.getText());
-
+
cons1.close();
-
+
MessageConsumer cons2 = sess2.createConsumer(queue);
TextMessage r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish3", r2.getText());
-
+
r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish4", r2.getText());
-
- cons2.close();
-
- //rollback
-
+
+ cons2.close();
+
+ //rollback
+
tx.rollback();
-
+
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
- TextMessage r3 = (TextMessage)cons.receive(1000);
+
+ TextMessage r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish1", r3.getText());
-
- r3 = (TextMessage)cons.receive(1000);
+
+ r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish2", r3.getText());
- TextMessage r4 = (TextMessage)cons.receive(1000);
+ TextMessage r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish3", r4.getText());
- r4 = (TextMessage)cons.receive(1000);
+ r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish4", r4.getText());
-
+
}
finally
{
@@ -1241,13 +1251,13 @@
conn2.close();
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxRollbackAcknowledge() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
@@ -1265,13 +1275,13 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
@@ -1279,69 +1289,69 @@
MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
res1.setPreventJoining(true);
res2.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
//Receive the messages, two on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue);
TextMessage r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish2", r1.getText());
-
+
cons1.close();
-
+
MessageConsumer cons2 = sess2.createConsumer(queue);
TextMessage r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish3", r2.getText());
-
+
r2 = (TextMessage)cons2.receive(1000);
-
+
assertNotNull(r2);
assertEquals("jellyfish4", r2.getText());
-
- //rollback
-
+
+ //rollback
+
cons2.close();
-
+
tx.rollback();
-
+
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
//NOTE
//The order here is actually probably dependent on the transaction manager implementation
//In this case, rollback will be called on each session, but whether it is called first on res1
//or res2 determines the order the messages are put back in the queue
//This test assumes it is called in order res1, res2
-
- TextMessage r3 = (TextMessage)cons.receive(1000);
+
+ TextMessage r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish3", r3.getText());
-
- r3 = (TextMessage)cons.receive(1000);
+
+ r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish4", r3.getText());
- TextMessage r4 = (TextMessage)cons.receive(1000);
+ TextMessage r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish1", r4.getText());
-
- r4 = (TextMessage)cons.receive(1000);
+
+ r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish2", r4.getText());
-
+
}
finally
{
@@ -1354,13 +1364,13 @@
conn2.close();
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
Connection conn2 = null;
@@ -1378,47 +1388,47 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
-
-
+
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
DummyXAResource res2 = new DummyXAResource(true);
res1.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
MessageConsumer cons1 = sess1.createConsumer(queue);
TextMessage r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish2", r1.getText());
-
+
r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish3", r1.getText());
-
+
r1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(r1);
assertEquals("jellyfish4", r1.getText());
-
+
cons1.close();
-
-
-
+
+
+
//try and commit - and we're going to make the dummyxaresource throw an exception on commit,
//which should cause rollback to be called on the other resource
try
@@ -1429,28 +1439,28 @@
{
//We should expect this
}
-
+
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
- TextMessage r3 = (TextMessage)cons.receive(1000);
+
+ TextMessage r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish1", r3.getText());
-
- r3 = (TextMessage)cons.receive(1000);
+
+ r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish2", r3.getText());
-
- TextMessage r4 = (TextMessage)cons.receive(1000);
+
+ TextMessage r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish3", r4.getText());
-
- r4 = (TextMessage)cons.receive(1000);
+
+ r4 = (TextMessage)cons.receive(1000);
assertNotNull(r4);
assertEquals("jellyfish4", r4.getText());
-
+
}
finally
{
@@ -1463,59 +1473,59 @@
conn2.close();
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
XAResource res2 = sess2.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
// Send 2 messages - one from each session
-
+
MessageProducer prod1 = sess1.createProducer(queue);
MessageProducer prod2 = sess2.createProducer(queue);
-
+
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
-
+
//commit
tx.commit();
-
+
//Messages should be in queue
-
+
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r1 = (TextMessage)cons.receive(1000);
assertNotNull(r1);
assertEquals("echidna1", r1.getText());
-
+
TextMessage r2 = (TextMessage)cons.receive(1000);
assertNotNull(r2);
assertEquals("echidna2", r2.getText());
@@ -1533,27 +1543,27 @@
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxCommitSend() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
@@ -1561,33 +1571,33 @@
MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
res1.setPreventJoining(true);
res2.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
// Send 2 messages - one from each session
-
+
MessageProducer prod1 = sess1.createProducer(queue);
MessageProducer prod2 = sess2.createProducer(queue);
-
+
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
-
+
//commit
tx.commit();
-
+
//Messages should be in queue
-
+
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r1 = (TextMessage)cons.receive(1000);
assertNotNull(r1);
assertEquals("echidna1", r1.getText());
-
+
TextMessage r2 = (TextMessage)cons.receive(1000);
assertNotNull(r2);
assertEquals("echidna2", r2.getText());
@@ -1605,60 +1615,60 @@
}
}
-
+
}
-
-
+
+
public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
//Since both resources have some RM, TM will probably use 1PC optimization
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
XAResource res2 = sess2.getXAResource();
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
// Send 2 messages - one from each session
-
+
MessageProducer prod1 = sess1.createProducer(queue);
MessageProducer prod2 = sess2.createProducer(queue);
-
+
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
-
+
//rollback
tx.rollback();
-
+
//Messages should not be in queue
-
+
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r1 = (TextMessage)cons.receive(1000);
assertNull(r1);
-
+
}
finally
{
@@ -1672,25 +1682,25 @@
}
}
-
+
}
-
+
public void testMultipleSessionsOneTxRollbackSend() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
- conn.start();
-
+ conn.start();
+
tm.begin();
-
+
//Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
@@ -1698,33 +1708,33 @@
MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
res1.setPreventJoining(true);
res2.setPreventJoining(true);
-
+
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
-
+
// Send 2 messages - one from each session
-
+
MessageProducer prod1 = sess1.createProducer(queue);
MessageProducer prod2 = sess2.createProducer(queue);
-
+
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
-
+
//rollback
tx.rollback();
-
+
//Messages should not be in queue
-
+
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue);
conn2.start();
-
+
TextMessage r1 = (TextMessage)cons.receive(1000);
assertNull(r1);
-
+
}
finally
{
@@ -1738,20 +1748,20 @@
}
}
-
+
}
-
-
+
+
public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
- {
+ {
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -1760,43 +1770,43 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
+
conn = cf.createXAConnection();
//Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
-
+
conn.start();
MessageConsumer cons1 = sess1.createConsumer(queue);
-
+
tm.begin();
-
+
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
-
+
//Receive one message in one tx
-
+
TextMessage r1 = (TextMessage)cons1.receive(1000);
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
//suspend the tx
Transaction suspended = tm.suspend();
-
+
tm.begin();
-
+
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
-
+
//Receive 2nd message in a different tx
TextMessage r2 = (TextMessage)cons1.receive(1000);
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
-
+
//commit this transaction
tx2.commit();
-
+
//verify that no messages are available
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -1804,12 +1814,12 @@
MessageConsumer cons = sess.createConsumer(queue);
TextMessage r3 = (TextMessage)cons.receive(1000);
assertNull(r3);
-
+
//now resume the first tx and then commit it
tm.resume(suspended);
suspended.commit();
-
+
}
finally
{
@@ -1823,20 +1833,20 @@
}
}
-
+
}
-
-
+
+
public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
- {
+ {
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -1845,45 +1855,45 @@
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
+
conn = cf.createXAConnection();
//Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
-
+
conn.start();
MessageConsumer cons1 = sess1.createConsumer(queue);
-
+
tm.begin();
-
+
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
-
+
//Receive one message in one tx
-
+
TextMessage r1 = (TextMessage)cons1.receive(1000);
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
-
+
//suspend the tx
Transaction suspended = tm.suspend();
-
+
tm.begin();
-
+
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
-
+
//Receive 2nd message in a different tx
TextMessage r2 = (TextMessage)cons1.receive(1000);
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
-
+
cons1.close();
-
+
//rollback this transaction
tx2.rollback();
-
+
//verify that second message is available
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -1896,19 +1906,19 @@
assertEquals("jellyfish2", r3.getText());
r3 = (TextMessage)cons.receive(1000);
assertNull(r3);
-
-
+
+
//rollback the other tx
tm.resume(suspended);
suspended.rollback();
-
+
//Verify the first message is now available
r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("jellyfish1", r3.getText());
r3 = (TextMessage)cons.receive(1000);
assertNull(r3);
-
+
}
finally
{
@@ -1922,52 +1932,52 @@
}
}
-
+
}
-
+
public void testOneSessionTwoTransactionsCommitSend() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
//Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
-
+
MessageProducer prod1 = sess1.createProducer(queue);
-
+
tm.begin();
-
+
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
-
+
//Send a message
prod1.send(sess1.createTextMessage("kangaroo1"));
-
+
//suspend the tx
Transaction suspended = tm.suspend();
-
+
tm.begin();
-
+
//Send another message in another tx using the same session
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
-
+
//Send a message
prod1.send(sess1.createTextMessage("kangaroo2"));
-
+
//commit this transaction
tx2.commit();
-
+
//verify only kangaroo2 message is sent
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -1978,16 +1988,16 @@
assertEquals("kangaroo2", r1.getText());
TextMessage r2 = (TextMessage)cons.receive(1000);
assertNull(r2);
-
+
//now resume the first tx and then commit it
tm.resume(suspended);
suspended.commit();
-
+
//verify that the first text message is received
TextMessage r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("kangaroo1", r3.getText());
-
+
}
finally
{
@@ -2001,70 +2011,71 @@
}
}
-
+
}
-
-
+
+
public void testOneSessionTwoTransactionsRollbackSend() throws Exception
{
if (ServerManagement.isRemote()) return;
-
+
XAConnection conn = null;
-
+
Connection conn2 = null;
-
+
try
{
-
+
conn = cf.createXAConnection();
//Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
-
+
MessageProducer prod1 = sess1.createProducer(queue);
-
+
tm.begin();
-
+
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
-
+
//Send a message
prod1.send(sess1.createTextMessage("kangaroo1"));
-
+
//suspend the tx
Transaction suspended = tm.suspend();
-
+
tm.begin();
-
+
//Send another message in another tx using the same session
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
-
+
//Send a message
prod1.send(sess1.createTextMessage("kangaroo2"));
-
+
//rollback this transaction
tx2.rollback();
-
+
//verify no messages are sent
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
MessageConsumer cons = sess.createConsumer(queue);
TextMessage r1 = (TextMessage)cons.receive(1000);
+
assertNull(r1);
-
-
+
+
//now resume the first tx and then commit it
tm.resume(suspended);
suspended.commit();
-
+
//verify that the first text message is received
TextMessage r3 = (TextMessage)cons.receive(1000);
assertNotNull(r3);
assertEquals("kangaroo1", r3.getText());
-
+
}
finally
{
@@ -2078,9 +2089,9 @@
}
}
-
+
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
More information about the jboss-cvs-commits
mailing list