Java Code Examples for java.util.concurrent.CompletableFuture#obtrudeValue()

The following examples show how to use java.util.concurrent.CompletableFuture#obtrudeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}}
 
Example 4
Source File: AsyncTest.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 5
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}}