[jboss-cvs] JBoss Messaging SVN: r1677 - 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
Fri Dec 1 21:23:04 EST 2006


Author: juha at jboss.org
Date: 2006-12-01 21:23:02 -0500 (Fri, 01 Dec 2006)
New Revision: 1677

Modified:
   branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java
Log:
correct transaction handling and run against JBossTS. Tx termination should be invoked on the TM, instead of the TX, to ensure correct thread disassociation

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-12-02 00:04:52 UTC (rev 1676)
+++ branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XATest.java	2006-12-02 02:23:02 UTC (rev 1677)
@@ -42,7 +42,7 @@
 import org.jboss.jms.tx.MessagingXAResource;
 import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.TxUtils;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -86,7 +86,7 @@
             
       if (!ServerManagement.isRemote())
       {
-         tm = TransactionManagerLocator.getInstance().locate();
+         tm = org.jboss.test.messaging.util.TransactionManagerLocator.getInstance().locate();
       }
 
       ServerManagement.undeployQueue("Queue");
@@ -106,11 +106,17 @@
       
       if (!ServerManagement.isRemote())
       {
-         if (tm.getTransaction() != null)
+         if (TxUtils.isUncommitted(tm))
          {
             //roll it back
             tm.rollback();
          }
+         if (tm.getTransaction() != null)
+         {
+            Transaction tx = tm.suspend();
+            if (tx != null)
+               log.warn("Transaction still associated with thread " + tx + " at status " + TxUtils.getStatusAsString(tx.getStatus()));
+         }
       }
       
       if (suspendedTx != null)
@@ -159,7 +165,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
          
-         tx.commit();
+         tm.commit();
          
          conn2 = cf.createConnection();
          conn2.start();
@@ -221,7 +227,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
 
-         tx.commit();
+         tm.commit();
 
          conn2 = cf.createConnection();
          conn2.start();
@@ -279,7 +285,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
 
-         tx.rollback();
+         tm.rollback();
 
          conn2 = cf.createConnection();
          conn2.start();
@@ -340,7 +346,9 @@
 
          try
          {
-            tx.commit();
+            tm.commit();
+
+            fail("should not get here");
          }
          catch (Exception e)
          {
@@ -399,7 +407,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
 
-         tx.rollback();
+         tm.rollback();
 
          conn2 = cf.createConnection();
          conn2.start();
@@ -469,7 +477,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.commit();
+         tm.commit();
 
          //New tx
          tm.begin();
@@ -545,7 +553,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.commit();
+         tm.commit();
 
          //New tx
          tm.begin();
@@ -620,7 +628,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.rollback();
+         tm.rollback();
 
          //Message should be redelivered
 
@@ -700,7 +708,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.rollback();
+         tm.rollback();
 
          //Message should be redelivered
 
@@ -766,7 +774,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
 
-         tx.commit();
+         tm.commit();
 
          conn2 = cf.createConnection();
          conn2.start();
@@ -819,7 +827,7 @@
          m = sess.createTextMessage("XATest2");
          prod.send(queue, m);
 
-         tx.rollback();
+         tm.rollback();
 
          conn2 = cf.createConnection();
          conn2.start();
@@ -883,7 +891,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.commit();
+         tm.commit();
 
          //New tx
          tm.begin();
@@ -954,7 +962,7 @@
          assertNotNull(m2);
          assertEquals("XATest2", m2.getText());
 
-         tx.rollback();
+         tm.rollback();
 
          //Message should be redelivered
 
@@ -1044,7 +1052,7 @@
          assertEquals("jellyfish2", r2.getText());
 
          //commit
-         tx.commit();
+         tm.commit();
 
          Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageConsumer cons = sess.createConsumer(queue);
@@ -1122,7 +1130,7 @@
          assertEquals("jellyfish2", r2.getText());
 
          //commit
-         tx.commit();
+         tm.commit();
 
          Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageConsumer cons = sess.createConsumer(queue);
@@ -1216,7 +1224,7 @@
 
          //rollback
 
-         tx.rollback();
+         tm.rollback();
 
          Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageConsumer cons = sess.createConsumer(queue);
@@ -1323,7 +1331,7 @@
 
          cons2.close();
 
-         tx.rollback();
+         tm.rollback();
 
          Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageConsumer cons = sess.createConsumer(queue);
@@ -1433,7 +1441,8 @@
          //which should cause rollback to be called on the other resource
          try
          {
-            tx.commit();
+            tm.commit();
+            fail("should not get here");
          }
          catch (Exception e)
          {
@@ -1513,7 +1522,7 @@
          prod2.send(sess2.createTextMessage("echidna2"));
 
          //commit
-         tx.commit();
+         tm.commit();
 
          //Messages should be in queue
 
@@ -1585,7 +1594,7 @@
          prod2.send(sess2.createTextMessage("echidna2"));
 
          //commit
-         tx.commit();
+         tm.commit();
 
          //Messages should be in queue
 
@@ -1656,7 +1665,7 @@
          prod2.send(sess2.createTextMessage("echidna2"));
 
          //rollback
-         tx.rollback();
+         tm.rollback();
 
          //Messages should not be in queue
 
@@ -1722,7 +1731,7 @@
          prod2.send(sess2.createTextMessage("echidna2"));
 
          //rollback
-         tx.rollback();
+         tm.rollback();
 
          //Messages should not be in queue
 
@@ -1805,7 +1814,7 @@
          assertEquals("jellyfish2", r2.getText());
 
          //commit this transaction
-         tx2.commit();
+         tm.commit();
 
          //verify that no messages are available
          conn2 = cf.createConnection();
@@ -1817,7 +1826,7 @@
 
          //now resume the first tx and then commit it
          tm.resume(suspended);
-         suspended.commit();
+         tm.commit();
 
 
       }
@@ -1892,7 +1901,7 @@
          cons1.close();
 
          //rollback this transaction
-         tx2.rollback();
+         tm.rollback();
 
          //verify that second message is available
          conn2 = cf.createConnection();
@@ -1910,7 +1919,7 @@
 
          //rollback the other tx
          tm.resume(suspended);
-         suspended.rollback();
+         tm.rollback();
 
          //Verify the first message is now available
          r3 = (TextMessage)cons.receive(1000);
@@ -1976,7 +1985,7 @@
          prod1.send(sess1.createTextMessage("kangaroo2"));
 
          //commit this transaction
-         tx2.commit();
+         tm.commit();
 
          //verify only kangaroo2 message is sent
          conn2 = cf.createConnection();
@@ -1991,7 +2000,7 @@
 
          //now resume the first tx and then commit it
          tm.resume(suspended);
-         suspended.commit();
+         tm.commit();
 
          //verify that the first text message is received
          TextMessage r3 = (TextMessage)cons.receive(1000);
@@ -2055,7 +2064,7 @@
          prod1.send(sess1.createTextMessage("kangaroo2"));
 
          //rollback this transaction
-         tx2.rollback();
+         tm.rollback();
 
          //verify no messages are sent
          conn2 = cf.createConnection();
@@ -2069,7 +2078,7 @@
 
          //now resume the first tx and then commit it
          tm.resume(suspended);
-         suspended.commit();
+         tm.commit();
 
          //verify that the first text message is received
          TextMessage r3 = (TextMessage)cons.receive(1000);




More information about the jboss-cvs-commits mailing list