@Test
  public void testBalancerDecisions() {
    conf.setBoolean("hbase.master.balancer.decision.buffer.enabled", true);
    MasterServices services = mock(MasterServices.class);
    when(services.getConfiguration()).thenReturn(conf);
    MasterClusterInfoProvider provider = new MasterClusterInfoProvider(services);
    loadBalancer.setClusterInfoProvider(provider);
    loadBalancer.onConfigurationChange(conf);
    float minCost = conf.getFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.05f);
    float slop = conf.getFloat(HConstants.LOAD_BALANCER_SLOP_KEY, 0.2f);
    conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 1.0f);
    conf.setFloat(HConstants.LOAD_BALANCER_SLOP_KEY, -1f);
    try {
      // Test with/without per table balancer.
      boolean[] perTableBalancerConfigs = { true, false };
      for (boolean isByTable : perTableBalancerConfigs) {
        conf.setBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable);
        loadBalancer.onConfigurationChange(conf);
        for (int[] mockCluster : clusterStateMocks) {
          Map<ServerName, List<RegionInfo>> servers = mockClusterServers(mockCluster);
          Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
            (Map) mockClusterServersWithTables(servers);
          List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
          boolean emptyPlans = plans == null || plans.isEmpty();
          Assert.assertTrue(emptyPlans || needsBalanceIdleRegion(mockCluster));
        }
      }
      final NamedQueueGetRequest namedQueueGetRequest = new NamedQueueGetRequest();
      namedQueueGetRequest.setNamedQueueEvent(BalancerDecisionDetails.BALANCER_DECISION_EVENT);
      namedQueueGetRequest
        .setBalancerDecisionsRequest(MasterProtos.BalancerDecisionsRequest.getDefaultInstance());
      NamedQueueGetResponse namedQueueGetResponse =
        provider.getNamedQueueRecorder().getNamedQueueRecords(namedQueueGetRequest);
      List<RecentLogs.BalancerDecision> balancerDecisions =
        namedQueueGetResponse.getBalancerDecisions();
      MasterProtos.BalancerDecisionsResponse response = MasterProtos.BalancerDecisionsResponse
        .newBuilder().addAllBalancerDecision(balancerDecisions).build();
      List<LogEntry> balancerDecisionRecords = ProtobufUtil.getBalancerDecisionEntries(response);
      Assert.assertTrue(balancerDecisionRecords.size() > 160);
    } finally {
      // reset config
      conf.unset(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE);
      conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", minCost);
      conf.setFloat(HConstants.LOAD_BALANCER_SLOP_KEY, slop);
      loadBalancer.onConfigurationChange(conf);
    }
  }
Test BalancerDecision ring buffer using namedQueue interface
hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerDecision.java