private void doBulkloadWithoutRetry(Path dir) throws Exception {
    BulkLoadHFilesTool h = new BulkLoadHFilesTool(conf) {

      @Override
      protected void bulkLoadPhase(AsyncClusterConnection conn, TableName tableName,
        Deque<LoadQueueItem> queue, Multimap<ByteBuffer, LoadQueueItem> regionGroups,
        boolean copyFiles, Map<LoadQueueItem, ByteBuffer> item2RegionMap) throws IOException {
        super.bulkLoadPhase(conn, tableName, queue, regionGroups, copyFiles, item2RegionMap);
        throw new MyExceptionToAvoidRetry(); // throw exception to avoid retry
      }
    };
    try {
      h.bulkLoad(TABLE, dir);
      Assert.fail("MyExceptionToAvoidRetry is expected");
    } catch (MyExceptionToAvoidRetry e) { // expected
    }
  }
A trick is used to make sure server-side failures( if any ) not being covered up by a client
retry. Since BulkLoadHFilesTool.bulkLoad keeps performing bulkload calls as long as the HFile
queue is not empty, while server-side exceptions in the doAs block do not lead to a client
exception, a bulkload will always succeed in this case by default, thus client will never be
aware that failures have ever happened . To avoid this kind of retry , a
MyExceptionToAvoidRetry exception is thrown after bulkLoadPhase finished and caught silently
outside the doBulkLoad call, so that the bulkLoadPhase would be called exactly once, and
server-side failures, if any ,can be checked via data.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSecureBulkLoadManager.java