List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:co.cask.cdap.client.rest.RestStreamWriterTest.java
@Test public void testNotAuthorizedEmptyTokenStringWrite() throws IOException, InterruptedException { AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class); AccessToken accessToken = Mockito.mock(AccessToken.class); Mockito.when(authClient.getAccessToken()).thenReturn(accessToken); Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY); Mockito.when(accessToken.getTokenType()).thenReturn("Bearer"); streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build(); streamWriter = streamClient/*from w w w . j a v a 2s . c om*/ .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 testNotAuthorizedUnknownTokenStringWrite() throws IOException, InterruptedException { AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class); AccessToken accessToken = Mockito.mock(AccessToken.class); Mockito.when(authClient.getAccessToken()).thenReturn(accessToken); Mockito.when(accessToken.getValue()).thenReturn("test"); Mockito.when(accessToken.getTokenType()).thenReturn("Bearer"); streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build(); streamWriter = streamClient// w w w .j ava2 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:org.apache.commons.rng.examples.stress.RandomStressTester.java
/** * Creates the tasks and starts the processes. * * @param generators List of generators to be analyzed. * @param numConcurrentTasks Number of concurrent tasks. * Twice as many threads will be started: one thread for the RNG and one * for the analyzer.// w w w . j av a2 s. c om * @throws IOException if an error occurs when writing to the disk. */ private void run(Iterable<UniformRandomProvider> generators, int numConcurrentTasks) throws IOException { // Parallel execution. final ExecutorService service = Executors.newFixedThreadPool(numConcurrentTasks); // Placeholder (output will be "null"). final List<Future<?>> execOutput = new ArrayList<Future<?>>(); // Run tasks. int count = 0; for (UniformRandomProvider rng : generators) { final File output = new File(fileOutputPrefix + (++count)); final Runnable r = new Task(rng, output); execOutput.add(service.submit(r)); } // Wait for completion (ignoring return value). try { for (Future<?> f : execOutput) { try { f.get(); } catch (ExecutionException e) { System.err.println(e.getCause().getMessage()); } } } catch (InterruptedException ignored) { } // Terminate all threads. service.shutdown(); }
From source file:org.sonar.batch.scan.filesystem.FileIndexer.java
private void waitForTasksToComplete() { executorService.shutdown();/*from www . ja va 2 s .c o m*/ for (Future<Void> task : tasks) { try { task.get(); } catch (ExecutionException e) { // Unwrap ExecutionException throw e.getCause() instanceof RuntimeException ? (RuntimeException) e.getCause() : new IllegalStateException(e.getCause()); } catch (InterruptedException e) { throw new IllegalStateException(e); } } }
From source file:com.asakusafw.runtime.stage.temporary.TemporaryFileInputHelper.java
public synchronized Result getNextPage() throws IOException, InterruptedException { if (sawEof) { return new Result(null, positionInBlock, currentBlock, blockRest, null, true); }//www.j a v a 2 s. c om // if no any tasks were running, first we submit a new task for reading the next contents submitIfAvailable(); if (running == null) { throw new IllegalStateException(); } assert running != null; Result result; try { result = running.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw new IOException("Exception occurred while reading contents", cause); } else if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } throw new IllegalStateException(cause); } finally { running = null; } this.sawEof = result.sawEof; this.positionInBlock = result.positionInBlock; this.currentBlock = result.currentBlock; this.blockRest = result.blockRest; // submit a task for reading the successive page (only if available) submitIfAvailable(); return result; }
From source file:com.addthis.hydra.data.util.JSONFetcher.java
private byte[] retrieveBytes(String url) throws IOException { MutableInt retry = new MutableInt(0); try {//w w w .j a v a 2s . com return retryer.call(() -> request(url, retry)); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } catch (RetryException e) { throw new IOException("Max retries exceeded"); } }
From source file:org.apache.pulsar.client.impl.ProducerBuilderImpl.java
@Override public Producer<T> create() throws PulsarClientException { try {/* w ww . ja v a2s. c om*/ return createAsync().get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
From source file:org.apache.hadoop.hbase.client.TestAsyncNonMetaRegionLocator.java
@Test public void testNoTable() throws InterruptedException { for (RegionLocateType locateType : RegionLocateType.values()) { try {//from ww w. j av a 2 s.co m LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
From source file:org.apache.hadoop.hbase.client.TestAsyncNonMetaRegionLocator.java
@Test public void testDisableTable() throws IOException, InterruptedException { createSingleRegionTable();/*from w w w . j a v a2s . c om*/ TEST_UTIL.getAdmin().disableTable(TABLE_NAME); for (RegionLocateType locateType : RegionLocateType.values()) { try { LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
From source file:org.springframework.batch.support.transaction.ConcurrentTransactionAwareProxyTests.java
@Ignore("This fails too often and is a false negative") @Test/*from w w w.ja v a 2 s .c o m*/ public void testConcurrentTransactionalList() throws Exception { List<String> list = TransactionAwareProxyFactory.createTransactionalList(); try { testList(list, true); fail("Expected ExecutionException or AssertionError (but don't panic if it didn't happen: it probably just means we got lucky for a change)"); } catch (ExecutionException e) { String message = e.getCause().getMessage(); assertTrue("Wrong message: " + message, message.startsWith("Lost update")); } catch (AssertionError e) { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.startsWith("Wrong number of results")); } }