@Test
  public void testRescheduleNoConcurrencyRun() throws Exception {
    Stoppable stop = new StoppableImplementation();
    Configuration conf = UTIL.getConfiguration();
    Path testDir = UTIL.getDataTestDir();
    FileSystem fs = UTIL.getTestFileSystem();
    fs.mkdirs(testDir);
    fs.createNewFile(new Path(testDir, "test"));
    String confKey = "hbase.test.cleaner.delegates";
    conf.set(confKey, GetConcurrency.class.getName());
    AtomicInteger maxConcurrency = new AtomicInteger();
    final AllValidPaths chore = new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir,
      confKey, POOL, ImmutableMap.of("maxConcurrency", maxConcurrency));
    try {
      SERVICE.scheduleChore(chore);
      for (int i = 0; i < 100; i++) {
        chore.triggerNow();
        Thread.sleep(5 + ThreadLocalRandom.current().nextInt(5));
      }
      Thread.sleep(1000);
      // set a barrier here to make sure that the previous runs are also finished
      assertFalse(chore.triggerCleanerNow().get());
      // make sure we do not have multiple cleaner runs at the same time
      assertEquals(1, maxConcurrency.get());
    } finally {
      chore.cancel();
    }
  }
The cleaner runs in a loop, where it first checks to see all the files under a directory can be
deleted. If they all can, then we try to delete the directory. However, a file may be added
that directory to after the original check. This ensures that we don't accidentally delete that
directory on and don't get spurious IOExceptions.
<p>
This was from HBASE-7465.
@throws Exception on failure
hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerChore.java