Java Code Examples for java.util.concurrent.CompletableFuture#obtrudeException()
The following examples show how to use
java.util.concurrent.CompletableFuture#obtrudeException() .
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: AsyncTest.java From caffeine with Apache License 2.0 | 6 votes |
@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())); }
Example 2
Source File: CompletableFutureTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 3
Source File: CompletableFutureTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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); }}