[jboss-cvs] JBoss Messaging SVN: r7810 - in branches/Branch_1_4: src/main/org/jboss/jms/tx and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 17 03:11:32 EDT 2009


Author: gaohoward
Date: 2009-09-17 03:11:30 -0400 (Thu, 17 Sep 2009)
New Revision: 7810

Modified:
   branches/Branch_1_4/docs/userguide/en/modules/introduction.xml
   branches/Branch_1_4/src/main/org/jboss/jms/tx/ResourceManager.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
Log:
JBMESSAGING-1734


Modified: branches/Branch_1_4/docs/userguide/en/modules/introduction.xml
===================================================================
--- branches/Branch_1_4/docs/userguide/en/modules/introduction.xml	2009-09-16 14:31:44 UTC (rev 7809)
+++ branches/Branch_1_4/docs/userguide/en/modules/introduction.xml	2009-09-17 07:11:30 UTC (rev 7810)
@@ -210,6 +210,13 @@
         will try to extract the native byte[] correlation ID from the foreign message headers. If set to false, it will use the normal string type JMSCorrelationID. If this system property is absent or
         is given some value other than 'true' and 'false', it will defaults to 'true'.</para>
       </section>
+
+      <section id="properties.retainOldxabehaviour">
+      <title>retain.oldxabehaviour</title>
+
+        <para>This system property controls what kind of exception a JMS XAResource throws when the prepare is called after the connection is broken. If this property is not defined, an XAException with XA_RBCOMMFAIL error code will be thrown. If this propertie is defined, an XAException with XA_RETRY error code will be thrown instead. JBM by default doesn't define this property.</para>
+      </section>
+
   </section>
 
 </chapter>

Modified: branches/Branch_1_4/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/tx/ResourceManager.java	2009-09-16 14:31:44 UTC (rev 7809)
+++ branches/Branch_1_4/src/main/org/jboss/jms/tx/ResourceManager.java	2009-09-17 07:11:30 UTC (rev 7810)
@@ -682,11 +682,19 @@
          
          //(In some cases it will not be possible to fix so the user will have to manually resolve the tx)
          
-         //Therefore we throw XA_RETRY
-         //Note we DO NOT throw XAER_RMFAIL or XAER_RMERR since both if these will cause the Arjuna
-         //tx mgr NOT to retry and the transaction will have to be resolve manually.
-         
-         throw new MessagingXAException(XAException.XA_RETRY, "A Throwable was caught in sending the transaction", t);
+         String oldBehaviour = System.getProperty("retain.oldxabehaviour");
+         if (oldBehaviour != null)
+         {
+            //Therefore we throw XA_RETRY
+            //Note we DO NOT throw XAER_RMFAIL or XAER_RMERR since both if these will cause the Arjuna
+            //tx mgr NOT to retry and the transaction will have to be resolve manually.
+            throw new MessagingXAException(XAException.XA_RETRY, "A Throwable was caught in sending the transaction", t);
+         }
+         else
+         {
+            //https://jira.jboss.org/jira/browse/JBMESSAGING-1734
+            throw new MessagingXAException(XAException.XA_RBCOMMFAIL, "A Throwable was caught in sending the transaction", t);
+         }
       }
    }
    

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2009-09-16 14:31:44 UTC (rev 7809)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2009-09-17 07:11:30 UTC (rev 7810)
@@ -22,6 +22,7 @@
 package org.jboss.test.messaging.jms;
 
 import javax.jms.*;
+import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
@@ -3759,5 +3760,300 @@
       }
    }
 
