From 1ea398c2f222b39acdc1c4317634a0176494052c Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sun, 17 May 2020 23:57:46 -0700 Subject: [PATCH] Fixed Javadoc and add an eviction test case --- .../benmanes/caffeine/cache/AsyncCache.java | 16 +++++++--------- .../github/benmanes/caffeine/cache/Cache.java | 4 ++-- .../benmanes/caffeine/cache/Policy.java | 4 ++-- .../benmanes/caffeine/cache/EvictionTest.java | 19 +++++++++++++++++++ gradle/codeQuality.gradle | 2 +- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java index 843118bf0e..308ddeddc0 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java @@ -47,7 +47,7 @@ public interface AsyncCache { * * @param key key whose associated value is to be returned * @return the current (existing or computed) future value to which the specified key is mapped, - * or {@code null} if this map contains no mapping for the key + * or {@code null} if this cache contains no mapping for the key * @throws NullPointerException if the specified key is null */ @Nullable @@ -119,10 +119,9 @@ CompletableFuture get(@NonNull K key, * @return the future containing an unmodifiable mapping of keys to values for the specified keys * in this cache * @throws NullPointerException if the specified collection is null or contains a null element, or - * if the future returned by the {@link AsyncCacheLoader} is null - * @throws RuntimeException or Error if the {@link AsyncCacheLoader} does so, if - * {@link AsyncCacheLoader#asyncLoadAll} returns {@code null}, or fails when constructing - * the future, in which case the mapping is left unestablished + * if the future returned by the mappingFunction is null + * @throws RuntimeException or Error if the mappingFunction does so, in which case the mapping is + * left unestablished */ @NonNull default CompletableFuture> getAll(@NonNull Iterable keys, @@ -150,10 +149,9 @@ default CompletableFuture> getAll(@NonNull Iterable> getAll(@NonNull Iterable keys, diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java index c6da398095..e6f487faea 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java @@ -45,8 +45,8 @@ public interface Cache { * cached value for the {@code key}. * * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or {@code null} if this map contains no - * mapping for the key + * @return the value to which the specified key is mapped, or {@code null} if this cache contains + * no mapping for the key * @throws NullPointerException if the specified key is null */ @Nullable diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java index b5dd02a055..1d4b15966f 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java @@ -51,8 +51,8 @@ public interface Policy { * expiration time, or triggering a refresh. * * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or {@code null} if this map contains no - * mapping for the key + * @return the value to which the specified key is mapped, or {@code null} if this cache contains + * no mapping for the key * @throws NullPointerException if the specified key is null */ @Nullable diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java index 122bc8dbc1..032e6a977b 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java @@ -27,6 +27,8 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.verify; import java.util.Collections; @@ -485,6 +487,23 @@ public void invalidateAll(Cache> cache, assertThat(eviction.weightedSize().getAsLong(), is(0L)); } + /* --------------- Policy --------------- */ + + @Test(dataProvider = "caches") + @CacheSpec(implementation = Implementation.Caffeine, + population = Population.FULL, maximumSize = Maximum.UNREACHABLE) + public void getIfPresentQuietly(Cache cache, CacheContext context) { + List expected = ImmutableList.copyOf( + cache.policy().eviction().get().hottest(Integer.MAX_VALUE).keySet()); + assertThat(cache.policy().getIfPresentQuietly(context.firstKey()), is(not(nullValue()))); + assertThat(cache.policy().getIfPresentQuietly(context.middleKey()), is(not(nullValue()))); + assertThat(cache.policy().getIfPresentQuietly(context.lastKey()), is(not(nullValue()))); + + List actual = ImmutableList.copyOf( + cache.policy().eviction().get().hottest(Integer.MAX_VALUE).keySet()); + assertThat(actual, is(expected)); + } + /* --------------- Policy: IsWeighted --------------- */ @Test(dataProvider = "caches") diff --git a/gradle/codeQuality.gradle b/gradle/codeQuality.gradle index 59b53992d7..b2c25ae9f0 100644 --- a/gradle/codeQuality.gradle +++ b/gradle/codeQuality.gradle @@ -181,7 +181,7 @@ afterEvaluate { it.enabled = System.properties.containsKey('spotbugs') it.group = 'SpotBugs' it.reports { - html { enabled = true } + html.enabled = true } } }