Example usage for java.util.concurrent ExecutionException printStackTrace

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

Introduction

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

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java

public void testShutdown() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS);

    try {//w  w w  . j  av a 2s  .  com
        // Make sure a normal request will succeed
        Assert.assertEquals(200, new RequestTask(0).call().intValue());

        // Send a long request - in parallel
        Future<Integer> future = executor.submit(new RequestTask(REQUEST_DURATION));

        // Make sure long request has started
        Thread.sleep(1000);

        // Shutdown server
        this.server.invoke(this.name, SHUTDOWN_METHOD, null, null);

        // Get result of long request
        // This request should succeed since it initiated before server shutdown
        try {
            Assert.assertEquals(200, future.get().intValue());
        } catch (ExecutionException e) {
            e.printStackTrace(System.err);

            Assert.fail(e.getCause().getMessage());
        }

        // Subsequent request should return 404
        Assert.assertEquals(404, new RequestTask(0).call().intValue());
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.jboss.as.test.clustering.cluster.web.ClusteredWebSimpleTestCase.java

private void abstractGracefulServe(URL baseURL1, boolean undeployOnly) throws Exception {

    final DefaultHttpClient client = HttpClientUtils.relaxedCookieHttpClient();
    String url1 = baseURL1.toString() + "simple";

    // Make sure a normal request will succeed
    HttpResponse response = client.execute(new HttpGet(url1));
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
    response.getEntity().getContent().close();

    // Send a long request - in parallel
    String longRunningUrl = url1 + "?" + SimpleServlet.REQUEST_DURATION_PARAM + "=" + REQUEST_DURATION;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningUrl));

    // Make sure long request has started
    Thread.sleep(1000);//from   w  w w.j a v a  2  s. co m

    if (undeployOnly) {
        // Undeploy the app only.
        undeploy(DEPLOYMENT_1);
    } else {
        // Shutdown server.
        stop(CONTAINER_1);
    }

    // Get result of long request
    // This request should succeed since it initiated before server shutdown
    try {
        response = future.get();
        Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.",
                HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    } catch (ExecutionException e) {
        e.printStackTrace(System.err);
        Assert.fail(e.getCause().getMessage());
    }

    if (undeployOnly) {
        // If we are only undeploying, then subsequent requests should return 404.
        response = client.execute(new HttpGet(url1));
        Assert.assertEquals("If we are only undeploying, then subsequent requests should return 404.",
                HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    }
}

From source file:org.jboss.as.test.clustering.cluster.web.DistributableTestCase.java

private void testGracefulServe(URL baseURL, Lifecycle lifecycle)
        throws URISyntaxException, IOException, InterruptedException {

    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        URI uri = SimpleServlet.createURI(baseURL);

        // Make sure a normal request will succeed
        HttpResponse response = client.execute(new HttpGet(uri));
        try {/*from  ww w .  j  a  v a  2s . c o  m*/
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        // Send a long request - in parallel
        URI longRunningURI = SimpleServlet.createURI(baseURL, REQUEST_DURATION);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningURI));

        // Make sure long request has started
        Thread.sleep(1000);

        lifecycle.stop(NODE_1);

        // Get result of long request
        // This request should succeed since it initiated before server shutdown
        try {
            response = future.get();
            try {
                Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.",
                        HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            } finally {
                HttpClientUtils.closeQuietly(response);
            }
        } catch (ExecutionException e) {
            e.printStackTrace(System.err);
            Assert.fail(e.getCause().getMessage());
        }
    }
}

From source file:org.jboss.additional.testsuite.jdkall.past.eap_6_4_x.clustering.cluster.web.ClusteredWebSimpleTestCase.java

private void abstractGracefulServe(URL baseURL1, boolean undeployOnly)
        throws IllegalStateException, IOException, InterruptedException, Exception {

    final DefaultHttpClient client = HttpClientUtils.relaxedCookieHttpClient();
    String url1 = baseURL1.toString() + SimpleServlet.URL;

    // Make sure a normal request will succeed
    HttpResponse response = client.execute(new HttpGet(url1));
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
    response.getEntity().getContent().close();

    // Send a long request - in parallel
    String longRunningUrl = url1 + "?" + SimpleServlet.REQUEST_DURATION_PARAM + "=" + REQUEST_DURATION;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningUrl));

    // Make sure long request has started
    Thread.sleep(1000);//ww w  .  jav  a  2s. com

    if (undeployOnly) {
        // Undeploy the app only.
        undeploy(DEPLOYMENT_1);
    } else {
        // Shutdown server.
        stop(CONTAINER_1);
    }

    // Get result of long request
    // This request should succeed since it initiated before server shutdown
    try {
        response = future.get();
        Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.",
                HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    } catch (ExecutionException e) {
        e.printStackTrace(System.err);
        Assert.fail(e.getCause().getMessage());
    }

    if (undeployOnly) {
        // If we are only undeploying, then subsequent requests should return 404.
        response = client.execute(new HttpGet(url1));
        Assert.assertEquals("If we are only undeploying, then subsequent requests should return 404.",
                HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    }

    // Cleanup after test.
    if (undeployOnly) {
        // Redeploy the app only.
        deploy(DEPLOYMENT_1);
    } else {
        // Startup server.
        start(CONTAINER_1);
    }
}