mirror of https://github.com/apache/activemq.git
Back ported the Atomikos test case
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/branches/activemq-4.1@480099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2eba7ef00a
commit
9eb343b322
|
@ -0,0 +1,101 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.apache.activemq</groupId>
|
||||||
|
<artifactId>activemq-parent</artifactId>
|
||||||
|
<version>4.2-incubator-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>activemq-test-atomikos</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>ActiveMQ :: Atomikos System Test</name>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<!-- for the Atomikos jars -->
|
||||||
|
<repository>
|
||||||
|
<id>logicblaze.deps</id>
|
||||||
|
<url>http://repo.logicblaze.com/maven2-all</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- activemq -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>${pom.groupId}</groupId>
|
||||||
|
<artifactId>activemq-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${pom.groupId}</groupId>
|
||||||
|
<artifactId>activemq-core</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<type>test-jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${pom.groupId}</groupId>
|
||||||
|
<artifactId>activeio-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.derby</groupId>
|
||||||
|
<artifactId>derby</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atomikos</groupId>
|
||||||
|
<artifactId>transactions</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atomikos</groupId>
|
||||||
|
<artifactId>transactions-api</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atomikos</groupId>
|
||||||
|
<artifactId>transactions-jta</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atomikos</groupId>
|
||||||
|
<artifactId>atomikos-util</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.broker.BrokerService;
|
||||||
|
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 {
|
||||||
|
BrokerService broker = new BrokerService();
|
||||||
|
broker.addConnector("tcp://localhost:61616");
|
||||||
|
broker.start();
|
||||||
|
|
||||||
|
|
||||||
|
String url = "tcp://localhost:61616";
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue