Correct test case

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@646673 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-04-10 08:01:08 +00:00
parent 85ebf3616e
commit 97a646c5a8
1 changed files with 7 additions and 51 deletions

View File

@ -30,6 +30,7 @@ import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.Command;
import org.apache.activemq.network.DemandForwardingBridge;
import org.apache.activemq.network.NetworkBridgeConfiguration;
import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.transport.TransportFactory;
import org.apache.activemq.util.MessageIdList;
@ -37,10 +38,7 @@ import org.apache.activemq.util.MessageIdList;
* @version $Revision: 1.1.1.1 $
*/
public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultipleBrokersTestSupport {
protected static final int MESSAGE_COUNT = 10;
protected List<DemandForwardingBridge> bridges;
protected AtomicInteger msgDispatchCount;
protected static final int MESSAGE_COUNT = 100;
/**
* BrokerA -> BrokerB
@ -58,6 +56,7 @@ public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultip
MessageConsumer clientA = createConsumer("BrokerA", dest);
MessageConsumer clientB = createConsumer("BrokerB", dest);
Thread.sleep(2000);
// Send messages
sendMessages("BrokerA", dest, MESSAGE_COUNT);
@ -71,8 +70,6 @@ public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultip
assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
assertEquals(MESSAGE_COUNT, msgsB.getMessageCount());
// Check that 10 message dispatch commands are send over the network
assertEquals(MESSAGE_COUNT, msgDispatchCount.get());
}
/**
@ -100,55 +97,14 @@ public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultip
assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
// Check that no message dispatch commands are send over the network
assertEquals(0, msgDispatchCount.get());
}
protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
List remoteTransports = remoteBroker.getTransportConnectors();
List localTransports = localBroker.getTransportConnectors();
URI remoteURI;
URI localURI;
if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri();
localURI = ((TransportConnector)localTransports.get(0)).getConnectUri();
// Ensure that we are connecting using tcp
if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
config.setBrokerName(localBroker.getBrokerName());
DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI)) {
protected void serviceLocalCommand(Command command) {
if (command.isMessageDispatch()) {
// Keep track of the number of message dispatches
// through the bridge
msgDispatchCount.incrementAndGet();
}
super.serviceLocalCommand(command);
}
};
bridges.add(bridge);
bridge.start();
} else {
throw new Exception("Remote broker or local broker is not using tcp connectors");
}
} else {
throw new Exception("Remote broker or local broker has no registered connectors.");
}
maxSetupTime = 2000;
}
public void setUp() throws Exception {
super.setAutoFail(true);
super.setUp();
createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false"));
createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false"));
bridges = new ArrayList<DemandForwardingBridge>();
msgDispatchCount = new AtomicInteger(0);
createBroker(new URI(
"broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false"));
createBroker(new URI(
"broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false"));
}
}