+   //https://jira.jboss.org/jira/browse/JBMESSAGING-1734
+   public void testTxPrepareAfterConnFailure_XACompliant() throws Exception
+   {
+      log.trace("starting testTxPrepareAfterConnFailure_XACompliant");
+
+      Connection conn1 = null;
+
+      XAConnection conn2 = null;
+
+      XAConnection conn3 = null;
+
+      try
+      {
+         //First send a message to the queue
+         conn1 = cf.createConnection();
+
+         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer prod = sess1.createProducer(queue4);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         TextMessage tm1 = sess1.createTextMessage("tm1");
+
+         prod.send(tm1);
+
+         conn2 = cf.createXAConnection();
+
+         XASession sess2 = conn2.createXASession();
+
+         XAResource res1 = sess2.getXAResource();
+
+         //Pretend to be a transaction manager by interacting through the XAResources
+         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+
+         res1.start(xid1, XAResource.TMNOFLAGS);
+
+         MessageConsumer cons = sess2.createConsumer(queue4);
+
+         conn2.start();
+
+         //Consume the message
+
+         TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+         assertNotNull(rm1);
+
+         assertEquals(tm1.getText(), rm1.getText());
+
+         res1.end(xid1, XAResource.TMSUCCESS);
+
+
+         conn1.close();
+
+         conn2.close();
+
+         conn1 = null;
+
+         conn2 = null;
+
+         // Now "crash" the server
+         ServerManagement.stopServerPeer();
+         
+         //prepare the tx
+         try
+         {
+            res1.prepare(xid1);
+            fail("Expected exception not received.");
+         }
+         catch (XAException e)
+         {
+            log.info("Got exception in prepare: " + e.errorCode);
+            assertEquals(XAException.XA_RBCOMMFAIL, e.errorCode);
+         }
+
+         //now start
+         ServerManagement.startServerPeer();
+
+         deployAndLookupAdministeredObjects();
+
+         //Now recover
+
+         conn3 = cf.createXAConnection();
+
+         XASession sess3 = conn3.createXASession();
+
+         XAResource res3 = sess3.getXAResource();
+
+         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
+         assertEquals(0, xids.length);
+
+         //The message should be acknowldged
+         conn3.close();
+
+         conn1 = cf.createConnection();
+
+         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer cons1 = sess1.createConsumer(queue4);
+
+         conn1.start();
+
+         Message m = cons1.receive(1000);
+
+         assertNull(m);
+
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn2 != null)
+         {
+            try
+            {
+               conn2.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn3 != null)
+         {
+            try
+            {
+               conn3.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+      }
+   }
+
+   //https://jira.jboss.org/jira/browse/JBMESSAGING-1734
+   public void testTxPrepareAfterConnFailure_XACompliant2() throws Exception
+   {
+      log.trace("starting testTxPrepareAfterConnFailure_XACompliant");
+
+      Connection conn1 = null;
+
+      XAConnection conn2 = null;
+
+      XAConnection conn3 = null;
+
+      System.setProperty("retain.oldxabehaviour", "");
+      
+      try
+      {
+         //First send a message to the queue
+         conn1 = cf.createConnection();
+
+         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer prod = sess1.createProducer(queue4);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         TextMessage tm1 = sess1.createTextMessage("tm1");
+
+         prod.send(tm1);
+
+         conn2 = cf.createXAConnection();
+
+         XASession sess2 = conn2.createXASession();
+
+         XAResource res1 = sess2.getXAResource();
+
+         //Pretend to be a transaction manager by interacting through the XAResources
+         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+
+         res1.start(xid1, XAResource.TMNOFLAGS);
+
+         MessageConsumer cons = sess2.createConsumer(queue4);
+
+         conn2.start();
+
+         //Consume the message
+
+         TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+         assertNotNull(rm1);
+
+         assertEquals(tm1.getText(), rm1.getText());
+
+         res1.end(xid1, XAResource.TMSUCCESS);
+
+
+         conn1.close();
+
+         conn2.close();
+
+         conn1 = null;
+
+         conn2 = null;
+
+         // Now "crash" the server
+         ServerManagement.stopServerPeer();
+         
+         //prepare the tx
+         try
+         {
+            res1.prepare(xid1);
+            fail("Expected exception not received.");
+         }
+         catch (XAException e)
+         {
+            log.info("Got exception in prepare: " + e.errorCode);
+            assertEquals(XAException.XA_RETRY, e.errorCode);
+         }
+
+         //now start
+         ServerManagement.startServerPeer();
+
+         deployAndLookupAdministeredObjects();
+
+         //Now recover
+
+         conn3 = cf.createXAConnection();
+
+         XASession sess3 = conn3.createXASession();
+
+         XAResource res3 = sess3.getXAResource();
+
+         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
+         assertEquals(0, xids.length);
+
+         //The message should be acknowldged
+         conn3.close();
+
+         conn1 = cf.createConnection();
+
+         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer cons1 = sess1.createConsumer(queue4);
+
+         conn1.start();
+
+         Message m = cons1.receive(1000);
+
+         assertNull(m);
+
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn2 != null)
+         {
+            try
+            {
+               conn2.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn3 != null)
+         {
+            try
+            {
+               conn3.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+         
+         System.clearProperty("retain.oldxabehaviour");
+
+      }
+   }
+
 }
 




More information about the jboss-cvs-commits mailing list