@Test
  public void testUpdateBalancerLoadInfo() {
    int[] cluster = new int[] { 10, 0 };
    Map<ServerName, List<RegionInfo>> servers = mockClusterServers(cluster);
    BalancerClusterState clusterState = mockCluster(cluster);
    Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
      (Map) mockClusterServersWithTables(servers);
    boolean[] perTableBalancerConfigs = { true, false };
    for (boolean isByTable : perTableBalancerConfigs) {
      conf.setBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable);
      loadBalancer.onConfigurationChange(conf);
      dummyMetricsStochasticBalancer.clearDummyMetrics();
      loadBalancer.updateBalancerLoadInfo(LoadOfAllTable);
      assertTrue("Metrics should be recorded!",
        dummyMetricsStochasticBalancer.getDummyCostsMap() != null
          && !dummyMetricsStochasticBalancer.getDummyCostsMap().isEmpty());

      String metricRecordKey;
      if (isByTable) {
        metricRecordKey = "table1#" + StochasticLoadBalancer.OVERALL_COST_FUNCTION_NAME;
      } else {
        metricRecordKey =
          HConstants.ENSEMBLE_TABLE_NAME + "#" + StochasticLoadBalancer.OVERALL_COST_FUNCTION_NAME;
      }
      double curOverallCost = loadBalancer.computeCost(clusterState, Double.MAX_VALUE);
      double curOverallCostInMetrics =
        dummyMetricsStochasticBalancer.getDummyCostsMap().get(metricRecordKey);
      assertEquals(curOverallCost, curOverallCostInMetrics, 0.001);
    }
  }
Data set for testLocalityCost: [test][0][0] = mapping of server to number of regions it hosts
[test][region + 1][0] = server that region is hosted on [test][region + 1][server + 1] =
locality for region on server
hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java