diff --git a/activemq-test-atomikos/pom.xml b/activemq-test-atomikos/pom.xml new file mode 100755 index 0000000000..4edab0fa50 --- /dev/null +++ b/activemq-test-atomikos/pom.xml @@ -0,0 +1,101 @@ + + + + + + + 4.0.0 + + + org.apache.activemq + activemq-parent + 4.2-incubator-SNAPSHOT + + + activemq-test-atomikos + jar + ActiveMQ :: Atomikos System Test + + + + + logicblaze.deps + http://repo.logicblaze.com/maven2-all + + true + + + true + + + + + + + + ${pom.groupId} + activemq-core + + + ${pom.groupId} + activemq-core + compile + test-jar + + + ${pom.groupId} + activeio-core + + + org.apache.derby + derby + true + + + + com.atomikos + transactions + 3.1.0 + + + com.atomikos + transactions-api + 3.1.0 + + + com.atomikos + transactions-jta + 3.1.0 + + + com.atomikos + atomikos-util + 3.1.0 + + + + junit + junit + compile + + + + diff --git a/activemq-test-atomikos/src/test/java/org/apache/activemq/atomikos/XATest.java b/activemq-test-atomikos/src/test/java/org/apache/activemq/atomikos/XATest.java new file mode 100644 index 0000000000..c087b25a09 --- /dev/null +++ b/activemq-test-atomikos/src/test/java/org/apache/activemq/atomikos/XATest.java @@ -0,0 +1,66 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.atomikos; + +import com.atomikos.datasource.xa.DefaultXidFactory; +import org.apache.activemq.ActiveMQXAConnectionFactory; +import org.apache.activemq.command.ActiveMQQueue; + +import javax.jms.MessageConsumer; +import javax.jms.XAConnection; +import javax.jms.XASession; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +import junit.framework.TestCase; + + +/** + * @version $Revision$ + */ +public class XATest extends TestCase { + + public void testXA() throws Exception { + //String url = "tcp://localhost:61616"; + String url = "vm://localhost"; + String qName = "MyQueue"; + int timeout = 5; + DefaultXidFactory xidFactory = new DefaultXidFactory(); + ActiveMQXAConnectionFactory xacf = new ActiveMQXAConnectionFactory(); + xacf.setBrokerURL(url); + ActiveMQQueue queue = new ActiveMQQueue(); + queue.setPhysicalName(qName); + XAConnection xaconn = xacf.createXAConnection(); + xaconn.start(); + XASession session = xaconn.createXASession(); + XAResource xares = session.getXAResource(); + MessageConsumer receiver = session.getSession().createConsumer(queue); + xares.recover(XAResource.TMSTARTRSCAN); + xares.recover(XAResource.TMNOFLAGS); + xares.setTransactionTimeout(timeout); + xares.isSameRM(xares); + Xid xid = xidFactory.createXid("part1", "part2"); + xares.start(xid, XAResource.TMNOFLAGS); + receiver.receive(timeout); + xares.end(xid, XAResource.TMSUCCESS); + xares.rollback(xid); + + System.out.println("Done!"); + } + +}