@Override public void clear() { this.cache.invalidateAll(); }
@Override public void clear() { requireNotClosed(); cache.invalidateAll(); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, maximumSize = Maximum.FULL, weigher = CacheWeigher.COLLECTION, population = Population.EMPTY, keys = ReferenceType.STRONG, values = ReferenceType.STRONG) public void invalidateAll(Cache<String, List<Integer>> cache, CacheContext context, Eviction<?, ?> eviction) { cache.putAll(ImmutableMap.of("a", asList(1, 2, 3), "b", asList(1))); cache.invalidateAll(); assertThat(cache.estimatedSize(), is(0L)); assertThat(eviction.weightedSize().getAsLong(), is(0L)); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, initialCapacity = InitialCapacity.EXCESSIVE, maximumSize = Maximum.FULL) public void coldest_snapshot(Cache<Integer, Integer> cache, CacheContext context, Eviction<Integer, Integer> eviction) { Map<Integer, Integer> coldest = eviction.coldest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(coldest, is(equalTo(context.original()))); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, initialCapacity = InitialCapacity.EXCESSIVE, maximumSize = Maximum.FULL) public void hottest_snapshot(Cache<Integer, Integer> cache, CacheContext context, Eviction<Integer, Integer> eviction) { Map<Integer, Integer> hottest = eviction.hottest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(hottest, is(equalTo(context.original()))); } }
@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 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(population = { Population.PARTIAL, Population.FULL }) public void invalidateAll_partial(Cache<Integer, Integer> cache, CacheContext context) { List<Integer> keys = cache.asMap().keySet().stream() .filter(i -> ((i % 2) == 0)) .collect(Collectors.toList()); cache.invalidateAll(keys); assertThat(cache.estimatedSize(), is(context.initialSize() - keys.size())); assertThat(cache, hasRemovalNotifications(context, keys.size(), RemovalCause.EXPLICIT)); verifyWriter(context, (verifier, writer) -> { verifier.deletedAll(Maps.filterKeys(context.original(), Predicates.in(keys)), RemovalCause.EXPLICIT); }); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, refreshAfterWrite = Expire.ONE_MINUTE) public void youngest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @RefreshAfterWrite Expiration<Integer, Integer> refreshAfterWrite) { Map<Integer, Integer> youngest = refreshAfterWrite.youngest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(youngest, is(equalTo(context.original()))); } }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expireAfterAccess = Expire.ONE_MINUTE) public void oldest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @ExpireAfterAccess Expiration<Integer, Integer> expireAfterAccess) { Map<Integer, Integer> oldest = expireAfterAccess.oldest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(oldest, is(equalTo(context.original()))); }
@CheckNoWriter @CheckNoStats @Test(dataProvider = "caches") @CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING }) public void invalidateAll_empty(Cache<Integer, Integer> cache, CacheContext context) { cache.invalidateAll(new HashSet<>()); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, refreshAfterWrite = Expire.ONE_MINUTE) public void oldest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @RefreshAfterWrite Expiration<Integer, Integer> refreshAfterWrite) { Map<Integer, Integer> oldest = refreshAfterWrite.oldest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(oldest, is(equalTo(context.original()))); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expireAfterWrite = Expire.ONE_MINUTE) public void youngest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @ExpireAfterWrite Expiration<Integer, Integer> expireAfterWrite) { Map<Integer, Integer> youngest = expireAfterWrite.youngest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(youngest, is(equalTo(context.original()))); } }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expireAfterAccess = Expire.ONE_MINUTE) public void youngest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @ExpireAfterAccess Expiration<Integer, Integer> expireAfterAccess) { Map<Integer, Integer> youngest = expireAfterAccess.youngest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(youngest, is(equalTo(context.original()))); } }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, expireAfterWrite = Expire.ONE_MINUTE) public void oldest_snapshot(Cache<Integer, Integer> cache, CacheContext context, @ExpireAfterWrite Expiration<Integer, Integer> expireAfterWrite) { Map<Integer, Integer> oldest = expireAfterWrite.oldest(Integer.MAX_VALUE); cache.invalidateAll(); assertThat(oldest, is(equalTo(context.original()))); }
@CheckNoStats @Test(dataProvider = "caches", expectedExceptions = DeleteException.class) @CacheSpec(implementation = Implementation.Caffeine, keys = ReferenceType.STRONG, population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }, compute = Compute.SYNC, writer = Writer.EXCEPTIONAL, removalListener = Listener.REJECTING) public void invalidateAll_full_writerFails(Cache<Integer, Integer> cache, CacheContext context) { try { cache.invalidateAll(); } finally { assertThat(cache.asMap(), equalTo(context.original())); } }
@CacheSpec @CheckNoWriter @CheckNoStats @Test(dataProvider = "caches", expectedExceptions = NullPointerException.class) public void invalidateAll_null(Cache<Integer, Integer> cache, CacheContext context) { cache.invalidateAll(null); }
@CheckNoStats @Test(dataProvider = "caches", expectedExceptions = DeleteException.class) @CacheSpec(implementation = Implementation.Caffeine, keys = ReferenceType.STRONG, population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }, compute = Compute.SYNC, writer = Writer.EXCEPTIONAL, removalListener = Listener.REJECTING) public void invalidateAll_partial_writerFails(Cache<Integer, Integer> cache, CacheContext context) { try { cache.invalidateAll(context.firstMiddleLastKeys()); } finally { assertThat(cache.asMap(), equalTo(context.original())); } }
@CacheSpec @Test(dataProvider = "caches") public void invalidateAll(Cache<Integer, Integer> cache, CacheContext context) { cache.invalidateAll(); assertThat(cache.estimatedSize(), is(0L)); assertThat(cache, hasRemovalNotifications(context, context.original().size(), RemovalCause.EXPLICIT)); verifyWriter(context, (verifier, writer) -> { verifier.deletedAll(context.original(), RemovalCause.EXPLICIT); }); }
@Test(dataProvider = "caches") @CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }) public void invalidateAll_full(Cache<Integer, Integer> cache, CacheContext context) { cache.invalidateAll(context.original().keySet()); assertThat(cache.estimatedSize(), is(0L)); assertThat(cache, hasRemovalNotifications(context, context.original().size(), RemovalCause.EXPLICIT)); verifyWriter(context, (verifier, writer) -> { verifier.deletedAll(context.original(), RemovalCause.EXPLICIT); }); }