mirror of https://github.com/apache/activemq.git
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/branches/activemq-4.0@420697 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
251b25de92
commit
fe3785c9ba
|
@ -16,14 +16,17 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.usecases;
|
package org.apache.activemq.usecases;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.xbean.BrokerFactoryBean;
|
|
||||||
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
||||||
|
import org.apache.activemq.util.ServiceSupport;
|
||||||
|
import org.apache.activemq.xbean.BrokerFactoryBean;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,10 +36,18 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
|
||||||
|
|
||||||
protected ActiveMQConnectionFactory sendFactory;
|
protected ActiveMQConnectionFactory sendFactory;
|
||||||
protected ActiveMQConnectionFactory receiveFactory;
|
protected ActiveMQConnectionFactory receiveFactory;
|
||||||
|
protected HashMap brokers = new HashMap();
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
sendFactory = createSenderConnectionFactory();
|
sendFactory = createSenderConnectionFactory();
|
||||||
receiveFactory = createReceiverConnectionFactory();
|
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();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +61,11 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
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 {
|
protected Connection createReceiveConnection() throws JMSException {
|
||||||
|
@ -64,11 +80,10 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
|
||||||
try {
|
try {
|
||||||
BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(config));
|
BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(config));
|
||||||
brokerFactory.afterPropertiesSet();
|
brokerFactory.afterPropertiesSet();
|
||||||
|
|
||||||
BrokerService broker = brokerFactory.getBroker();
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -25,14 +25,6 @@ import javax.jms.JMSException;
|
||||||
*/
|
*/
|
||||||
public class TwoBrokerTopicSendReceiveUsingHttpTest extends TwoBrokerTopicSendReceiveTest {
|
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 {
|
protected ActiveMQConnectionFactory createReceiverConnectionFactory() throws JMSException {
|
||||||
return createConnectionFactory("org/apache/activemq/usecases/receiver-http.xml", "receiver", "vm://receiver");
|
return createConnectionFactory("org/apache/activemq/usecases/receiver-http.xml", "receiver", "vm://receiver");
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class TwoBrokerTopicSendReceiveUsingTcpTest extends TwoBrokerTopicSendRec
|
||||||
senderBroker = brokerFactory.getBroker();
|
senderBroker = brokerFactory.getBroker();
|
||||||
|
|
||||||
super.setUp();
|
super.setUp();
|
||||||
Thread.sleep(2000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue