diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java b/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java index 728d4b7ebc..95c5d21832 100755 --- a/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java +++ b/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java @@ -1284,21 +1284,22 @@ public class FailoverTransport implements CompositeTransport { @Override public void updateURIs(boolean rebalance, URI[] updatedURIs) throws IOException { if (isUpdateURIsSupported()) { - HashSet copy = new HashSet(this.updated); - updated.clear(); - if (updatedURIs != null && updatedURIs.length > 0) { - for (URI uri : updatedURIs) { - if (uri != null && !updated.contains(uri)) { - updated.add(uri); - } - } - if (!(copy.isEmpty() && updated.isEmpty()) && !copy.equals(new HashSet(updated))) { - buildBackups(); - synchronized (reconnectMutex) { - reconnect(rebalance); + HashSet copy = new HashSet(); + synchronized (reconnectMutex) { + copy.addAll(this.updated); + updated.clear(); + if (updatedURIs != null && updatedURIs.length > 0) { + for (URI uri : updatedURIs) { + if (uri != null && !updated.contains(uri)) { + updated.add(uri); + } } } } + if (!(copy.isEmpty() && updated.isEmpty()) && !copy.equals(new HashSet(updated))) { + buildBackups(); + reconnect(rebalance); + } } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java index fab2da50cb..74fc0b549f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; * broker is removed and then show 3 after the 3rd broker is reintroduced. */ public class FailoverComplexClusterTest extends FailoverClusterTestSupport { + protected final Logger LOG = LoggerFactory.getLogger(FailoverComplexClusterTest.class); private static final String BROKER_A_CLIENT_TC_ADDRESS = "tcp://127.0.0.1:61616"; private static final String BROKER_B_CLIENT_TC_ADDRESS = "tcp://127.0.0.1:61617"; @@ -258,6 +259,7 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport { private void runTests(boolean multi, String tcParams, String clusterFilter, String destinationFilter) throws Exception, InterruptedException { assertClientsConnectedToThreeBrokers(); + LOG.info("Stopping BrokerC in prep for restart"); getBroker(BROKER_C_NAME).stop(); getBroker(BROKER_C_NAME).waitUntilStopped(); removeBroker(BROKER_C_NAME); @@ -266,6 +268,7 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport { assertClientsConnectedToTwoBrokers(); + LOG.info("Recreating BrokerC after stop"); createBrokerC(multi, tcParams, clusterFilter, destinationFilter); getBroker(BROKER_C_NAME).waitUntilStarted(); Thread.sleep(5000);