@Test
  public void testFractionUpdate() {
    // Cache has 4 entries; 2 for LFU and 2 for MFU
    // key is considered as MFU, if its accessCount > 1
    mCache =
        createDummyAdaptiveCountingMemoryCache(
            mParamsSupplier,
            mCacheTrimStrategy,
            mValueDescriptor,
            100,
            1,
            2,
            initialLFUCacheFractionPromil);

    // insert item1 to LFU
    CloseableReference<Integer> originalRef1 = newReference(10);
    CloseableReference<Integer> valueRef1 = mCache.cache(KEYS[1], originalRef1);
    originalRef1.close();
    valueRef1.close();
    assertLFUExclusivelyOwned(KEYS[1], 10);

    // insert item2 to LFU
    CloseableReference<Integer> originalRef2 = newReference(20);
    CloseableReference<Integer> valueRef2 = mCache.cache(KEYS[2], originalRef2);
    originalRef2.close();
    valueRef2.close();
    assertLFUExclusivelyOwned(KEYS[1], 10);
    assertLFUExclusivelyOwned(KEYS[2], 20);

    // insert item3 to LFU, item1 will be evicted from LFU and inserted to the LFU ghost list
    CloseableReference<Integer> originalRef3 = newReference(30);
    CloseableReference<Integer> valueRef3 = mCache.cache(KEYS[3], originalRef3);
    originalRef3.close();
    valueRef3.close();
    assertLFUExclusivelyOwned(KEYS[2], 20);
    assertLFUExclusivelyOwned(KEYS[3], 30);
    assertNotCached(KEYS[1], 10);
    assertKeyIsInLFUGhostList(KEYS[1], 1);
    assertEquals(mCache.mLFUFractionPromil, initialLFUCacheFractionPromil);

    // access item1, which was already evicted from LFU
    CloseableReference<Integer> valueRef1a = mCache.get(KEYS[1]);
    assertNull(valueRef1a);
    // checks if the LFU fraction has been increased by adativeRate value
    assertEquals(
        initialLFUCacheFractionPromil + mCache.mAdaptiveRatePromil, mCache.mLFUFractionPromil);

    // make item2 "frequently used" by accessing it more than mFrequentlyUsedThreshiold
    // notice, MFU max size is 1 now (LFU size is 3).
    CloseableReference<Integer> valueRef2a = mCache.get(KEYS[2]);
    valueRef2a.close();
    assertMFUExclusivelyOwned(KEYS[2], 20);

    // insert item4 to MFU, item2 will be evicted from MFU and inserted in the MFU ghost list
    CloseableReference<Integer> originalRef4 = newReference(40);
    CloseableReference<Integer> valueRef4 = mCache.cache(KEYS[4], originalRef4);
    CloseableReference<Integer> valueRef4a = mCache.get(KEYS[4]);
    originalRef4.close();
    valueRef4.close();
    valueRef4a.close();
    assertEquals(
        initialLFUCacheFractionPromil + mCache.mAdaptiveRatePromil, mCache.mLFUFractionPromil);
  }
This test maskes sure that the LFU cache fraction is being updated correctly when trying to
access a recently evicted key from LFU. Test: add 3 LFU items, the 1st item will be evicted and
inserted to the LFU ghost list (the LFU size is up to 2 keys). try to access the recently
evicted key and make sure that the LFU cache fraction is increased by the value of the
adaptiveRate.
imagepipeline-base/src/test/java/com/facebook/imagepipeline/cache/AbstractAdaptiveCountingMemoryCacheTest.java