List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip.java
@Test public void invoke_invalidRequest_error() throws InterruptedException, TimeoutException, ExecutionException { RemoteInvoker invoker = HttpRestInvoker.host("localhost").port(23332).ssl(false).build(); try {//ww w. java 2 s . c o m CompletableFuture<Res> future = invoker.invoke(new Invalid(25), Res.class); exception.expect(ExecutionException.class); future.get(500, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { EncodingException cause = (EncodingException) ex.getCause(); assertEquals( "Failed to encode JSON: No serializer found for class io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip$Invalid and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )", cause.getMessage()); throw ex; } finally { invoker.close().get(500, TimeUnit.MILLISECONDS); } }
From source file:org.apache.tez.runtime.library.common.shuffle.impl.Shuffle.java
/** * Waits for the Shuffle and Merge to complete, and returns an iterator over the input. * @return an iterator over the fetched input. * @throws IOException//from w w w.j a v a 2 s.co m * @throws InterruptedException */ public TezRawKeyValueIterator waitForInput() throws IOException, InterruptedException { Preconditions.checkState(runShuffleFuture != null, "waitForInput can only be called after run"); TezRawKeyValueIterator kvIter; try { kvIter = runShuffleFuture.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } else { throw new TezUncheckedException("Unexpected exception type while running Shuffle and Merge", cause); } } return kvIter; }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testUnexpectedBodyStringWrite() throws Exception { streamWriter = streamClient/*from w w w. jav a2s. com*/ .createWriter(TestUtils.SUCCESS_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write("Unexpected body", Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testBadRequestStringWrite() throws Exception { streamWriter = streamClient/*from ww w . j a v a2s .c om*/ .createWriter(TestUtils.BAD_REQUEST_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testNotFoundStringWrite() throws Exception { streamWriter = streamClient//from w w w. j a v a 2 s. c o m .createWriter(TestUtils.NOT_FOUND_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testConflictStringWrite() throws Exception { streamWriter = streamClient// w w w .j av a 2s . com .createWriter(TestUtils.CONFLICT_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testNotAuthorizedStringWrite() throws IOException, InterruptedException { streamWriter = streamClient/*from w ww. jav a2 s .c o m*/ .createWriter(TestUtils.AUTH_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testForbiddenStringWrite() throws IOException, InterruptedException { streamWriter = streamClient//from w w w . j a v a 2 s.c o m .createWriter(TestUtils.FORBIDDEN_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testNotAllowedStringWrite() throws IOException, InterruptedException { streamWriter = streamClient//from ww w . j a v a 2s. c om .createWriter(TestUtils.NOT_ALLOWED_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX); try { streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get(); } catch (ExecutionException e) { assertEquals(HttpFailureException.class, e.getCause().getClass()); } }
From source file:org.apache.whirr.actions.ByonClusterAction.java
@Override protected void doAction(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException, InterruptedException { final Collection<Future<ExecResponse>> futures = Sets.newHashSet(); List<NodeMetadata> nodes = Lists.newArrayList(); List<NodeMetadata> usedNodes = Lists.newArrayList(); int numberAllocated = 0; Set<Instance> allInstances = Sets.newLinkedHashSet(); for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) { final ClusterSpec clusterSpec = entry.getValue().getClusterSpec(); final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder(); if (statementBuilder.isEmpty()) { continue; // skip }/*from w w w . ja va 2 s. c o m*/ final ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); final ComputeService computeService = computeServiceContext.getComputeService(); LoginCredentials credentials = LoginCredentials.builder().user(clusterSpec.getClusterUser()) .privateKey(clusterSpec.getPrivateKey()).build(); final RunScriptOptions options = overrideLoginCredentials(credentials); if (numberAllocated == 0) { for (ComputeMetadata compute : computeService.listNodes()) { if (!(compute instanceof NodeMetadata)) { throw new IllegalArgumentException("Not an instance of NodeMetadata: " + compute); } nodes.add((NodeMetadata) compute); } } int num = entry.getKey().getNumberOfInstances(); Predicate<NodeMetadata> unused = not(in(usedNodes)); Predicate<NodeMetadata> instancePredicate = new TagsPredicate( StringUtils.split(entry.getKey().getHardwareId())); List<NodeMetadata> templateNodes = Lists.newArrayList(filter(nodes, and(unused, instancePredicate))); if (templateNodes.size() < num) { LOG.warn("Not enough nodes available for template " + StringUtils.join(entry.getKey().getRoles(), "+")); } templateNodes = templateNodes.subList(0, num); usedNodes.addAll(templateNodes); numberAllocated = usedNodes.size(); Set<Instance> templateInstances = getInstances(credentials, entry.getKey().getRoles(), templateNodes); allInstances.addAll(templateInstances); for (final Instance instance : templateInstances) { futures.add(runStatementOnInstanceInCluster(statementBuilder, instance, clusterSpec, options)); } } for (Future<ExecResponse> future : futures) { try { future.get(); } catch (ExecutionException e) { throw new IOException(e.getCause()); } } if (action.equals(ClusterActionHandler.BOOTSTRAP_ACTION)) { Cluster cluster = new Cluster(allInstances); for (ClusterActionEvent event : eventMap.values()) { event.setCluster(cluster); } } }