Make the tests more reliable by explicity creating and shutting down the brokers. Also wait for the brokers to be setup before running the tests

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@420699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-07-11 03:59:54 +00:00
parent e4266c33f6
commit 2fe01ce355
3 changed files with 21 additions and 15 deletions

View File

@ -16,14 +16,17 @@
*/
package org.apache.activemq.usecases;
import java.util.HashMap;
import java.util.Iterator;
import javax.jms.Connection;
import javax.jms.JMSException;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
import org.apache.activemq.util.ServiceSupport;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.springframework.core.io.ClassPathResource;
/**
@ -33,10 +36,18 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
protected ActiveMQConnectionFactory sendFactory;
protected ActiveMQConnectionFactory receiveFactory;
protected HashMap brokers = new HashMap();
protected void setUp() throws Exception {
sendFactory = createSenderConnectionFactory();
receiveFactory = createReceiverConnectionFactory();
// Give server enough time to setup,
// so we don't lose messages when connection fails
log.info("Waiting for brokers Initialize.");
Thread.sleep(5000);
log.info("Brokers should be initialized by now.. starting test.");
super.setUp();
}
@ -50,6 +61,11 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
protected void tearDown() throws Exception {
super.tearDown();
for (Iterator iter = brokers.values().iterator(); iter.hasNext();) {
BrokerService broker = (BrokerService) iter.next();
ServiceSupport.dispose(broker);
iter.remove();
}
}
protected Connection createReceiveConnection() throws JMSException {
@ -64,11 +80,10 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
try {
BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(config));
brokerFactory.afterPropertiesSet();
BrokerService broker = brokerFactory.getBroker();
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getConnectUri());
brokers.put(brokerName, broker);
return factory;
return new ActiveMQConnectionFactory(connectUrl);
} catch (Exception e) {
e.printStackTrace();

View File

@ -25,14 +25,6 @@ import javax.jms.JMSException;
*/
public class TwoBrokerTopicSendReceiveUsingHttpTest extends TwoBrokerTopicSendReceiveTest {
protected void setUp() throws Exception {
super.setUp();
// Give jetty server enough time to setup,
// so we don't lose messages when connection fails
Thread.sleep(5000);
}
protected ActiveMQConnectionFactory createReceiverConnectionFactory() throws JMSException {
return createConnectionFactory("org/apache/activemq/usecases/receiver-http.xml", "receiver", "vm://receiver");
}

View File

@ -46,7 +46,6 @@ public class TwoBrokerTopicSendReceiveUsingTcpTest extends TwoBrokerTopicSendRec
senderBroker = brokerFactory.getBroker();
super.setUp();
Thread.sleep(2000);
}
protected void tearDown() throws Exception {