Skip to content

Commit

Permalink
Fixed Javadoc and add an eviction test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed May 18, 2020
1 parent eae5803 commit 1ea398c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface AsyncCache<K, V> {
*
* @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
Expand Down Expand Up @@ -119,10 +119,9 @@ CompletableFuture<V> 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<Map<K, V>> getAll(@NonNull Iterable<? extends @NonNull K> keys,
Expand Down Expand Up @@ -150,10 +149,9 @@ default CompletableFuture<Map<K, V>> getAll(@NonNull Iterable<? extends @NonNull
* @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<Map<K, V>> getAll(@NonNull Iterable<? extends @NonNull K> keys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public interface Cache<K, V> {
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public interface Policy<K, V> {
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -485,6 +487,23 @@ public void invalidateAll(Cache<String, List<Integer>> 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<Integer, Integer> cache, CacheContext context) {
List<Integer> 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<Integer> actual = ImmutableList.copyOf(
cache.policy().eviction().get().hottest(Integer.MAX_VALUE).keySet());
assertThat(actual, is(expected));
}

/* --------------- Policy: IsWeighted --------------- */

@Test(dataProvider = "caches")
Expand Down
2 changes: 1 addition & 1 deletion gradle/codeQuality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ afterEvaluate {
it.enabled = System.properties.containsKey('spotbugs')
it.group = 'SpotBugs'
it.reports {
html { enabled = true }
html.enabled = true
}
}
}
Expand Down

0 comments on commit 1ea398c

Please sign in to comment.