private void createAndTestSnapshot(final SnapshotFileCache cache,
    final SnapshotMock.SnapshotBuilder builder, final boolean tmp, final boolean removeOnExit,
    boolean setFolderTime) throws IOException {
    List<Path> files = new ArrayList<>();
    for (int i = 0; i < 3; ++i) {
      for (Path filePath : builder.addRegion()) {
        if (tmp) {
          // We should be able to find all the files while the snapshot creation is in-progress
          CommonFSUtils.logFileSystemState(fs, rootDir, LOG);
          assertFalse("Cache didn't find " + filePath,
            contains(getNonSnapshotFiles(cache, filePath), filePath));
        }
        files.add(filePath);
      }
    }

    // Finalize the snapshot
    if (!tmp) {
      builder.commit();
    }

    if (setFolderTime) {
      fs.setTimes(snapshotDir, 0, -1);
    }

    // Make sure that all files are still present
    for (Path path : files) {
      assertFalse("Cache didn't find " + path, contains(getNonSnapshotFiles(cache, path), path));
    }

    CommonFSUtils.logFileSystemState(fs, rootDir, LOG);
    if (removeOnExit) {
      LOG.debug("Deleting snapshot.");
      builder.getSnapshotsDir().getFileSystem(conf).delete(builder.getSnapshotsDir(), true);
      CommonFSUtils.logFileSystemState(fs, rootDir, LOG);

      // then trigger a refresh
      cache.triggerCacheRefreshForTesting();
      // and not it shouldn't find those files
      for (Path filePath : files) {
        assertTrue("Cache found '" + filePath + "', but it shouldn't have.",
          contains(getNonSnapshotFiles(cache, filePath), filePath));

      }
    }
  }
Test that we correctly reload the cache, filter directories, etc.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java