java.util.concurrent.CompletableFuture#obtrudeException ( )源码实例Demo

下面列出了java.util.concurrent.CompletableFuture#obtrudeException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: caffeine   文件: AsyncTest.java
@Test(dataProvider = "unsuccessful")
public void getWhenSuccessful_fails(CompletableFuture<?> future) {
  if ((future != null) && !future.isDone()) {
    AtomicInteger result = new AtomicInteger();
    ConcurrentTestHarness.execute(() -> {
      result.set(1);
      Object value = Async.getWhenSuccessful(future);
      result.set((value == null) ? 2 : 3);
    });
    Awaits.await().untilAtomic(result, is(1));
    future.obtrudeException(new IllegalStateException());
    Awaits.await().untilAtomic(result, is(not(1)));
    assertThat(result.get(), is(2));
  }
  assertThat(Async.getWhenSuccessful(future), is(nullValue()));
}
 
源代码2 项目: openjdk-jdk9   文件: CompletableFutureTest.java
/**
 * obtrudeException forces completion with given exception
 */
public void testObtrudeException() {
    for (Integer v1 : new Integer[] { 1, null })
{
    CFException ex;
    CompletableFuture<Integer> f;

    f = new CompletableFuture<>();
    assertTrue(f.complete(v1));
    for (int i = 0; i < 2; i++) {
        f.obtrudeException(ex = new CFException());
        checkCompletedExceptionally(f, ex);
    }

    f = new CompletableFuture<>();
    for (int i = 0; i < 2; i++) {
        f.obtrudeException(ex = new CFException());
        checkCompletedExceptionally(f, ex);
    }

    f = new CompletableFuture<>();
    f.completeExceptionally(ex = new CFException());
    f.obtrudeValue(v1);
    checkCompletedNormally(f, v1);
    f.obtrudeException(ex = new CFException());
    checkCompletedExceptionally(f, ex);
    f.completeExceptionally(new CFException());
    checkCompletedExceptionally(f, ex);
    assertFalse(f.complete(v1));
    checkCompletedExceptionally(f, ex);
}}
 
源代码3 项目: j2objc   文件: CompletableFutureTest.java
/**
 * obtrudeException forces completion with given exception
 */
public void testObtrudeException() {
    for (Integer v1 : new Integer[] { 1, null })
{
    CFException ex;
    CompletableFuture<Integer> f;

    f = new CompletableFuture<>();
    assertTrue(f.complete(v1));
    for (int i = 0; i < 2; i++) {
        f.obtrudeException(ex = new CFException());
        checkCompletedExceptionally(f, ex);
    }

    f = new CompletableFuture<>();
    for (int i = 0; i < 2; i++) {
        f.obtrudeException(ex = new CFException());
        checkCompletedExceptionally(f, ex);
    }

    f = new CompletableFuture<>();
    f.completeExceptionally(ex = new CFException());
    f.obtrudeValue(v1);
    checkCompletedNormally(f, v1);
    f.obtrudeException(ex = new CFException());
    checkCompletedExceptionally(f, ex);
    f.completeExceptionally(new CFException());
    checkCompletedExceptionally(f, ex);
    assertFalse(f.complete(v1));
    checkCompletedExceptionally(f, ex);
}}