activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1475798 - in /activemq/trunk/activemq-ra/src: main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
Date Thu, 25 Apr 2013 14:33:54 GMT
Author: gtully
Date: Thu Apr 25 14:33:54 2013
New Revision: 1475798

URL: http://svn.apache.org/r1475798
Log:
https://issues.apache.org/jira/browse/AMQ-4486 - fix and test

Modified:
    activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
    activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java

Modified: activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java?rev=1475798&r1=1475797&r2=1475798&view=diff
==============================================================================
--- activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
(original)
+++ activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
Thu Apr 25 14:33:54 2013
@@ -34,6 +34,7 @@ import javax.transaction.xa.XAResource;
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.RedeliveryPolicy;
+import org.apache.activemq.TransactionContext;
 import org.apache.activemq.broker.BrokerFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.util.ServiceSupport;
@@ -233,25 +234,20 @@ public class ActiveMQResourceAdapter ext
      * @see javax.resource.spi.ResourceAdapter#getXAResources(javax.resource.spi.ActivationSpec[])
      */
     public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException
{
-        Connection connection = null;
         try {
-            connection = makeConnection();
-            if (connection instanceof XAConnection) {
-                XASession session = ((XAConnection)connection).createXASession();
-                XAResource xaResource = session.getXAResource();
-                return new XAResource[] {
-                    xaResource
-                };
-            }
-            return new XAResource[] {};
+            final ActiveMQConnection connection = makeConnection();
+            return new XAResource[]{new LocalAndXATransaction(new TransactionContext(connection))
{
+                public void finalize() throws Throwable {
+                    try {
+                        connection.close();
+                    } catch (Throwable ignore) {
+                    } finally {
+                        super.finalize();
+                    }
+                }
+            }};
         } catch (JMSException e) {
             throw new ResourceException(e);
-        } finally {
-            try {
-                connection.close();
-            } catch (Throwable ignore) {
-                //
-            }
         }
     }
 

Modified: activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java?rev=1475798&r1=1475797&r2=1475798&view=diff
==============================================================================
--- activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
(original)
+++ activemq/trunk/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
Thu Apr 25 14:33:54 2013
@@ -30,6 +30,7 @@ import javax.resource.spi.UnavailableExc
 import javax.resource.spi.XATerminator;
 import javax.resource.spi.work.WorkManager;
 
+import javax.transaction.xa.XAResource;
 import junit.framework.TestCase;
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQTopicSubscriber;
@@ -105,4 +106,16 @@ public class ActiveMQConnectionFactoryTe
         assertEquals(0, ((ActiveMQTopicSubscriber)sub).getPrefetchNumber());
     }
 
+    public void testGetXAResource() throws Exception {
+
+        ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
+        ra.setServerUrl(url);
+        ra.setUserName(user);
+        ra.setPassword(pwd);
+
+        XAResource[] resoruces = ra.getXAResources(null);
+        assertEquals("one resource", 1, resoruces.length);
+
+        assertEquals("no pending transactions", 0, resoruces[0].recover(100).length);
+    }
 }



Mime
View raw message