From e5e9bc3cf4d30decd1b8f95df0b4d4eb90bb6c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allan=20Rodri=CC=81guez?= Date: Sat, 24 Feb 2024 15:48:42 -0800 Subject: [PATCH] When `AsyncCacheLoader.asyncLoadAll` returns excess keys, wait for all keys to be added to the cache before returning requested keys Fixes #1409. --- .../com/github/benmanes/caffeine/cache/LocalAsyncCache.java | 3 +-- .../github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java index a228fcf4b1..367398d459 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java @@ -144,8 +144,7 @@ default CompletableFuture> getAll(Iterable keys, try { var loader = mappingFunction.apply( Collections.unmodifiableSet(proxies.keySet()), cache().executor()); - loader.whenComplete(completer); - return composeResult(futures); + return loader.whenComplete(completer).thenCompose(ignored -> composeResult(futures)); } catch (Throwable t) { completer.accept(/* result */ null, t); throw t; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java index a56e9ea963..0fab3cded7 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java @@ -319,7 +319,8 @@ public void getAll_present_partial(AsyncLoadingCache cache, CacheConte @Test(dataProvider = "caches") @CacheSpec(loader = Loader.BULK_NEGATIVE_EXCEEDS, - removalListener = { Listener.DISABLED, Listener.REJECTING }) + removalListener = { Listener.DISABLED, Listener.REJECTING }, + executor = { CacheExecutor.DIRECT, CacheExecutor.DEFAULT }) public void getAll_exceeds(AsyncLoadingCache cache, CacheContext context) { var result = cache.getAll(context.absentKeys()).join();