activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r805881 - /activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java
Date Wed, 19 Aug 2009 17:08:48 GMT
Author: djencks
Date: Wed Aug 19 17:08:48 2009
New Revision: 805881

URL: http://svn.apache.org/viewvc?rev=805881&view=rev
Log:
AMQ-2346 test demonstrating problem (set to not run)

Added:
    activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java
      - copied, changed from r801013, activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXAQueueTransactionTest.java

Copied: activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java
(from r801013, activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXAQueueTransactionTest.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java?p2=activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java&p1=activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXAQueueTransactionTest.java&r1=801013&r2=805881&rev=805881&view=diff
==============================================================================
--- activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXAQueueTransactionTest.java
(original)
+++ activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/JmsXARollback2CxTransactionTest.java
Wed Aug 19 17:08:48 2009
@@ -25,8 +25,8 @@
 import java.io.DataOutputStream;
 
 import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
 import javax.jms.Session;
+import javax.jms.Connection;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 import javax.resource.spi.ManagedConnection;
@@ -38,14 +38,14 @@
 /**
  * @version $Rev$ $Date$
  */
-public class JmsXAQueueTransactionTest extends JmsQueueTransactionTest {
+public class JmsXARollback2CxTransactionTest extends JmsQueueTransactionTest {
     private static final String DEFAULT_HOST = "vm://localhost";
 
     private ConnectionManagerAdapter connectionManager = new ConnectionManagerAdapter();
-    private ActiveMQManagedConnectionFactory managedConnectionFactory;
-    private XAResource xaResource;
     private static long txGenerator;
     private Xid xid;
+    private XAResource[] xares = new XAResource[2];
+    private int index = 0;
 
     @Override
     protected void setSessionTransacted() {
@@ -55,14 +55,19 @@
 
     @Override
     protected ConnectionFactory newConnectionFactory() throws Exception {
-        managedConnectionFactory = new ActiveMQManagedConnectionFactory();
+        ActiveMQManagedConnectionFactory managedConnectionFactory = new ActiveMQManagedConnectionFactory();
         managedConnectionFactory.setServerUrl(DEFAULT_HOST);
-        managedConnectionFactory.setUserName(org.apache.activemq.ActiveMQConnectionFactory.DEFAULT_USER);
+        managedConnectionFactory.setUserName(ActiveMQConnectionFactory.DEFAULT_USER);
         managedConnectionFactory.setPassword(ActiveMQConnectionFactory.DEFAULT_PASSWORD);
 
-        return (ConnectionFactory)managedConnectionFactory.createConnectionFactory(connectionManager);
+        return (ConnectionFactory) managedConnectionFactory.createConnectionFactory(connectionManager);
     }
 
+    public void xtestRepeatReceiveTwoThenRollback() throws Exception {
+        for (index = 0; index< 20; index ++) {
+            testReceiveTwoThenRollback();
+        }
+    }
 
     /**
      * Recreates the connection.
@@ -72,9 +77,15 @@
     @Override
     protected void reconnect() throws Exception {
         super.reconnect();
+        xares[0] = getXAResource(connection);
+        ManagedConnectionProxy cx2 = (ManagedConnectionProxy) connectionFactory.createConnection();
+        xares[1] = getXAResource(cx2);
+    }
+
+    private XAResource getXAResource(Connection connection) throws ResourceException {
         ManagedConnectionProxy proxy = (ManagedConnectionProxy) connection;
         ManagedConnection mc = proxy.getManagedConnection();
-        xaResource = mc.getXAResource();
+        return mc.getXAResource();
     }
 
     @Override
@@ -88,23 +99,26 @@
     @Override
     protected void beginTx() throws Exception {
         xid = createXid();
-        xaResource.start(xid, XAResource.TMNOFLAGS);
+        xares[index%2].start(xid, XAResource.TMNOFLAGS);
+        xares[(index+ 1)%2].start(xid, XAResource.TMJOIN);
     }
 
     @Override
     protected void commitTx() throws Exception {
-        xaResource.end(xid, XAResource.TMSUCCESS);
-        int result = xaResource.prepare(xid);
+        xares[index%2].end(xid, XAResource.TMSUCCESS);
+        xares[(index+ 1)%2].end(xid, XAResource.TMSUCCESS);
+        int result = xares[index%2].prepare(xid);
         if (result == XAResource.XA_OK) {
-            xaResource.commit(xid, false);
+            xares[index%2].commit(xid, false);
         }
         xid = null;
     }
 
     @Override
     protected void rollbackTx() throws Exception {
-        xaResource.end(xid, XAResource.TMSUCCESS);
-        xaResource.rollback(xid);
+        xares[index%2].end(xid, XAResource.TMSUCCESS);
+        xares[(index+ 1)%2].end(xid, XAResource.TMSUCCESS);
+        xares[index%2].rollback(xid);
         xid = null;
     }
 
@@ -149,4 +163,4 @@
 
     }
 
-}
+}
\ No newline at end of file



Mime
View raw message