for (Cache c : caches) {
StateTransferManager stateTransferManager = extractComponent(c, StateTransferManager.class);
DefaultRebalancePolicy rebalancePolicy = (DefaultRebalancePolicy) TestingUtil.extractGlobalComponent(c.getCacheManager(), RebalancePolicy.class);
Address cacheAddress = c.getAdvancedCache().getRpcManager().getAddress();
while (true) {
CacheTopology cacheTopology = stateTransferManager.getCacheTopology();
boolean rebalanceInProgress = stateTransferManager.isStateTransferInProgress();
boolean chIsBalanced = !rebalanceInProgress && rebalancePolicy.isBalanced(cacheTopology.getCurrentCH());
boolean chContainsAllMembers = cacheTopology.getCurrentCH().getMembers().size() == caches.length;
if (chIsBalanced && chContainsAllMembers)
break;
if (System.currentTimeMillis() > giveup) {
String message;
if (!chContainsAllMembers) {
Address[] addresses = new Address[caches.length];
for (int i = 0; i < caches.length; i++) {
addresses[i] = caches[i].getCacheManager().getAddress();
}
message = String.format("Timed out waiting for rebalancing to complete on node %s, " +
"expected member list is %s, current member list is %s!",
cacheAddress, Arrays.toString(addresses), cacheTopology.getCurrentCH().getMembers());
} else {
message = String.format("Timed out waiting for rebalancing to complete on node %s, " +
"current topology is %s", c.getCacheManager().getAddress(), cacheTopology);
}
log.error(message);