@Test
  public void testTriggerCleaner() throws Exception {
    Stoppable stop = new StoppableImplementation();
    Configuration conf = UTIL.getConfiguration();
    Path testDir = UTIL.getDataTestDir();
    FileSystem fs = UTIL.getTestFileSystem();
    fs.mkdirs(testDir);
    String confKey = "hbase.test.cleaner.delegates";
    conf.set(confKey, AlwaysDelete.class.getName());
    final AllValidPaths chore =
      new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey, POOL);
    try {
      SERVICE.scheduleChore(chore);
      assertTrue(chore.triggerCleanerNow().get());
      chore.setEnabled(false);
      // should still runnable
      assertTrue(chore.triggerCleanerNow().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