mirror of https://github.com/apache/activemq.git
add little test to validate load balancing in a simple network
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@943856 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c15b6d0046
commit
c3a64a8eb3
|
@ -17,26 +17,13 @@
|
|||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
*/
|
||||
public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultipleBrokersTestSupport {
|
||||
protected static final int MESSAGE_COUNT = 100;
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
import org.apache.activemq.util.Wait;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class TwoBrokerNetworkLoadBalanceTest extends JmsMultipleBrokersTestSupport {
|
||||
protected static final Log LOG = LogFactory.getLog(TwoBrokerNetworkLoadBalanceTest.class);
|
||||
public void testLoadBalancing() throws Exception {
|
||||
bridgeBrokers("BrokerA", "BrokerB");
|
||||
bridgeBrokers("BrokerB", "BrokerA");
|
||||
|
||||
startAllBrokers();
|
||||
waitForBridgeFormation();
|
||||
|
||||
// Setup destination
|
||||
Destination dest = createDestination("TEST.FOO", false);
|
||||
|
||||
// Setup consumers
|
||||
MessageConsumer clientA = createConsumer("BrokerA", dest);
|
||||
|
||||
// Setup consumers
|
||||
MessageConsumer clientB = createConsumer("BrokerB", dest);
|
||||
|
||||
// Send messages
|
||||
sendMessages("BrokerA", dest, 5000);
|
||||
|
||||
// Send messages
|
||||
sendMessages("BrokerB", dest, 1000);
|
||||
|
||||
// Get message count
|
||||
final MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
|
||||
final MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
|
||||
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
public boolean isSatisified() throws Exception {
|
||||
return msgsA.getMessageCount() + msgsB.getMessageCount() == 6000;
|
||||
}});
|
||||
|
||||
LOG.info("A got: " + msgsA.getMessageCount());
|
||||
LOG.info("B got: " + msgsB.getMessageCount());
|
||||
|
||||
assertTrue("B got is fair share: " + msgsB.getMessageCount(), msgsB.getMessageCount() > 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"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue