private BucketCache testEvictOrphans(long orphanEvictionGracePeriod) throws Exception {
    Path validFile = new Path(HBASE_TESTING_UTILITY.getDataTestDir(), "testEvictOrphans-valid");
    Path orphanFile = new Path(HBASE_TESTING_UTILITY.getDataTestDir(), "testEvictOrphans-orphan");
    Map<String, HRegion> onlineRegions = new HashMap<>();
    List<HStore> stores = new ArrayList<>();
    Collection<HStoreFile> storeFiles = new ArrayList<>();
    HRegion mockedRegion = mock(HRegion.class);
    HStore mockedStore = mock(HStore.class);
    HStoreFile mockedStoreFile = mock(HStoreFile.class);
    when(mockedStoreFile.getPath()).thenReturn(validFile);
    storeFiles.add(mockedStoreFile);
    when(mockedStore.getStorefiles()).thenReturn(storeFiles);
    stores.add(mockedStore);
    when(mockedRegion.getStores()).thenReturn(stores);
    onlineRegions.put("mocked_region", mockedRegion);
    HBASE_TESTING_UTILITY.getConfiguration().setDouble(MIN_FACTOR_CONFIG_NAME, 0.99);
    HBASE_TESTING_UTILITY.getConfiguration().setDouble(ACCEPT_FACTOR_CONFIG_NAME, 1);
    HBASE_TESTING_UTILITY.getConfiguration().setDouble(EXTRA_FREE_FACTOR_CONFIG_NAME, 0.01);
    HBASE_TESTING_UTILITY.getConfiguration().setLong(BLOCK_ORPHAN_GRACE_PERIOD,
      orphanEvictionGracePeriod);
    BucketCache bucketCache = new BucketCache(ioEngineName, (constructedBlockSize + 1024) * 21,
      constructedBlockSize, new int[] { constructedBlockSize + 1024 }, 1, 1, null, 60 * 1000,
      HBASE_TESTING_UTILITY.getConfiguration(), onlineRegions);
    HFileBlockPair[] validBlockPairs =
      CacheTestUtils.generateBlocksForPath(constructedBlockSize, 10, validFile);
    HFileBlockPair[] orphanBlockPairs =
      CacheTestUtils.generateBlocksForPath(constructedBlockSize, 10, orphanFile);
    for (HFileBlockPair pair : validBlockPairs) {
      bucketCache.cacheBlockWithWait(pair.getBlockName(), pair.getBlock(), false, true);
    }
    waitUntilAllFlushedToBucket(bucketCache);
    assertEquals(10, bucketCache.getBackingMap().size());
    bucketCache.freeSpace("test");
    assertEquals(10, bucketCache.getBackingMap().size());
    for (HFileBlockPair pair : orphanBlockPairs) {
      bucketCache.cacheBlockWithWait(pair.getBlockName(), pair.getBlock(), false, true);
    }
    waitUntilAllFlushedToBucket(bucketCache);
    assertEquals(20, bucketCache.getBackingMap().size());
    bucketCache.freeSpace("test");
    return bucketCache;
  }
This test is for HBASE-26295, {@link BucketEntry} which is restored from a persistence file
could not be freed even if corresponding {@link HFileBlock} is evicted from
{@link BucketCache}.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java