[jboss-cvs] JBoss Messaging SVN: r7909 - in branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734: tests/src/org/jboss/test/messaging/jms and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 25 11:57:31 EST 2009
Author: jbertram at redhat.com
Date: 2009-11-25 11:57:31 -0500 (Wed, 25 Nov 2009)
New Revision: 7909
Modified:
branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/src/main/org/jboss/jms/tx/ResourceManager.java
branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
Log:
[JBPAPP-3144]
Modified: branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/src/main/org/jboss/jms/tx/ResourceManager.java 2009-11-25 04:49:05 UTC (rev 7908)
+++ branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/src/main/org/jboss/jms/tx/ResourceManager.java 2009-11-25 16:57:31 UTC (rev 7909)
@@ -387,7 +387,7 @@
request.xid = xid;
- sendTransactionXA(request, connection);
+ sendTransactionXA(request, connection);
}
if (tx != null)
@@ -681,12 +681,27 @@
//the server has been fixed.
//(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);
+ if (request.getRequestType() == TransactionRequest.TWO_PHASE_PREPARE_REQUEST)
+ {
+
+ 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);
+ }
+ }
+ else
+ {
+ throw new MessagingXAException(XAException.XA_RETRY, "A Throwable was caught in sending the transaction", t);
+ }
}
}
Modified: branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2009-11-25 04:49:05 UTC (rev 7908)
+++ branches/Branch_JBossMessaging_1_4_0_SP3_CP08.patch01_JBMESSAGING_1734/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2009-11-25 16:57:31 UTC (rev 7909)
@@ -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