mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-4486 - fix and test
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1475798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
66e8011e9e
commit
f2b01a7f01
|
@ -34,6 +34,7 @@ import javax.transaction.xa.XAResource;
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.RedeliveryPolicy;
|
import org.apache.activemq.RedeliveryPolicy;
|
||||||
|
import org.apache.activemq.TransactionContext;
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.util.ServiceSupport;
|
import org.apache.activemq.util.ServiceSupport;
|
||||||
|
@ -233,25 +234,20 @@ public class ActiveMQResourceAdapter extends ActiveMQConnectionSupport implement
|
||||||
* @see javax.resource.spi.ResourceAdapter#getXAResources(javax.resource.spi.ActivationSpec[])
|
* @see javax.resource.spi.ResourceAdapter#getXAResources(javax.resource.spi.ActivationSpec[])
|
||||||
*/
|
*/
|
||||||
public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
|
public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
|
||||||
Connection connection = null;
|
|
||||||
try {
|
try {
|
||||||
connection = makeConnection();
|
final ActiveMQConnection connection = makeConnection();
|
||||||
if (connection instanceof XAConnection) {
|
return new XAResource[]{new LocalAndXATransaction(new TransactionContext(connection)) {
|
||||||
XASession session = ((XAConnection)connection).createXASession();
|
public void finalize() throws Throwable {
|
||||||
XAResource xaResource = session.getXAResource();
|
try {
|
||||||
return new XAResource[] {
|
connection.close();
|
||||||
xaResource
|
} catch (Throwable ignore) {
|
||||||
};
|
} finally {
|
||||||
}
|
super.finalize();
|
||||||
return new XAResource[] {};
|
}
|
||||||
|
}
|
||||||
|
}};
|
||||||
} catch (JMSException e) {
|
} catch (JMSException e) {
|
||||||
throw new ResourceException(e);
|
throw new ResourceException(e);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
connection.close();
|
|
||||||
} catch (Throwable ignore) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import javax.resource.spi.UnavailableException;
|
||||||
import javax.resource.spi.XATerminator;
|
import javax.resource.spi.XATerminator;
|
||||||
import javax.resource.spi.work.WorkManager;
|
import javax.resource.spi.work.WorkManager;
|
||||||
|
|
||||||
|
import javax.transaction.xa.XAResource;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQTopicSubscriber;
|
import org.apache.activemq.ActiveMQTopicSubscriber;
|
||||||
|
@ -105,4 +106,16 @@ public class ActiveMQConnectionFactoryTest extends TestCase {
|
||||||
assertEquals(0, ((ActiveMQTopicSubscriber)sub).getPrefetchNumber());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue