You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2009/06/28 16:49:37 UTC

svn commit: r789105 - in /db/derby/code/branches/10.5: ./ java/client/org/apache/derby/client/net/NetXAConnectionRequest.java java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java

Author: kahatlen
Date: Sun Jun 28 14:49:37 2009
New Revision: 789105

URL: http://svn.apache.org/viewvc?rev=789105&view=rev
Log:
DERBY-4232: XAResource.setTransactionTimeout() makes XAResource.start() fail with the client driver

Merged fix from trunk (revision 788674).

Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jun 28 14:49:37 2009
@@ -1 +1 @@
-/db/derby/code/trunk:772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788968
+/db/derby/code/trunk:772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788674,788968

Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java?rev=789105&r1=789104&r2=789105&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java Sun Jun 28 14:49:37 2009
@@ -73,11 +73,15 @@
         }
 
         writeXAFlags(CodePoint.XAFLAGS, xaFlags);
+
         // Check whether the timeout value was specified.
         // Value less than 0 means no timeout is specified.
-        if (xaTimeout >= 0) {
+        // DERBY-4232: The DRDA spec says that SYNCCTL should only have a
+        // timeout property if TMNOFLAGS is specified.
+        if (xaTimeout >= 0 && xaFlags == XAResource.TMNOFLAGS) {
             writeXATimeout(CodePoint.TIMEOUT, xaTimeout);
         }
+
         updateLengthBytes();
     }
 

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java?rev=789105&r1=789104&r2=789105&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java Sun Jun 28 14:49:37 2009
@@ -45,6 +45,7 @@
 import org.apache.derbyTesting.junit.J2EEDataSource;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.XATestUtil;
 
 /** The test of the properties of the XA transaction interface implementation.
   */
@@ -287,6 +288,75 @@
     }
 
     /**
+     * DERBY-4232: Test that an XA transaction can be suspended and resumed
+     * when a timeout is in effect.
+     */
+    public void testTransactionTimeoutAndSuspendResume() throws Exception {
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        XAConnection xac = xads.getXAConnection();
+        XAResource xar = xac.getXAResource();
+        Xid xid = XATestUtil.getXid(1, 2, 3);
+
+        // Start work in a new transaction with a timeout
+        xar.setTransactionTimeout(500);
+        xar.start(xid, XAResource.TMNOFLAGS);
+
+        // Suspend the transaction
+        xar.end(xid, XAResource.TMSUSPEND);
+
+        // Resume the transaction (used to fail with a XAER_PROTO on the
+        // network client)
+        xar.start(xid, XAResource.TMRESUME);
+
+        // End the transaction and free up the resources
+        xar.end(xid, XAResource.TMSUCCESS);
+        xar.rollback(xid);
+        xac.close();
+    }
+
+    /**
+     * DERBY-4232: Test that two branches can be joined after the timeout has
+     * been set.
+     */
+    public void testTransactionTimeoutAndJoin() throws Exception {
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        XAConnection xac1 = xads.getXAConnection();
+        XAResource xar1 = xac1.getXAResource();
+        Xid xid1 = XATestUtil.getXid(4, 5, 6);
+
+        // Start/end work in a new transaction
+        xar1.setTransactionTimeout(500);
+        xar1.start(xid1, XAResource.TMNOFLAGS);
+        xar1.end(xid1, XAResource.TMSUCCESS);
+
+        // Create a new branch that can be joined with the existing one
+        XAConnection xac2 = xads.getXAConnection();
+        XAResource xar2 = xac2.getXAResource();
+        xar2.setTransactionTimeout(500);
+
+        // Do some work on the new branch before joining (the bug won't be
+        // reproduced if we join with a fresh branch)
+        Xid xid2 = XATestUtil.getXid(4, 5, 7);
+        xar2.start(xid2, XAResource.TMNOFLAGS);
+        xar2.end(xid2, XAResource.TMSUCCESS);
+        xar2.rollback(xid2);
+
+        assertTrue(
+                "Branches can only be joined if RM is same",
+                xar1.isSameRM(xar2));
+
+        // Join the branches. This used to fail with XAER_PROTO on the
+        // network client.
+        xar2.start(xid1, XAResource.TMJOIN);
+
+        // End the transaction and free up the resources
+        xar2.end(xid1, XAResource.TMSUCCESS);
+        xar2.rollback(xid1);
+        xac1.close();
+        xac2.close();
+    }
+
+    /**
      * DERBY-4141 XAExceptions caused by SQLExceptions should have a
      * non-zero errorCode. SESSION_SEVERITY or greater map to
      * XAException.XAER_RMFAIL. Lesser exceptions map to XAException.XAER_RMERR