Java Code Examples for java.util.concurrent.CompletionException#getCause()
The following examples show how to use
java.util.concurrent.CompletionException#getCause() .
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: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 6 votes |
@Test(expected = TestException.class) public void testDelayedExceptionalPipeline() throws Throwable { try { final AsyncIterator<Long> concat = AsyncIterator.concat( Arrays.asList( AsyncIterator.repeat(0L).take(3), AsyncIterator.<Long>error(testException), AsyncIterator.repeat(1L).take(3)) .iterator()); this.terminal .apply(this.intermediate.apply(concat)) .toCompletableFuture() .join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 2
Source File: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 6 votes |
@Test(expected = TestException.class) public void testExceptionalPipelineShortcircuit() throws Throwable { try { final AsyncIterator<Long> concat = AsyncIterator.concat( Arrays.asList( AsyncIterator.repeat(0L).take(3), AsyncIterator.<Long>error(testException), AsyncIterator.repeat(1L)) // infinite .iterator()); this.terminal.apply(this.intermediate.apply(concat)).toCompletableFuture().join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 3
Source File: ExceptionAssert.java From symbol-sdk-java with Apache License 2.0 | 6 votes |
/** * Asserts that the execution of consumer throws a completion exception wrapping an exception of * the specific class. * * @param consumer The consumer. * @param exceptionClass The expected exception class. */ public static void assertThrowsCompletionException( final Consumer<Void> consumer, final Class<?> exceptionClass) { try { consumer.accept(null); } catch (final CompletionException completionEx) { final Throwable ex = completionEx.getCause(); if (ex.getClass() == exceptionClass) { return; } Assertions.fail(String.format("unexpected exception of type %s was thrown", ex.getClass())); } Assertions.fail(String.format("expected exception of type %s was not thrown", exceptionClass)); }
Example 4
Source File: ConversationsTest.java From botbuilder-java with MIT License | 6 votes |
@Test public void GetConversationMembersWithInvalidConversationId() { ConversationParameters createMessage = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); }}; ConversationResourceResponse conversation = connector.getConversations().createConversation(createMessage).join(); try { List<ChannelAccount> members = connector.getConversations().getConversationMembers(conversation.getId().concat("M")).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals("ServiceError", ((ErrorResponseException)e.getCause()).body().getError().getCode()); Assert.assertTrue(((ErrorResponseException)e.getCause()).body().getError().getMessage().contains("The specified channel was not found")); } else { throw e; } } }
Example 5
Source File: AsyncIteratorCloseTest.java From java-async-util with Apache License 2.0 | 6 votes |
@Test(expected = IllegalStateException.class) public void testNextFutureAfterCloseIllegal() throws Throwable { final AsyncIterator<Long> it = AsyncIterator.range(0, 15); final AsyncIterator<Long> ahead = it.thenComposeAhead(i -> StageSupport.completedStage(i + 1), 5); final CompletionStage<Either<AsyncIterator.End, Long>> first = ahead.nextStage(); TestUtil.join(first); TestUtil.join(ahead.close()); try { TestUtil.join(ahead.nextStage()); } catch (final CompletionException e) { throw e.getCause(); } }
Example 6
Source File: CompletionExceptionMapper.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Response toResponse(CompletionException exception) { Throwable cause = exception.getCause(); if (cause != null) { ExceptionMapper<Throwable> mapper = (ExceptionMapper<Throwable>) providers.getExceptionMapper(cause.getClass()); if (mapper != null) return mapper.toResponse(cause); if (cause instanceof WebApplicationException) return ((WebApplicationException) cause).getResponse(); } System.err.println("Could not find mapper for completion exception"); exception.printStackTrace(); return Response.serverError().build(); }
Example 7
Source File: GcsWriteTest.java From gcp-ingestion with Mozilla Public License 2.0 | 5 votes |
@Test public void failsOnInsertErrors() { final Throwable expect = new RuntimeException("fail"); doThrow(expect).when(storage).create(any(BlobInfo.class), any(byte[].class), any()); Throwable cause = null; try { output.apply(EMPTY_MESSAGE).join(); } catch (CompletionException e) { cause = e.getCause(); } assertEquals(expect, cause); }
Example 8
Source File: ConversationsTest.java From botbuilder-java with MIT License | 5 votes |
@Test public void SendToConversationWithInvalidConversationId() { Activity activity = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setName("activity"); setText("TEST Send to Conversation"); }}; ConversationParameters createMessage = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); }}; ConversationResourceResponse conversation = connector.getConversations().createConversation(createMessage).join(); try { ResourceResponse response = connector.getConversations().sendToConversation(conversation.getId().concat("M"), activity).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals("ServiceError", ((ErrorResponseException)e.getCause()).body().getError().getCode()); Assert.assertTrue(((ErrorResponseException)e.getCause()).body().getError().getMessage().contains("The specified channel was not found")); } else { throw e; } } }
Example 9
Source File: ConversationsTest.java From botbuilder-java with MIT License | 5 votes |
@Test public void GetConversationPagedMembersWithInvalidConversationId() { Activity activity = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setText("TEST Get Activity Members"); }}; ConversationParameters createMessage = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); setActivity(activity); }}; ConversationResourceResponse conversation = connector.getConversations().createConversation(createMessage).join(); try { connector.getConversations().getConversationPagedMembers(conversation.getId().concat("M")).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals(400, ((ErrorResponseException)e.getCause()).response().code()); } else { throw e; } } }
Example 10
Source File: ConversationsTest.java From botbuilder-java with MIT License | 5 votes |
@Test public void CreateConversationWithInvalidBot() { Activity activity = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setText("TEST Create Conversation"); }}; bot.setId("invalid-id"); ConversationParameters params = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); setActivity(activity); }}; try { ConversationResourceResponse result = connector.getConversations().createConversation(params).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals("ServiceError", ((ErrorResponseException)e.getCause()).body().getError().getCode()); Assert.assertTrue(((ErrorResponseException)e.getCause()).body().getError().getMessage().startsWith("Invalid userId")); } else { throw e; } } }
Example 11
Source File: AsyncIteratorTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = NullPointerException.class) public void testFlattenAheadNull() throws Throwable { final CompletionStage<Either<End, Object>> future = AsyncIterator .range(0, 15) .thenFlattenAhead(i -> StageSupport.completedStage(null), 5) .nextStage(); try { TestUtil.join(future); } catch (final CompletionException e) { throw e.getCause(); } }
Example 12
Source File: ConversationsTest.java From botbuilder-java with MIT License | 5 votes |
@Test public void UpdateActivityWithInvalidConversationId() { Activity activity = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setText("TEST Send to Conversation"); }}; ConversationParameters createMessage = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); }}; ConversationResourceResponse conversation = connector.getConversations().createConversation(createMessage).join(); ResourceResponse response = connector.getConversations().sendToConversation(conversation.getId(), activity).join(); activity.setId(response.getId()); activity.setText("TEST Update Activity"); try { ResourceResponse updateResponse = connector.getConversations().updateActivity("B21S8SG7K:T03CWQ0QB", response.getId(), activity).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals("ServiceError", ((ErrorResponseException)e.getCause()).body().getError().getCode()); Assert.assertTrue(((ErrorResponseException)e.getCause()).body().getError().getMessage().contains("Invalid ConversationId")); } else { throw e; } } }
Example 13
Source File: AsyncIteratorTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = NullPointerException.class) public void testFindNull() throws Throwable { try { AsyncIterator.<Integer>once(null).find(i -> i == null).toCompletableFuture().join().get(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 14
Source File: AsyncTrampolineTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = NullPointerException.class) public void testNullBooleanThrowsException() throws Throwable { try { AsyncTrampoline.asyncWhile(() -> null).toCompletableFuture().join(); } catch (CompletionException e) { throw e.getCause(); } }
Example 15
Source File: SaltService.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * This is a helper for keeping the old exception behaviour until * all code makes proper use of the async api. * @param fn function to execute and adapt. * @param <T> result of fn * @return the result of fn * @throws SaltException if an exception gets thrown */ public static <T> T adaptException(CompletionStage<T> fn) throws SaltException { try { return fn.toCompletableFuture().join(); } catch (CompletionException e) { Throwable cause = e.getCause(); if (cause instanceof SaltException) { throw (SaltException) cause; } else { throw new SaltException(cause); } } }
Example 16
Source File: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = TestException.class) public void testDelayedException() throws Throwable { try { final AsyncIterator<Integer> concat = AsyncIterator.concat( Arrays.asList( AsyncIterator.repeat(0).take(3), AsyncIterator.<Integer>error(testException), AsyncIterator.repeat(1).take(3)) .iterator()); this.fn.apply(concat).toCompletableFuture().join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 17
Source File: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = TestException.class) public void testErrorTerminalShortCircuit() throws Throwable { try { this.fn.apply(AsyncIterator.repeat(0L)).toCompletableFuture().join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 18
Source File: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = TestException.class) public void testExceptionPropagation() throws Throwable { try { final AsyncIterator<Long> concat = AsyncIterator.concat( Arrays.asList( AsyncIterator.repeat(0L).take(3), AsyncIterator.<Long>error(testException), AsyncIterator.repeat(1L).take(3)) .iterator()); this.fn.apply(concat).consume().toCompletableFuture().join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 19
Source File: AsyncIteratorParameterizedTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test(expected = TestException.class) public void testExceptionalPipeline() throws Throwable { try { this.terminal .apply(this.intermediate.apply(AsyncIterator.error(testException))) .toCompletableFuture() .join(); } catch (final CompletionException e) { throw e.getCause(); } }
Example 20
Source File: ConversationsTest.java From botbuilder-java with MIT License | 5 votes |
@Test public void ReplyToActivityWithInvalidConversationId() { Activity activity = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setText("TEST Send to Conversation"); }}; Activity reply = new Activity(ActivityTypes.MESSAGE) {{ setRecipient(user); setFrom(bot); setText("TEST Reply to Activity"); }}; ConversationParameters createMessage = new ConversationParameters() {{ setMembers(Collections.singletonList(user)); setBot(bot); }}; ConversationResourceResponse conversation = connector.getConversations().createConversation(createMessage).join(); ResourceResponse response = connector.getConversations().sendToConversation(conversation.getId(), activity).join(); try { ResourceResponse replyResponse = connector.getConversations().replyToActivity(conversation.getId().concat("M"), response.getId(), reply).join(); Assert.fail("expected exception did not occur."); } catch (CompletionException e) { if (e.getCause() instanceof ErrorResponseException) { Assert.assertEquals("ServiceError", ((ErrorResponseException)e.getCause()).body().getError().getCode()); Assert.assertTrue(((ErrorResponseException)e.getCause()).body().getError().getMessage().contains("The specified channel was not found")); } else { throw e; } } }