activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1002604 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/TransactionBroker.java test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
Date Wed, 29 Sep 2010 13:10:52 GMT
Author: dejanb
Date: Wed Sep 29 13:10:52 2010
New Revision: 1002604

URL: http://svn.apache.org/viewvc?rev=1002604&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-2950 - xa transaction rollback on connection
close

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java?rev=1002604&r1=1002603&r2=1002604&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
Wed Sep 29 13:10:52 2010
@@ -251,6 +251,16 @@ public class TransactionBroker extends B
             }
             iter.remove();
         }
+
+        for (Transaction tx : xaTransactions.values()) {
+           try {
+             if (!tx.isPrepared()) {
+                tx.rollback();
+             }
+           } catch (Exception e) {
+               LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e);
+           }
+        }
         next.removeConnection(context, info, error);
     }
 

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java?rev=1002604&r1=1002603&r2=1002604&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
Wed Sep 29 13:10:52 2010
@@ -301,6 +301,31 @@ public class ActiveMQXAConnectionFactory
         
     }
 
+    public void testCloseSendConnection() throws Exception {
+        String brokerName = "closeSend";
+        BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/"
+ brokerName));
+        broker.start();
+        broker.waitUntilStarted();
+        ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
+        XAConnection connection = (XAConnection)cf.createConnection();
+        connection.start();
+        XASession session = connection.createXASession();
+        XAResource resource = session.getXAResource();
+        Destination dest = new ActiveMQQueue(getName());
+
+        // publish a message
+        Xid tid = createXid();
+        resource.start(tid, XAResource.TMNOFLAGS);
+        MessageProducer producer = session.createProducer(dest);
+        ActiveMQTextMessage message  = new ActiveMQTextMessage();
+        message.setText(getName());
+        producer.send(message);
+
+        connection.close();
+
+        assertTransactionGoneFromBroker(tid);
+    }
+
     private void assertTransactionGoneFromFailoverState(
             ActiveMQXAConnection connection1, Xid tid) throws Exception {
         
@@ -336,7 +361,7 @@ public class ActiveMQXAConnectionFactory
         TransactionBroker transactionBroker = (TransactionBroker)broker.getBroker().getAdaptor(TransactionBroker.class);
         try {
             transactionBroker.getTransaction(null, new XATransactionId(tid), false);
-            fail("expecte ex on tx not found");
+            fail("expected exception on tx not found");
         } catch (XAException expectedOnNotFound) {
         }
     }



Mime
View raw message