Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.collect.Lists;
import com.google.common.testing.FakeTicker;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -230,15 +231,19 @@ public void testAsyncLoadingCacheWithExpireAfterWrite() throws InterruptedExcept
Assertions.assertTrue(futureValue.isDone());
Assertions.assertEquals("value1", futureValue.get().get().getValue());
Assertions.assertEquals(1, counter.get());
CompletableFuture<Optional<CacheValue>> cachedFuture = futureValue;
// advance 11 seconds to pass the refreshAfterWrite
ticker.advance(11, TimeUnit.SECONDS);
// trigger refresh
futureValue = loadingCache.get(1);
// refresh in background, so still get value1
Assertions.assertTrue(futureValue.isDone());
Assertions.assertEquals("value1", futureValue.get().get().getValue());
// sleep longer to wait for refresh
Thread.sleep(2500);
// Wait until the refresh is published to the cache instead of observing loader-side progress.
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
CompletableFuture<Optional<CacheValue>> refreshedFuture = loadingCache.get(1);
return refreshedFuture != cachedFuture && refreshedFuture.isDone();
});
futureValue = loadingCache.get(1);
Assertions.assertEquals("value1", futureValue.get().get().getValue());
// refreshed, so counter +1
Expand Down
Loading