@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = {Population.PARTIAL, Population.FULL}, expiry = CacheExpiry.ACCESS, removalListener = { Listener.DEFAULT, Listener.REJECTING }) public void youngest_order(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { Map<Integer, Integer> youngest = expireAfterVar.youngest(Integer.MAX_VALUE); Set<Integer> keys = new LinkedHashSet<>(ImmutableList.copyOf(youngest.keySet()).reverse()); assertThat(keys, contains(Iterables.toArray(keys, Integer.class))); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL, expiry = CacheExpiry.ACCESS) public void youngest_partial(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { int count = (int) context.initialSize() / 2; assertThat(expireAfterVar.youngest(count).size(), is(count)); }
@CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) @Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class) public void youngest_unmodifiable(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { expireAfterVar.youngest(Integer.MAX_VALUE).clear();; }
@CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) @Test(dataProvider = "caches", expectedExceptions = IllegalArgumentException.class) public void youngest_negative(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { expireAfterVar.youngest(-1); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) public void youngest_snapshot(Cache<Integer, Integer> cache, CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { Map<Integer, Integer> youngest = expireAfterVar.youngest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(youngest, is(equalTo(context.original()))); } }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) public void youngest_zero(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { assertThat(expireAfterVar.youngest(0), is(emptyMap())); }