Example usage for java.util.concurrent ExecutionException getCause

List of usage examples for java.util.concurrent ExecutionException getCause

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:mitm.common.util.KeyedBarrierTest.java

@Test
public void testTimeout() throws Exception {
    final long timeout = 100;

    final KeyedBarrier<String, Object> barrier = new KeyedBarrier<String, Object>(10);

    final long waitTime = 1000;

    final SleepingCallable callable1 = new SleepingCallable(waitTime);
    final SleepingCallable callable2 = new SleepingCallable(waitTime);

    try {/*from w w w.  j a v  a 2  s  .  co m*/
        Future<?> future1 = execute(barrier, "key", callable1, timeout);

        Future<?> future2 = execute(barrier, "key", callable2, timeout);

        future1.get();
        future2.get();

        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof KeyedBarrierTimeoutException);
    }
}

From source file:org.datacleaner.monitor.configuration.TenantContextFactoryImpl.java

public TenantContext getContext(String tenantId) {
    if (Strings.isNullOrEmpty(tenantId)) {
        throw new IllegalArgumentException("Tenant ID cannot be null or empty string");
    }//from  www .  j a v a 2  s  .  c om

    tenantId = getStandardizedTenantName(tenantId);

    try {
        return _contexts.get(tenantId);
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw new IllegalStateException(e);
    }
}

From source file:org.openhab.tools.analysis.utils.CachingHttpClient.java

/**
 * Makes an attempt to download a file only once,
 * subsequent calls will return the result of the first attempt
 * until the entry expires/*from ww w  . ja va2s  . co  m*/
 *
 * @param url the resource URL
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the URL is null
 * @return the requested object or null, if the first download attempt is unsuccessful
 */
public synchronized T get(URL url) throws IOException {
    if (url == null) {
        throw new IllegalArgumentException("URL must not be null");
    }

    Optional<byte[]> content = Optional.empty();
    try {
        content = cache.get(url, () -> Optional.of(getContent(url)));
    } catch (ExecutionException e) {
        cache.put(url, Optional.empty());
        throw new IOException("Unable to get " + url.toString(), e.getCause());
    }
    return content.isPresent() ? callback.transform(content.get()) : null;
}

From source file:org.apache.hadoop.hbase.client.TestAsyncSingleRequestRpcRetryingCaller.java

@Test
public void testMaxRetries() throws IOException, InterruptedException {
    try {//from ww  w  .  jav  a  2s  . co  m
        CONN.callerFactory.single().table(TABLE_NAME).row(ROW).operationTimeout(1, TimeUnit.DAYS).maxAttempts(3)
                .pause(10, TimeUnit.MILLISECONDS).action((controller, loc, stub) -> failedFuture()).call()
                .get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class));
    }
}

From source file:org.apache.hadoop.ipc.TestRPCServerShutdown.java

/**
 *  Verify the RPC server can shutdown properly when callQueue is full.
 *///from www .  jav a  2 s  .co m
@Test(timeout = 30000)
public void testRPCServerShutdown() throws Exception {
    final int numClients = 3;
    final List<Future<Void>> res = new ArrayList<Future<Void>>();
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);
    conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
    RPC.Builder builder = newServerBuilder(conf).setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
    final Server server = setupTestServer(builder);

    final TestRpcService proxy = getClient(addr, conf);
    try {
        // start a sleep RPC call to consume the only handler thread.
        // Start another sleep RPC call to make callQueue full.
        // Start another sleep RPC call to make reader thread block on CallQueue.
        for (int i = 0; i < numClients; i++) {
            res.add(executorService.submit(new Callable<Void>() {
                @Override
                public Void call() throws ServiceException, InterruptedException {
                    proxy.sleep(null, newSleepRequest(100000));
                    return null;
                }
            }));
        }
        while (server.getCallQueueLen() != 1 || countThreads(CallQueueManager.class.getName()) != 1
                || countThreads(PBServerImpl.class.getName()) != 1) {
            Thread.sleep(100);
        }
    } finally {
        try {
            stop(server, proxy);
            assertEquals("Not enough clients", numClients, res.size());
            for (Future<Void> f : res) {
                try {
                    f.get();
                    fail("Future get should not return");
                } catch (ExecutionException e) {
                    ServiceException se = (ServiceException) e.getCause();
                    assertTrue("Unexpected exception: " + se, se.getCause() instanceof IOException);
                    LOG.info("Expected exception", e.getCause());
                }
            }
        } finally {
            executorService.shutdown();
        }
    }
}

