mirror of https://github.com/apache/activemq.git
fix intermittent failure - wait rather than sleep which also speeds up the test run
This commit is contained in:
parent
b22184ebf6
commit
1a3ade0414
|
@ -36,6 +36,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
import org.apache.activemq.broker.TransportConnector;
|
||||||
import org.apache.activemq.network.NetworkConnector;
|
import org.apache.activemq.network.NetworkConnector;
|
||||||
|
import org.apache.activemq.util.Wait;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -49,26 +50,31 @@ public class FailoverClusterTestSupport extends TestCase {
|
||||||
private final Map<String, BrokerService> brokers = new HashMap<String, BrokerService>();
|
private final Map<String, BrokerService> brokers = new HashMap<String, BrokerService>();
|
||||||
private final List<ActiveMQConnection> connections = new ArrayList<ActiveMQConnection>();
|
private final List<ActiveMQConnection> connections = new ArrayList<ActiveMQConnection>();
|
||||||
|
|
||||||
protected void assertClientsConnectedToTwoBrokers() {
|
protected void assertClientsConnectedToTwoBrokers() throws Exception {
|
||||||
Set<String> set = new HashSet<String>();
|
assertClientsConnectedToXBrokers(2);
|
||||||
for (ActiveMQConnection c : connections) {
|
|
||||||
if (c.getTransportChannel().getRemoteAddress() != null) {
|
|
||||||
set.add(c.getTransportChannel().getRemoteAddress());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertTrue("Only 2 connections should be found: " + set,
|
|
||||||
set.size() == 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertClientsConnectedToThreeBrokers() {
|
protected void assertClientsConnectedToThreeBrokers() throws Exception {
|
||||||
Set<String> set = new HashSet<String>();
|
assertClientsConnectedToXBrokers(3);
|
||||||
for (ActiveMQConnection c : connections) {
|
}
|
||||||
if (c.getTransportChannel().getRemoteAddress() != null) {
|
|
||||||
set.add(c.getTransportChannel().getRemoteAddress());
|
protected void assertClientsConnectedToXBrokers(final int x) throws Exception {
|
||||||
|
final Set<String> set = new HashSet<String>();
|
||||||
|
Wait.waitFor(new Wait.Condition() {
|
||||||
|
@Override
|
||||||
|
public boolean isSatisified() throws Exception {
|
||||||
|
set.clear();
|
||||||
|
for (ActiveMQConnection c : connections) {
|
||||||
|
if (c.getTransportChannel().getRemoteAddress() != null) {
|
||||||
|
set.add(c.getTransportChannel().getRemoteAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return set.size() == x;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
assertTrue("Only 3 connections should be found: " + set,
|
|
||||||
set.size() == 3);
|
assertTrue("Only " + x + " connections should be found: " + set,
|
||||||
|
set.size() == x);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertClientsConnectionsEvenlyDistributed(double minimumPercentage) {
|
protected void assertClientsConnectionsEvenlyDistributed(double minimumPercentage) {
|
||||||
|
|
|
@ -147,7 +147,6 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport {
|
||||||
|
|
||||||
setClientUrl("failover://(" + BROKER_A_CLIENT_TC_ADDRESS + "," + BROKER_B_CLIENT_TC_ADDRESS + ")");
|
setClientUrl("failover://(" + BROKER_A_CLIENT_TC_ADDRESS + "," + BROKER_B_CLIENT_TC_ADDRESS + ")");
|
||||||
createClients();
|
createClients();
|
||||||
Thread.sleep(2000);
|
|
||||||
|
|
||||||
assertClientsConnectedToThreeBrokers();
|
assertClientsConnectedToThreeBrokers();
|
||||||
|
|
||||||
|
@ -155,13 +154,10 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport {
|
||||||
getBroker(BROKER_A_NAME).waitUntilStopped();
|
getBroker(BROKER_A_NAME).waitUntilStopped();
|
||||||
removeBroker(BROKER_A_NAME);
|
removeBroker(BROKER_A_NAME);
|
||||||
|
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToTwoBrokers();
|
assertClientsConnectedToTwoBrokers();
|
||||||
|
|
||||||
createBrokerA(false, null, null, null);
|
createBrokerA(false, null, null, null);
|
||||||
getBroker(BROKER_A_NAME).waitUntilStarted();
|
getBroker(BROKER_A_NAME).waitUntilStarted();
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToThreeBrokers();
|
assertClientsConnectedToThreeBrokers();
|
||||||
}
|
}
|
||||||
|
@ -264,14 +260,11 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport {
|
||||||
getBroker(BROKER_C_NAME).waitUntilStopped();
|
getBroker(BROKER_C_NAME).waitUntilStopped();
|
||||||
removeBroker(BROKER_C_NAME);
|
removeBroker(BROKER_C_NAME);
|
||||||
|
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToTwoBrokers();
|
assertClientsConnectedToTwoBrokers();
|
||||||
|
|
||||||
LOG.info("Recreating BrokerC after stop");
|
LOG.info("Recreating BrokerC after stop");
|
||||||
createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
|
createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
|
||||||
getBroker(BROKER_C_NAME).waitUntilStarted();
|
getBroker(BROKER_C_NAME).waitUntilStarted();
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToThreeBrokers();
|
assertClientsConnectedToThreeBrokers();
|
||||||
}
|
}
|
||||||
|
@ -292,14 +285,11 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport {
|
||||||
getBroker(BROKER_C_NAME).waitUntilStopped();
|
getBroker(BROKER_C_NAME).waitUntilStopped();
|
||||||
removeBroker(BROKER_C_NAME);
|
removeBroker(BROKER_C_NAME);
|
||||||
|
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToTwoBrokers();
|
assertClientsConnectedToTwoBrokers();
|
||||||
assertClientsConnectionsEvenlyDistributed(.35);
|
assertClientsConnectionsEvenlyDistributed(.35);
|
||||||
|
|
||||||
createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
|
createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
|
||||||
getBroker(BROKER_C_NAME).waitUntilStarted();
|
getBroker(BROKER_C_NAME).waitUntilStarted();
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
assertClientsConnectedToThreeBrokers();
|
assertClientsConnectedToThreeBrokers();
|
||||||
assertClientsConnectionsEvenlyDistributed(.20);
|
assertClientsConnectionsEvenlyDistributed(.20);
|
||||||
|
|
Loading…
Reference in New Issue