@Test
  public void testReportBadSinkDownToZeroSinks() {
    List<ServerName> serverNames = Lists.newArrayList();
    int totalServers = 4;
    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 serverNameA = endpoint.getSinkServers().get(0);
    ServerName serverNameB = endpoint.getSinkServers().get(1);

    serverNames.remove(serverNameA);
    serverNames.remove(serverNameB);

    SinkPeer sinkPeerA = new SinkPeer(serverNameA, mock(AsyncRegionServerAdmin.class));
    SinkPeer sinkPeerB = new SinkPeer(serverNameB, mock(AsyncRegionServerAdmin.class));

    for (int i = 0; i <= HBaseReplicationEndpoint.DEFAULT_BAD_SINK_THRESHOLD; i++) {
      endpoint.reportBadSink(sinkPeerA);
      endpoint.reportBadSink(sinkPeerB);
    }

    // We've gone down to 0 good sinks, so the replication sinks
    // should have been refreshed now, so out of 4 servers, 2 are not considered as they are
    // reported as bad.
    expected =
      (int) ((totalServers - 2) * HBaseReplicationEndpoint.DEFAULT_REPLICATION_SOURCE_RATIO);
    assertEquals(expected, 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