@Test
  public void testBalanceCluster() throws Exception {
    setMaxRunTime(Duration.ofMillis(2500));
    loadBalancer.onConfigurationChange(conf);
    for (int[] mockCluster : clusterStateMocks) {
      Map<ServerName, List<RegionInfo>> servers = mockClusterServers(mockCluster);
      List<ServerAndLoad> list = convertToList(servers);
      LOG.info("Mock Cluster : " + printMock(list) + " " + printStats(list));
      Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
        (Map) mockClusterServersWithTables(servers);
      List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
      List<ServerAndLoad> balancedCluster = reconcile(list, plans, servers);
      LOG.info("Mock Balance : " + printMock(balancedCluster));
      assertClusterAsBalanced(balancedCluster);
      LoadOfAllTable = (Map) mockClusterServersWithTables(servers);
      List<RegionPlan> secondPlans = loadBalancer.balanceCluster(LoadOfAllTable);
      assertNull(secondPlans);
      for (Map.Entry<ServerName, List<RegionInfo>> entry : servers.entrySet()) {
        returnRegions(entry.getValue());
        returnServer(entry.getKey());
      }
    }
  }
Test the load balancing algorithm.
<p>
Invariant is that all servers should be hosting either floor(average) or ceiling(average)
hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerBalanceCluster.java