@Test
  public void testTempAndCommit() throws IOException {
    Path rootDir = TEST_UTIL.getDataTestDirOnTestFS("testTempAndCommit");
    FileSystem fs = TEST_UTIL.getTestFileSystem();
    Configuration conf = TEST_UTIL.getConfiguration();

    // Create a Region
    String familyName = "cf";

    RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
    HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs, rootDir, hri);
    StoreContext storeContext = StoreContext.getBuilder()
      .withColumnFamilyDescriptor(ColumnFamilyDescriptorBuilder.of(familyName))
      .withFamilyStoreDirectoryPath(
        new Path(regionFs.getTableDir(), new Path(hri.getRegionNameAsString(), familyName)))
      .withRegionFileSystem(regionFs).build();
    StoreFileTracker sft = StoreFileTrackerFactory.create(conf, false, storeContext);
    // New region, no store files
    List<StoreFileInfo> storeFiles = sft.load();
    assertEquals(0, storeFiles != null ? storeFiles.size() : 0);

    // Create a new file in temp (no files in the family)
    Path buildPath = regionFs.createTempName();
    fs.createNewFile(buildPath);
    storeFiles = sft.load();
    assertEquals(0, storeFiles != null ? storeFiles.size() : 0);

    // commit the file
    Path dstPath = regionFs.commitStoreFile(familyName, buildPath);
    storeFiles = sft.load();
    assertEquals(0, storeFiles != null ? storeFiles.size() : 0);
    assertFalse(fs.exists(buildPath));

    fs.delete(rootDir, true);
  }
a mock fs which throws exception for first 3 times, and then process the call (returns the
excepted result).
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionFileSystem.java