mirror of https://github.com/apache/activemq.git
Tweaked some tests so that they are more resiliant against thread schedualing variations
git-svn-id: https://svn.apache.org/repos/asf/activemq/branches/activemq-4.1@524780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5dde5562a9
commit
38afec2a7b
|
@ -34,23 +34,34 @@ import org.apache.activemq.broker.TransportConnector;
|
|||
|
||||
public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
||||
|
||||
public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException, JMSException {
|
||||
private ActiveMQConnection connection;
|
||||
private BrokerService broker;
|
||||
|
||||
public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException, JMSException {
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.clientIDPrefix=Cheese");
|
||||
assertEquals("Cheese", cf.getClientIDPrefix());
|
||||
|
||||
ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
|
||||
try {
|
||||
connection.start();
|
||||
connection = (ActiveMQConnection) cf.createConnection();
|
||||
connection.start();
|
||||
|
||||
String clientID = connection.getClientID();
|
||||
log.info("Got client ID: " + clientID);
|
||||
String clientID = connection.getClientID();
|
||||
log.info("Got client ID: " + clientID);
|
||||
|
||||
assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese"));
|
||||
}
|
||||
finally {
|
||||
connection.close();
|
||||
}
|
||||
assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese"));
|
||||
}
|
||||
|
||||
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 testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException {
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=true");
|
||||
|
@ -73,26 +84,27 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
|||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||
// Make sure the broker is not created until the connection is instantiated.
|
||||
assertNull( BrokerRegistry.getInstance().lookup("localhost") );
|
||||
Connection connection = cf.createConnection();
|
||||
connection = (ActiveMQConnection) cf.createConnection();
|
||||
// This should create the connection.
|
||||
assertNotNull(connection);
|
||||
// Verify the broker was created.
|
||||
assertNotNull( BrokerRegistry.getInstance().lookup("localhost") );
|
||||
|
||||
connection.close();
|
||||
|
||||
// Verify the broker was destroyed.
|
||||
assertNull( BrokerRegistry.getInstance().lookup("localhost") );
|
||||
}
|
||||
|
||||
public void testGetBrokerName() throws URISyntaxException, JMSException {
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||
ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
|
||||
connection = (ActiveMQConnection) cf.createConnection();
|
||||
connection.start();
|
||||
|
||||
String brokerName = connection.getBrokerName();
|
||||
log.info("Got broker name: " + brokerName);
|
||||
|
||||
assertNotNull("No broker name available!", brokerName);
|
||||
connection.close();
|
||||
}
|
||||
|
||||
public void testCreateTcpConnectionUsingAllocatedPort() throws Exception {
|
||||
|
@ -128,7 +140,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
|||
|
||||
protected void assertCreateConnection(String uri) throws Exception {
|
||||
// Start up a broker with a tcp connector.
|
||||
BrokerService broker = new BrokerService();
|
||||
broker = new BrokerService();
|
||||
broker.setPersistent(false);
|
||||
TransportConnector connector = broker.addConnector(uri);
|
||||
broker.start();
|
||||
|
@ -147,9 +159,8 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
|||
|
||||
// This should create the connection.
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
|
||||
Connection connection = cf.createConnection();
|
||||
connection = (ActiveMQConnection) cf.createConnection();
|
||||
assertNotNull(connection);
|
||||
connection.close();
|
||||
|
||||
broker.stop();
|
||||
}
|
||||
|
|
|
@ -1309,6 +1309,9 @@ public class BrokerTest extends BrokerTestSupport {
|
|||
connection2.send(sessionInfo2);
|
||||
connection2.send(consumerInfo2);
|
||||
|
||||
// Wait a little for messages to get delivered.
|
||||
Thread.sleep(1000);
|
||||
|
||||
for( int i=0; i < 4; i++ ) {
|
||||
Message m1 = receiveMessage(connection1);
|
||||
Message m2 = receiveMessage(connection2);
|
||||
|
|
|
@ -173,7 +173,7 @@ public class RecoveryBrokerTest extends BrokerRestartTestSupport {
|
|||
// The we should get the messages.
|
||||
for( int i=0; i < 4 ; i++ ) {
|
||||
Message m2 = receiveMessage(connection2);
|
||||
assertNotNull(m2);
|
||||
assertNotNull("Message "+(i+1)+" is missing.", m2);
|
||||
}
|
||||
assertNoMessagesLeft(connection2);
|
||||
}
|
||||
|
|
|
@ -117,6 +117,14 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
|
|||
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
|
||||
connection2.send(consumerInfo);
|
||||
|
||||
// Give demand forwarding bridge a chance to finish forwarding the subscriptions.
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
// Send the message to the local boker.
|
||||
connection1.send(createMessage(producerInfo, destination, deliveryMode));
|
||||
|
||||
|
@ -130,14 +138,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
|
|||
bridge = new DemandForwardingBridge(createTransport(), createRemoteTransport());
|
||||
bridge.setLocalBrokerName("local");
|
||||
bridge.setDispatchAsync(false);
|
||||
bridge.start();
|
||||
|
||||
// PATCH: Give demand forwarding bridge a chance to finish setting up
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
bridge.start();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
|
|
@ -68,6 +68,13 @@ public class ForwardingBridgeTest extends NetworkTestSupport {
|
|||
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
|
||||
connection2.send(consumerInfo);
|
||||
Thread.sleep(1000);
|
||||
// Give forwarding bridge a chance to finish setting up
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
|
||||
// Send the message to the local boker.
|
||||
connection1.send(createMessage(producerInfo, destination, deliveryMode));
|
||||
|
||||
|
@ -82,14 +89,7 @@ public class ForwardingBridgeTest extends NetworkTestSupport {
|
|||
bridge = new ForwardingBridge(createTransport(), createRemoteTransport());
|
||||
bridge.setClientId("local-remote-bridge");
|
||||
bridge.setDispatchAsync(false);
|
||||
bridge.start();
|
||||
|
||||
// PATCH: Give forwarding bridge a chance to finish setting up
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
bridge.start();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue