@Test public void asyncReload() throws Exception { CacheLoader<Integer, Integer> loader = key -> -key; CompletableFuture<?> future = loader.asyncReload(1, 2, Runnable::run); assertThat(future.get(), is(-1)); } }
@Test public void asyncReload_exception() throws Exception { for (Exception e : Arrays.asList(new Exception(), new RuntimeException())) { CacheLoader<Integer, Integer> loader = key -> { throw e; }; try { loader.asyncReload(1, 1, Runnable::run).join(); Assert.fail(); } catch (CompletionException ex) { assertThat(ex.getCause(), is(sameInstance(e))); } } }
@SuppressWarnings("NullAway") CompletableFuture<V> refresh = future.thenCompose(value -> cacheLoader.asyncReload(key, value, executor)); refreshFuture = refresh; } else { CompletableFuture<V> refresh = cacheLoader.asyncReload(key, oldValue, executor); refreshFuture = refresh;
CompletableFuture<V> refreshFuture = (oldValue == null) ? cacheLoader().asyncLoad(key, cache().executor()) : cacheLoader().asyncReload(key, oldValue, cache().executor()); refreshFuture.whenComplete((newValue, error) -> { long loadTime = cache().statsTicker().read() - startTime;
@SuppressWarnings("NullAway") CompletableFuture<V> refresh = future.thenCompose(value -> cacheLoader.asyncReload(key, value, executor)); refreshFuture = refresh; } else { CompletableFuture<V> refresh = cacheLoader.asyncReload(key, oldValue, executor); refreshFuture = refresh;
CompletableFuture<V> refreshFuture = (oldValue == null) ? cacheLoader().asyncLoad(key, cache().executor()) : cacheLoader().asyncReload(key, oldValue, cache().executor()); refreshFuture.whenComplete((newValue, error) -> { long loadTime = cache().statsTicker().read() - startTime;