Fixing test on CI server

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1383860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Claus Ibsen 2012-09-12 09:12:02 +00:00
parent 5453b26eb8
commit f830d96b8b
1 changed files with 94 additions and 48 deletions

View File

@ -56,6 +56,21 @@ import org.slf4j.LoggerFactory;
public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport { public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQXAConnectionFactoryTest.class); private static final Logger LOG = LoggerFactory.getLogger(ActiveMQXAConnectionFactoryTest.class);
long txGenerator = System.currentTimeMillis(); long txGenerator = System.currentTimeMillis();
private ActiveMQConnection connection;
private BrokerService broker;
protected void tearDown() throws Exception {
// Try our best to close any previously opend connection.
try {
connection.close();
} catch (Throwable ignore) {
}
// Try our best to stop any previously started broker.
try {
broker.stop();
} catch (Throwable ignore) {
}
}
public void testCopy() throws URISyntaxException, JMSException { public void testCopy() throws URISyntaxException, JMSException {
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?"); ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?");
@ -97,25 +112,25 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
} }
public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException { public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException {
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory( ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://myBroker?broker.persistent=false");
"vm://localhost?broker.persistent=false");
// Make sure the broker is not created until the connection is // Make sure the broker is not created until the connection is
// instantiated. // instantiated.
assertNull(BrokerRegistry.getInstance().lookup("localhost")); assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
Connection connection = cf.createConnection(); connection = (ActiveMQConnection) cf.createConnection();
// This should create the connection. // This should create the connection.
assertNotNull(connection); assertNotNull(connection);
// Verify the broker was created. // Verify the broker was created.
assertNotNull(BrokerRegistry.getInstance().lookup("localhost")); assertNotNull(BrokerRegistry.getInstance().lookup("myBroker"));
connection.close(); connection.close();
// Verify the broker was destroyed. // Verify the broker was destroyed.
assertNull(BrokerRegistry.getInstance().lookup("localhost")); assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
connection.close();
} }
public void testGetBrokerName() throws URISyntaxException, JMSException { public void testGetBrokerName() throws URISyntaxException, JMSException {
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory( ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
"vm://localhost?broker.persistent=false"); connection = (ActiveMQConnection)cf.createConnection();
ActiveMQConnection connection = (ActiveMQConnection)cf.createConnection();
connection.start(); connection.start();
String brokerName = connection.getBrokerName(); String brokerName = connection.getBrokerName();
@ -135,52 +150,83 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
public void testIsSameRM() throws URISyntaxException, JMSException, XAException { public void testIsSameRM() throws URISyntaxException, JMSException, XAException {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false"); XAConnection connection1 = null;
XAConnection connection1 = (XAConnection)cf1.createConnection(); XAConnection connection2 = null;
XASession session1 = connection1.createXASession(); try {
XAResource resource1 = session1.getXAResource(); ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
connection1 = (XAConnection)cf1.createConnection();
XASession session1 = connection1.createXASession();
XAResource resource1 = session1.getXAResource();
ActiveMQXAConnectionFactory cf2 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false"); ActiveMQXAConnectionFactory cf2 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection2 = (XAConnection)cf2.createConnection(); connection2 = (XAConnection)cf2.createConnection();
XASession session2 = connection2.createXASession(); XASession session2 = connection2.createXASession();
XAResource resource2 = session2.getXAResource(); XAResource resource2 = session2.getXAResource();
assertTrue(resource1.isSameRM(resource2)); assertTrue(resource1.isSameRM(resource2));
session1.close();
connection1.close(); session2.close();
connection2.close(); } finally {
if (connection1 != null) {
try {
connection1.close();
} catch (Exception e) {
// ignore
}
}
if (connection2 != null) {
try {
connection2.close();
} catch (Exception e) {
// ignore
}
}
}
} }
public void testVanilaTransactionalProduceReceive() throws Exception { public void testVanilaTransactionalProduceReceive() throws Exception {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false"); XAConnection connection1 = null;
XAConnection connection1 = (XAConnection)cf1.createConnection(); try {
connection1.start(); ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
XASession session = connection1.createXASession(); connection1 = (XAConnection)cf1.createConnection();
XAResource resource = session.getXAResource(); connection1.start();
Destination dest = new ActiveMQQueue(getName()); XASession session = connection1.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message // publish a message
Xid tid = createXid(); Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS); resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest); MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage(); ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName()); message.setText(getName());
producer.send(message); producer.send(message);
resource.end(tid, XAResource.TMSUCCESS); resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true); resource.commit(tid, true);
session.close(); session.close();
session = connection1.createXASession(); session = connection1.createXASession();
MessageConsumer consumer = session.createConsumer(dest); MessageConsumer consumer = session.createConsumer(dest);
tid = createXid(); tid = createXid();
resource = session.getXAResource(); resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS); resource.start(tid, XAResource.TMNOFLAGS);
TextMessage receivedMessage = (TextMessage) consumer.receive(1000); TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
assertNotNull(receivedMessage); assertNotNull(receivedMessage);
assertEquals(getName(), receivedMessage.getText()); assertEquals(getName(), receivedMessage.getText());
resource.end(tid, XAResource.TMSUCCESS); resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true); resource.commit(tid, true);
session.close();
} finally {
if (connection1 != null) {
try {
connection1.close();
} catch (Exception e) {
// ignore
}
}
}
} }
public void testConsumerCloseTransactionalSendReceive() throws Exception { public void testConsumerCloseTransactionalSendReceive() throws Exception {
@ -382,7 +428,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
protected void assertCreateConnection(String uri) throws Exception { protected void assertCreateConnection(String uri) throws Exception {
// Start up a broker with a tcp connector. // Start up a broker with a tcp connector.
BrokerService broker = new BrokerService(); broker = new BrokerService();
broker.setPersistent(false); broker.setPersistent(false);
TransportConnector connector = broker.addConnector(uri); TransportConnector connector = broker.addConnector(uri);
broker.start(); broker.start();