From source file:cc.kave.commons.pointsto.evaluation.cv.CVEvaluator.java

public double evaluate(SetProvider setProvider) {
    List<Future<Pair<Integer, Double>>> futures = new ArrayList<>(numFolds);
    double[] evaluationResults = new double[numFolds];

    for (int i = 0; i < numFolds; ++i) {
        futures.add(executorService.submit(new FoldEvaluation(i, setProvider)));
    }//from ww  w .j a va2 s . c  o m

    for (int i = 0; i < evaluationResults.length; ++i) {
        try {
            Pair<Integer, Double> result = futures.get(i).get();
            evaluationResults[i] = result.getValue();
            log("\tFold %d: %.3f\n", i + 1, evaluationResults[i]);
        } catch (ExecutionException e) {
            throw new RuntimeException(e.getCause());
        } catch (InterruptedException e) {
            e.printStackTrace();
            return Double.NaN;
        }

    }

    return StatUtils.mean(evaluationResults);
}

From source file:eu.tripledframework.demo.presentation.GlobalExceptionControllerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.CONFLICT)//from w  ww .  jav  a  2  s.c o m
@ResponseBody
public List<ErrorMessage> handleExecutionException(ExecutionException exception) throws Throwable {
    // we simply rethrow the cause.
    List<ErrorMessage> errorMessages = new ArrayList<>();
    if (exception.getCause() instanceof CommandValidationException) {
        errorMessages.addAll(handleValidationError((CommandValidationException) exception.getCause()));
    } else {
        LOGGER.error("The execution failed with an uncaught exception.", exception);
        errorMessages.add(new ErrorMessage("The execution failed with an uncaught exception."));
    }
    return errorMessages;
}

From source file:android.support.test.espresso.base.ThreadPoolExecutorExtractor.java

public ThreadPoolExecutor getAsyncTaskThreadPool() {
    FutureTask<Optional<ThreadPoolExecutor>> getTask = null;
    if (Build.VERSION.SDK_INT < 11) {
        getTask = new FutureTask<Optional<ThreadPoolExecutor>>(LEGACY_ASYNC_TASK_EXECUTOR);
    } else {/*from  w w w .  j av a 2s.c  o m*/
        getTask = new FutureTask<Optional<ThreadPoolExecutor>>(POST_HONEYCOMB_ASYNC_TASK_EXECUTOR);
    }

    try {
        return runOnMainThread(getTask).get().get();
    } catch (InterruptedException ie) {
        throw new RuntimeException("Interrupted while trying to get the async task executor!", ie);
    } catch (ExecutionException ee) {
        throw new RuntimeException(ee.getCause());
    }
}

From source file:de.metas.procurement.webui.MockedTestServerSync.java

public ListenableFuture<SyncWeeklySupply> getReportedWeeklySupply(final String uuid) {
    try {// ww w. j a va2 s.c o  m
        return weeklySupplies.get(uuid);
    } catch (final ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    }
}

From source file:de.metas.procurement.webui.MockedTestServerSync.java

private final void setReportedProductSupply(final SyncProductSupply syncProductSupply) {
    try {/*  w  w w  .j  av  a  2s .  co m*/
        final String uuid = syncProductSupply.getUuid();
        productSupplies.get(uuid).set(syncProductSupply);
    } catch (final ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    }
}