List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:com.smartling.cms.gateway.client.CmsGatewayClientTest.java
@Test public void failsOnExceptionInUpload() throws Exception { Future<ResponseStatus<Void>> future = onUploadResponse(500, "{\"response\":{\"code\":\"GENERAL_ERROR\",\"messages\":[\"some error message\"]}}"); try {/* w w w . j a va 2s . co m*/ future.get(); } catch (ExecutionException e) { CmsGatewayClientException clientException = (CmsGatewayClientException) e.getCause(); assertThat(clientException.getMessage(), containsString("some error message")); } }
From source file:com.hortonworks.streamline.streams.metrics.storm.topology.StormTopologyMetricsImpl.java
private Map<String, ?> getTopologyInfo(String topologyId, String asUser) { LOG.debug("[START] getTopologyInfo - topology id: {}, asUser: {}", topologyId, asUser); Stopwatch stopwatch = Stopwatch.createStarted(); try {/*from ww w . j a va 2 s. c o m*/ Map<String, ?> responseMap; try { responseMap = topologyRetrieveCache.get(new ImmutablePair<>(topologyId, asUser)); } catch (ExecutionException e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } catch (UncheckedExecutionException e) { if (e.getCause() != null) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e); } } LOG.debug("[END] getTopologyInfo - topology id: {}, elapsed: {} ms", topologyId, stopwatch.elapsed(TimeUnit.MILLISECONDS)); return responseMap; } finally { stopwatch.stop(); } }
From source file:org.apache.tez.runtime.library.common.shuffle.orderedgrouped.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 va 2 s .c o m * @throws InterruptedException */ public TezRawKeyValueIterator waitForInput() throws IOException, InterruptedException, TezException { Preconditions.checkState(runShuffleFuture != null, "waitForInput can only be called after run"); TezRawKeyValueIterator kvIter = null; try { kvIter = runShuffleFuture.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); handleThrowable(cause); } if (isShutDown.get()) { throw new InputAlreadyClosedException(); } if (throwable != null) { handleThrowable(throwable); } return kvIter; }
From source file:com.hortonworks.streamline.streams.metrics.storm.topology.StormTopologyMetricsImpl.java
private Map<String, ?> getComponentInfo(String topologyId, String componentId, String asUser) { LOG.debug("[START] getComponentInfo - topology id: {}, component id: {}, asUser: {}", topologyId, componentId, asUser);/* w w w . ja v a 2 s. c o m*/ Stopwatch stopwatch = Stopwatch.createStarted(); try { Map<String, ?> responseMap; try { responseMap = componentRetrieveCache .get(new ImmutablePair<>(new ImmutablePair<>(topologyId, componentId), asUser)); } catch (ExecutionException e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } catch (UncheckedExecutionException e) { if (e.getCause() != null) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e); } } LOG.debug("[END] getComponentInfo - topology id: {}, component id: {}, elapsed: {} ms", topologyId, componentId, stopwatch.elapsed(TimeUnit.MILLISECONDS)); return responseMap; } finally { stopwatch.stop(); } }
From source file:com.cloudera.livy.rsc.rpc.TestRpc.java
@Test public void testBadHello() throws Exception { RpcServer server = autoClose(new RpcServer(emptyConfig)); RpcServer.ClientCallback callback = mock(RpcServer.ClientCallback.class); server.registerClient("client", "newClient", callback); Future<Rpc> clientRpcFuture = Rpc.createClient(emptyConfig, server.getEventLoopGroup(), "localhost", server.getPort(), "client", "wrongClient", new TestDispatcher()); try {// w w w . j ava2 s . c o m autoClose(clientRpcFuture.get(10, TimeUnit.SECONDS)); fail("Should have failed to create client with wrong secret."); } catch (ExecutionException ee) { // On failure, the SASL handler will throw an exception indicating that the SASL // negotiation failed. assertTrue("Unexpected exception: " + ee.getCause(), ee.getCause() instanceof SaslException); } verify(callback, never()).onNewClient(any(Rpc.class)); }
From source file:gobblin.hive.HiveRegister.java
/** * Wait till all registration requested submitted via {@link #register(HiveSpec)} to finish. * * @throws IOException if any registration failed or was interrupted. *//* w ww.ja va 2 s .co m*/ @Override public void close() throws IOException { try { for (Map.Entry<String, Future<Void>> entry : this.futures.entrySet()) { try { entry.getValue().get(); } catch (ExecutionException ee) { throw new IOException("Failed to finish registration for " + entry.getKey(), ee.getCause()); } } } catch (InterruptedException e) { throw new IOException(e); } finally { ExecutorsUtils.shutdownExecutorService(this.executor, Optional.of(log)); } }
From source file:com.cloudera.livy.client.local.rpc.TestRpc.java
@Test public void testBadHello() throws Exception { RpcServer server = autoClose(new RpcServer(emptyConfig)); Future<Rpc> serverRpcFuture = server.registerClient("client", "newClient", new TestDispatcher()); NioEventLoopGroup eloop = new NioEventLoopGroup(); Future<Rpc> clientRpcFuture = Rpc.createClient(emptyConfig, eloop, "localhost", server.getPort(), "client", "wrongClient", new TestDispatcher()); try {//from w w w. j a v a 2s . c om autoClose(clientRpcFuture.get(10, TimeUnit.SECONDS)); fail("Should have failed to create client with wrong secret."); } catch (ExecutionException ee) { // On failure, the SASL handler will throw an exception indicating that the SASL // negotiation failed. assertTrue("Unexpected exception: " + ee.getCause(), ee.getCause() instanceof SaslException); } serverRpcFuture.cancel(true); }
From source file:org.apache.hadoop.hbase.ipc.AsyncRpcClient.java
/** * Make a call, passing <code>param</code>, to the IPC server running at * <code>address</code> which is servicing the <code>protocol</code> protocol, * with the <code>ticket</code> credentials, returning the value. * Throws exceptions if there are network problems or if the remote code * threw an exception.//from w ww . ja v a2 s . c o m * * @param ticket Be careful which ticket you pass. A new user will mean a new Connection. * {@link org.apache.hadoop.hbase.security.UserProvider#getCurrent()} makes a new * instance of User each time so will be a new Connection each time. * @return A pair with the Message response and the Cell data (if any). * @throws InterruptedException if call is interrupted * @throws java.io.IOException if a connection failure is encountered */ @Override protected Pair<Message, CellScanner> call(PayloadCarryingRpcController pcrc, Descriptors.MethodDescriptor md, Message param, Message returnType, User ticket, InetSocketAddress addr) throws IOException, InterruptedException { if (pcrc == null) { pcrc = new PayloadCarryingRpcController(); } final AsyncRpcChannel connection = createRpcChannel(md.getService().getName(), addr, ticket); Promise<Message> promise = connection.callMethod(md, pcrc, param, returnType); long timeout = pcrc.hasCallTimeout() ? pcrc.getCallTimeout() : 0; try { Message response = timeout > 0 ? promise.get(timeout, TimeUnit.MILLISECONDS) : promise.get(); return new Pair<>(response, pcrc.cellScanner()); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw new IOException(e.getCause()); } } catch (TimeoutException e) { throw new CallTimeoutException(promise.toString()); } }
From source file:org.sonarqube.tests.analysis.IssuesModeTest.java
private void runConcurrentIssues(final String workDirPath) throws Exception { // Install sonar-runner in advance to avoid concurrent unzip issues FileSystem fileSystem = orchestrator.getConfiguration().fileSystem(); new SonarScannerInstaller(fileSystem).install(Version.create(SonarScanner.DEFAULT_SCANNER_VERSION), fileSystem.workspace(), true); final int nThreads = 3; ExecutorService executorService = Executors.newFixedThreadPool(nThreads); List<Callable<BuildResult>> tasks = new ArrayList<>(); final File homeDir = temp.newFolder(); for (int i = 0; i < nThreads; i++) { tasks.add(() -> {/*from w w w .j av a 2 s . co m*/ SonarScanner scanner = configureScannerIssues("shared/xoo-sample", homeDir, "sonar.it.enableWaitingSensor", "true", "sonar.working.directory", workDirPath); return orchestrator.executeBuild(scanner); }); } boolean expectedError = false; for (Future<BuildResult> result : executorService.invokeAll(tasks)) { try { result.get(); } catch (ExecutionException e) { if (e.getCause() instanceof BuildFailureException) { BuildFailureException bfe = (BuildFailureException) e.getCause(); assertThat(bfe.getResult().getLogs()) .contains("Another SonarQube analysis is already in progress for this project"); expectedError = true; } else { throw e; } } } if (!expectedError) { fail("At least one of the threads should have failed"); } }
From source file:it.analysis.IssuesModeTest.java
private void runConcurrentIssues(final String workDirPath) throws Exception { // Install sonar-runner in advance to avoid concurrent unzip issues FileSystem fileSystem = orchestrator.getConfiguration().fileSystem(); new SonarScannerInstaller(fileSystem).install(Version.create(SonarScanner.DEFAULT_SCANNER_VERSION), fileSystem.workspace(), true); final int nThreads = 3; ExecutorService executorService = Executors.newFixedThreadPool(nThreads); List<Callable<BuildResult>> tasks = new ArrayList<>(); final File homeDir = temp.newFolder(); for (int i = 0; i < nThreads; i++) { tasks.add(new Callable<BuildResult>() { public BuildResult call() throws Exception { SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.it.enableWaitingSensor", "true", "sonar.working.directory", workDirPath); return orchestrator.executeBuild(runner); }// ww w.j a v a 2 s . c o m }); } boolean expectedError = false; for (Future<BuildResult> result : executorService.invokeAll(tasks)) { try { result.get(); } catch (ExecutionException e) { if (e.getCause() instanceof BuildFailureException) { BuildFailureException bfe = (BuildFailureException) e.getCause(); assertThat(bfe.getResult().getLogs()) .contains("Another SonarQube analysis is already in progress for this project"); expectedError = true; } else { throw e; } } } if (!expectedError) { fail("At least one of the threads should have failed"); } }