@Test
  public void testReportBadSinkPastThreshold() {
    List<ServerName> serverNames = Lists.newArrayList();
    int totalServers = 30;
    for (int i = 0; i < totalServers; i++) {
      serverNames.add(mock(ServerName.class));
    }
    ((DummyHBaseReplicationEndpoint) endpoint).setRegionServers(serverNames);
    endpoint.chooseSinks();
    // Sanity check
    int expected = (int) (totalServers * HBaseReplicationEndpoint.DEFAULT_REPLICATION_SOURCE_RATIO);
    assertEquals(expected, endpoint.getNumSinks());

    ServerName badSinkServer0 = endpoint.getSinkServers().get(0);
    SinkPeer sinkPeer = new SinkPeer(badSinkServer0, mock(AsyncRegionServerAdmin.class));
    for (int i = 0; i <= HBaseReplicationEndpoint.DEFAULT_BAD_SINK_THRESHOLD; i++) {
      endpoint.reportBadSink(sinkPeer);
    }
    // Reporting a bad sink more than the threshold count should remove it
    // from the list of potential sinks
    assertEquals(expected - 1, endpoint.getNumSinks());

    // now try a sink that has some successes
    ServerName badSinkServer1 = endpoint.getSinkServers().get(0);
    sinkPeer = new SinkPeer(badSinkServer1, mock(AsyncRegionServerAdmin.class));
    for (int i = 0; i < HBaseReplicationEndpoint.DEFAULT_BAD_SINK_THRESHOLD; i++) {
      endpoint.reportBadSink(sinkPeer);
    }
    endpoint.reportSinkSuccess(sinkPeer); // one success
    endpoint.reportBadSink(sinkPeer);
    // did not remove the sink, since we had one successful try
    assertEquals(expected - 1, endpoint.getNumSinks());

    for (int i = 0; i < HBaseReplicationEndpoint.DEFAULT_BAD_SINK_THRESHOLD - 1; i++) {
      endpoint.reportBadSink(sinkPeer);
    }
    // still not remove, since the success reset the counter
    assertEquals(expected - 1, endpoint.getNumSinks());
    endpoint.reportBadSink(sinkPeer);
    // but we exhausted the tries
    assertEquals(expected - 2, endpoint.getNumSinks());
  }
Once a SinkPeer has been reported as bad more than BAD_SINK_THRESHOLD times, it should not be
replicated to anymore.
hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestHBaseReplicationEndpoint.java