use of com.github.benmanes.caffeine.cache.testing.CacheSpec in project caffeine by ben-manes.
the class EvictionTest method put_asyncWeight.
@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, maximumSize = Maximum.FULL, weigher = CacheWeigher.COLLECTION, population = Population.EMPTY, keys = ReferenceType.STRONG, values = ReferenceType.STRONG)
@SuppressWarnings("FutureReturnValueIgnored")
public void put_asyncWeight(AsyncLoadingCache<Integer, List<Integer>> cache, CacheContext context, Eviction<?, ?> eviction) {
AtomicBoolean ready = new AtomicBoolean();
AtomicBoolean done = new AtomicBoolean();
CompletableFuture<List<Integer>> valueFuture = CompletableFuture.supplyAsync(() -> {
Awaits.await().untilTrue(ready);
return ImmutableList.of(1, 2, 3, 4, 5);
});
valueFuture.whenComplete((r, e) -> done.set(true));
cache.put(context.absentKey(), valueFuture);
assertThat(eviction.weightedSize().getAsLong(), is(0L));
assertThat(cache.synchronous().estimatedSize(), is(1L));
ready.set(true);
Awaits.await().untilTrue(done);
Awaits.await().until(() -> eviction.weightedSize().getAsLong(), is(5L));
Awaits.await().until(() -> cache.synchronous().estimatedSize(), is(1L));
}
Aggregations