@Test
  public void testConnectionExhaustion() throws IOException {
    int MAX_INSTANCES = 5; // fails on iteration 3 if zk connections leak
    for (int i = 0; i < MAX_INSTANCES; i++) {
      final int iter = i;
      try {
        openCloseTableOutputFormat(iter);
      } catch (Exception e) {
        LOG.error("Exception encountered", e);
        fail("Failed on iteration " + i);
      }
    }
  }
Open and close a TableOutputFormat. The closing the RecordWriter should release HBase
Connection (ZK) resources, and will throw exception if they are exhausted.
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestTableOutputFormatConnectionExhaust.java