@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = {Population.PARTIAL, Population.FULL}, expiry = CacheExpiry.ACCESS, removalListener = { Listener.DEFAULT, Listener.REJECTING }) public void oldest_order(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { Map<Integer, Integer> oldest = expireAfterVar.oldest(Integer.MAX_VALUE); assertThat(oldest.keySet(), contains(context.original().keySet().toArray(new Integer[0]))); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL, expiry = CacheExpiry.ACCESS) public void oldest_partial(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { int count = (int) context.initialSize() / 2; assertThat(expireAfterVar.oldest(count).size(), is(count)); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) public void oldest_snapshot(Cache<Integer, Integer> cache, CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { Map<Integer, Integer> oldest = expireAfterVar.oldest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(oldest, is(equalTo(context.original()))); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) public void oldest_zero(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { assertThat(expireAfterVar.oldest(0), is(emptyMap())); }
@CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) @Test(dataProvider = "caches", expectedExceptions = IllegalArgumentException.class) public void oldest_negative(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { expireAfterVar.oldest(-1); }
@CacheSpec(implementation = Implementation.Caffeine, expiry = CacheExpiry.ACCESS) @Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class) public void oldest_unmodifiable(CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { expireAfterVar.oldest(Integer.MAX_VALUE).clear(); }