@Before
  public void configureDirectoriesAndLinks() throws IOException {
    conf = TEST_UTIL.getConfiguration();
    CommonFSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir());
    conf.set(HFileCleaner.MASTER_HFILE_CLEANER_PLUGINS, HFileLinkCleaner.class.getName());
    rootDir = CommonFSUtils.getRootDir(conf);
    fs = FileSystem.get(conf);

    tableName = TableName.valueOf(name.getMethodName());
    tableLinkName = TableName.valueOf(name.getMethodName() + "-link");
    hfileName = "1234567890";
    familyName = "cf";

    hri = RegionInfoBuilder.newBuilder(tableName).build();
    hriLink = RegionInfoBuilder.newBuilder(tableLinkName).build();

    archiveDir = HFileArchiveUtil.getArchivePath(conf);
    archiveStoreDir =
      HFileArchiveUtil.getStoreArchivePath(conf, tableName, hri.getEncodedName(), familyName);

    // Create hfile /hbase/table-link/region/cf/getEncodedName.HFILE(conf);
    familyPath = getFamilyDirPath(archiveDir, tableName, hri.getEncodedName(), familyName);
    fs.mkdirs(familyPath);
    hfilePath = new Path(familyPath, hfileName);
    fs.createNewFile(hfilePath);

    HRegionFileSystem regionFS = HRegionFileSystem.create(conf, fs,
      CommonFSUtils.getTableDir(rootDir, tableLinkName), hriLink);
    StoreFileTracker sft = StoreFileTrackerFactory.create(conf, true,
      StoreContext.getBuilder()
        .withFamilyStoreDirectoryPath(new Path(regionFS.getRegionDir(), familyName))
        .withColumnFamilyDescriptor(ColumnFamilyDescriptorBuilder.of(familyName))
        .withRegionFileSystem(regionFS).build());
    createLink(sft, true);

    // Initialize cleaner
    conf.setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, TTL);
    Server server = new DummyServer();
    cleaner = new HFileCleaner(1000, server, conf, fs, archiveDir, POOL);
  }
Test the HFileLink Cleaner. HFiles with links cannot be deleted until a link is present.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java