@Override public boolean isCompletedExceptionally() { return delegate.isCompletedExceptionally(); }
private static boolean isSuccessfullyCompleted(CompletableFuture<?> connectFuture) { return connectFuture.isDone() && !connectFuture.isCompletedExceptionally(); }
private static boolean isSuccessfullyCompleted(CompletableFuture<?> connectFuture) { return connectFuture.isDone() && !connectFuture.isCompletedExceptionally(); }
public SocketAddress getRemoteAddress() { if (remoteAddress.isDone() && !remoteAddress.isCompletedExceptionally()) { return remoteAddress.join(); } return null; }
/** Returns if the future has successfully completed. */ static boolean isReady(@Nullable CompletableFuture<?> future) { return (future != null) && future.isDone() && !future.isCompletedExceptionally() && (future.join() != null); }
private boolean atLeastOneFailed(Map<RedisClusterNode, CompletionStage<?>> executions) { return executions.values().stream() .anyMatch(completionStage -> completionStage.toCompletableFuture().isCompletedExceptionally()); }
@SuppressWarnings("unchecked") public static void linkFuturesOnError(CompletableFuture source, CompletableFuture target) { if (source != null && (!source.isDone() || source.isCompletedExceptionally())) { ((CompletableFuture<Object>) source).whenComplete((r, e) -> { if (e != null) { target.completeExceptionally(e); } }); } }
public static boolean isSuccessFuture(CompletableFuture future) { return future.isDone() && !future.isCompletedExceptionally() && !future.isCancelled(); }
/** * Verifies that the {@link CompletableFuture} is not completed normally (i.e. incomplete, failed or cancelled). * <p> * Assertion will pass : * <pre><code class='java'> assertThat(new CompletableFuture()).isNotCompleted();</code></pre> * * Assertion will fail : * <pre><code class='java'> assertThat(CompletableFuture.completedFuture("something")).isNotCompleted();</code></pre> * * @return this assertion object. */ public SELF isNotCompleted() { isNotNull(); if (actual.isDone() && !actual.isCompletedExceptionally()) throwAssertionError(shouldNotBeCompleted(actual)); return myself; }
/** * Verifies that the {@link CompletableFuture} is completed normally (i.e.{@link CompletableFuture#isDone() done} * but not {@link CompletableFuture#isCompletedExceptionally() completed exceptionally}). * <p> * Assertion will pass : * <pre><code class='java'> assertThat(CompletableFuture.completedFuture("something")).isCompleted();</code></pre> * * Assertion will fail : * <pre><code class='java'> assertThat(new CompletableFuture()).isCompleted();</code></pre> * * @return this assertion object. */ public SELF isCompleted() { isNotNull(); if (!actual.isDone() || actual.isCompletedExceptionally()) throwAssertionError(shouldBeCompleted(actual)); return myself; }
private static void assertFutureIsCompleted(CompletableFuture<Void> future) { assertThat(future.isDone(), is(true)); assertThat(future.isCancelled(), is(false)); assertThat(future.isCompletedExceptionally(), is(false)); }
/** * Verifies that the {@link CompletableFuture} is not completed exceptionally. * <p> * Assertion will pass : * <pre><code class='java'> assertThat(CompletableFuture.completedFuture("something")).isNotCompletedExceptionally();</code></pre> * * Assertion will fail : * <pre><code class='java'> CompletableFuture future = new CompletableFuture(); * future.completeExceptionally(new RuntimeException()); * assertThat(future).isNotCompletedExceptionally();</code></pre> * * @return this assertion object. * * @see CompletableFuture#isCompletedExceptionally() */ public SELF isNotCompletedExceptionally() { isNotNull(); if (actual.isCompletedExceptionally()) throwAssertionError(shouldNotHaveCompletedExceptionally(actual)); return myself; }
@CheckNoWriter @Test(dataProvider = "caches") @CacheSpec(loader = Loader.EXCEPTIONAL) public void get_absent_failure(AsyncLoadingCache<Integer, Integer> cache, CacheContext context) { CompletableFuture<Integer> future = cache.get(context.absentKey()); assertThat(future.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(context.absentKey()), is(nullValue())); }
private void checkMap(UnboundedLocalCache<K, V> map, DescriptionBuilder desc) { if (map.isEmpty()) { desc.expectThat("empty map", map, emptyMap()); } map.data.forEach((key, value) -> { desc.expectThat("non null key", key, is(not(nullValue()))); desc.expectThat("non null value", value, is(not(nullValue()))); if (value instanceof CompletableFuture<?>) { CompletableFuture<?> future = (CompletableFuture<?>) value; boolean success = future.isDone() && !future.isCompletedExceptionally(); desc.expectThat("future is done", success, is(true)); desc.expectThat("not null value", future.getNow(null), is(not(nullValue()))); } }); }
@Test(expected = Exception.class) public void error() throws Exception { CompletableFuture<Integer> f = Mono.<Integer>error(new Exception("test")).toFuture(); assertThat(f.isDone()).isTrue(); assertThat(f.isCompletedExceptionally()).isTrue(); f.get(); }
@CacheSpec @CheckNoWriter @Test(dataProvider = "caches") public void getBiFunc_absent_failure_after(AsyncCache<Integer, Integer> cache, CacheContext context) { CompletableFuture<Integer> failedFuture = new CompletableFuture<>(); Integer key = context.absentKey(); CompletableFuture<Integer> valueFuture = cache.get(key, (k, executor) -> failedFuture); failedFuture.completeExceptionally(new IllegalStateException()); assertThat(context, both(hasMissCount(1)).and(hasHitCount(0))); assertThat(context, both(hasLoadSuccessCount(0)).and(hasLoadFailureCount(1))); assertThat(valueFuture.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(key), is(nullValue())); }
@CacheSpec @CheckNoWriter @Test(dataProvider = "caches") public void getBiFunc_absent_failure_before(AsyncCache<Integer, Integer> cache, CacheContext context) { CompletableFuture<Integer> failedFuture = new CompletableFuture<>(); failedFuture.completeExceptionally(new IllegalStateException()); Integer key = context.absentKey(); CompletableFuture<Integer> valueFuture = cache.get(key, (k, executor) -> failedFuture); assertThat(context, both(hasMissCount(1)).and(hasHitCount(0))); assertThat(context, both(hasLoadSuccessCount(0)).and(hasLoadFailureCount(1))); assertThat(valueFuture.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(key), is(nullValue())); }
@CacheSpec @CheckNoWriter @Test(dataProvider = "caches") public void getFunc_absent_failure(AsyncCache<Integer, Integer> cache, CacheContext context) { CompletableFuture<Integer> valueFuture = cache.get(context.absentKey(), k -> { throw new IllegalStateException(); }); assertThat(context, both(hasMissCount(1)).and(hasHitCount(0))); assertThat(context, both(hasLoadSuccessCount(0)).and(hasLoadFailureCount(1))); assertThat(valueFuture.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(context.absentKey()), is(nullValue())); }
@CheckNoWriter @Test(dataProvider = "caches") @CacheSpec(loader = Loader.EXCEPTIONAL, executor = CacheExecutor.THREADED, executorFailure = ExecutorFailure.IGNORED) public void get_absent_failure_async(AsyncLoadingCache<Integer, Integer> cache, CacheContext context) throws InterruptedException { AtomicBoolean done = new AtomicBoolean(); Integer key = context.absentKey(); CompletableFuture<Integer> valueFuture = cache.get(key); valueFuture.whenComplete((r, e) -> done.set(true)); Awaits.await().untilTrue(done); Awaits.await().until(() -> !cache.synchronous().asMap().containsKey(context.absentKey())); Awaits.await().until(() -> context, both(hasMissCount(1)).and(hasHitCount(0))); Awaits.await().until(() -> context, both(hasLoadSuccessCount(0)).and(hasLoadFailureCount(1))); assertThat(valueFuture.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(key), is(nullValue())); }
@CheckNoWriter @Test(dataProvider = "caches") @CacheSpec(executor = CacheExecutor.THREADED, executorFailure = ExecutorFailure.IGNORED) public void getFunc_absent_failure_async(AsyncCache<Integer, Integer> cache, CacheContext context) { AtomicBoolean ready = new AtomicBoolean(); AtomicBoolean done = new AtomicBoolean(); CompletableFuture<Integer> valueFuture = cache.get(context.absentKey(), k -> { Awaits.await().untilTrue(ready); throw new IllegalStateException(); }); valueFuture.whenComplete((r, e) -> done.set(true)); ready.set(true); Awaits.await().untilTrue(done); Awaits.await().until(() -> !cache.synchronous().asMap().containsKey(context.absentKey())); Awaits.await().until(() -> context, both(hasMissCount(1)).and(hasHitCount(0))); Awaits.await().until(() -> context, both(hasLoadSuccessCount(0)).and(hasLoadFailureCount(1))); assertThat(valueFuture.isCompletedExceptionally(), is(true)); assertThat(cache.getIfPresent(context.absentKey()), is(nullValue())); }