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

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

源代码1 项目: openjdk-jdk9   文件: CompletableFutureTest.java
/**
 * obtrudeValue forces completion with given value
 */
public void testObtrudeValue() {
    CompletableFuture<Integer> f = new CompletableFuture<>();
    checkIncomplete(f);
    assertTrue(f.complete(one));
    checkCompletedNormally(f, one);
    f.obtrudeValue(three);
    checkCompletedNormally(f, three);
    f.obtrudeValue(two);
    checkCompletedNormally(f, two);
    f = new CompletableFuture<>();
    f.obtrudeValue(three);
    checkCompletedNormally(f, three);
    f.obtrudeValue(null);
    checkCompletedNormally(f, null);
    f = new CompletableFuture<>();
    f.completeExceptionally(new CFException());
    f.obtrudeValue(four);
    checkCompletedNormally(f, four);
}
 
源代码2 项目: j2objc   文件: CompletableFutureTest.java
/**
 * obtrudeValue forces completion with given value
 */
public void testObtrudeValue() {
    CompletableFuture<Integer> f = new CompletableFuture<>();
    checkIncomplete(f);
    assertTrue(f.complete(one));
    checkCompletedNormally(f, one);
    f.obtrudeValue(three);
    checkCompletedNormally(f, three);
    f.obtrudeValue(two);
    checkCompletedNormally(f, two);
    f = new CompletableFuture<>();
    f.obtrudeValue(three);
    checkCompletedNormally(f, three);
    f.obtrudeValue(null);
    checkCompletedNormally(f, null);
    f = new CompletableFuture<>();
    f.completeExceptionally(new CFException());
    f.obtrudeValue(four);
    checkCompletedNormally(f, four);
}
 
源代码3 项目: 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);
}}
 
源代码4 项目: caffeine   文件: AsyncTest.java
@Test
public void getWhenSuccessful_success_async() {
  CompletableFuture<Integer> future = new CompletableFuture<Integer>();
  AtomicInteger result = new AtomicInteger();
  ConcurrentTestHarness.execute(() -> {
    result.set(1);
    result.set(Async.getWhenSuccessful(future));
  });
  Awaits.await().untilAtomic(result, is(1));
  future.obtrudeValue(2);
  Awaits.await().untilAtomic(result, is(2));
}
 
源代码5 项目: 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);
}}