Search in sources :

Example 96 with ExecutionException

use of java.util.concurrent.ExecutionException in project jetty.project by eclipse.

the class HttpClientTest method testRequestAfterFailedRequest.

@Test
public void testRequestAfterFailedRequest() throws Exception {
    int length = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
    start(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            try {
                baseRequest.setHandled(true);
                response.getOutputStream().write(new byte[length]);
            } catch (IOException e) {
            }
        }
    });
    // Make a request with a large enough response buffer.
    org.eclipse.jetty.client.api.Request request = client.newRequest(newURI());
    FutureResponseListener listener = new FutureResponseListener(request, length);
    request.send(listener);
    ContentResponse response = listener.get(5, TimeUnit.SECONDS);
    Assert.assertEquals(response.getStatus(), 200);
    // Make a request with a small response buffer, should fail.
    try {
        request = client.newRequest(newURI());
        listener = new FutureResponseListener(request, length / 10);
        request.send(listener);
        listener.get(5, TimeUnit.SECONDS);
        Assert.fail();
    } catch (ExecutionException x) {
        Assert.assertThat(x.getMessage(), Matchers.containsString("Buffering capacity exceeded"));
    }
    // Verify that we can make another request.
    request = client.newRequest(newURI());
    listener = new FutureResponseListener(request, length);
    request.send(listener);
    response = listener.get(5, TimeUnit.SECONDS);
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ExecutionException(java.util.concurrent.ExecutionException) FutureResponseListener(org.eclipse.jetty.client.util.FutureResponseListener) Test(org.junit.Test)

Example 97 with ExecutionException

use of java.util.concurrent.ExecutionException in project jetty.project by eclipse.

the class HttpClientTest method test_Request_IdleTimeout.

@Slow
@Test
public void test_Request_IdleTimeout() throws Exception {
    final long idleTimeout = 1000;
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            try {
                baseRequest.setHandled(true);
                TimeUnit.MILLISECONDS.sleep(2 * idleTimeout);
            } catch (InterruptedException x) {
                throw new ServletException(x);
            }
        }
    });
    final String host = "localhost";
    final int port = connector.getLocalPort();
    try {
        client.newRequest(host, port).scheme(scheme).idleTimeout(idleTimeout, TimeUnit.MILLISECONDS).timeout(3 * idleTimeout, TimeUnit.MILLISECONDS).send();
        Assert.fail();
    } catch (ExecutionException expected) {
        Assert.assertTrue(expected.getCause() instanceof TimeoutException);
    }
    // Make another request without specifying the idle timeout, should not fail
    ContentResponse response = client.newRequest(host, port).scheme(scheme).timeout(3 * idleTimeout, TimeUnit.MILLISECONDS).send();
    Assert.assertNotNull(response);
    Assert.assertEquals(200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) EndPoint(org.eclipse.jetty.io.EndPoint) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 98 with ExecutionException

use of java.util.concurrent.ExecutionException in project jetty.project by eclipse.

the class HttpClientTLSTest method testNoCommonTLSProtocol.

@Test
public void testNoCommonTLSProtocol() throws Exception {
    SslContextFactory serverTLSFactory = createSslContextFactory();
    serverTLSFactory.setIncludeProtocols("TLSv1.2");
    startServer(serverTLSFactory, new EmptyServerHandler());
    CountDownLatch serverLatch = new CountDownLatch(1);
    connector.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            serverLatch.countDown();
        }
    });
    SslContextFactory clientTLSFactory = createSslContextFactory();
    clientTLSFactory.setIncludeProtocols("TLSv1.1");
    startClient(clientTLSFactory);
    CountDownLatch clientLatch = new CountDownLatch(1);
    client.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            clientLatch.countDown();
        }
    });
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).timeout(5, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
    // Expected.
    }
    Assert.assertTrue(serverLatch.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(clientLatch.await(1, TimeUnit.SECONDS));
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 99 with ExecutionException

use of java.util.concurrent.ExecutionException in project jetty.project by eclipse.

the class HttpClientTLSTest method testNoCommonTLSCiphers.

@Test
public void testNoCommonTLSCiphers() throws Exception {
    SslContextFactory serverTLSFactory = createSslContextFactory();
    serverTLSFactory.setIncludeCipherSuites("TLS_RSA_WITH_AES_128_CBC_SHA");
    startServer(serverTLSFactory, new EmptyServerHandler());
    CountDownLatch serverLatch = new CountDownLatch(1);
    connector.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            serverLatch.countDown();
        }
    });
    SslContextFactory clientTLSFactory = createSslContextFactory();
    clientTLSFactory.setExcludeCipherSuites(".*_SHA$");
    startClient(clientTLSFactory);
    CountDownLatch clientLatch = new CountDownLatch(1);
    client.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            clientLatch.countDown();
        }
    });
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).timeout(5, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
    // Expected.
    }
    Assert.assertTrue(serverLatch.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(clientLatch.await(1, TimeUnit.SECONDS));
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 100 with ExecutionException

use of java.util.concurrent.ExecutionException in project jetty.project by eclipse.

the class HttpClientTLSTest method testMismatchBetweenTLSProtocolAndTLSCiphersOnServer.

@Test
public void testMismatchBetweenTLSProtocolAndTLSCiphersOnServer() throws Exception {
    SslContextFactory serverTLSFactory = createSslContextFactory();
    // TLS 1.1 protocol, but only TLS 1.2 ciphers.
    serverTLSFactory.setIncludeProtocols("TLSv1.1");
    serverTLSFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
    startServer(serverTLSFactory, new EmptyServerHandler());
    CountDownLatch serverLatch = new CountDownLatch(1);
    connector.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            serverLatch.countDown();
        }
    });
    SslContextFactory clientTLSFactory = createSslContextFactory();
    startClient(clientTLSFactory);
    CountDownLatch clientLatch = new CountDownLatch(1);
    client.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            clientLatch.countDown();
        }
    });
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).timeout(5, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
    // Expected.
    }
    Assert.assertTrue(serverLatch.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(clientLatch.await(1, TimeUnit.SECONDS));
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1341 IOException (java.io.IOException)367 Test (org.junit.Test)335 TimeoutException (java.util.concurrent.TimeoutException)258 ArrayList (java.util.ArrayList)237 Future (java.util.concurrent.Future)218 ExecutorService (java.util.concurrent.ExecutorService)152 CountDownLatch (java.util.concurrent.CountDownLatch)103 List (java.util.List)98 CancellationException (java.util.concurrent.CancellationException)98 Callable (java.util.concurrent.Callable)97 Test (org.testng.annotations.Test)78 HashMap (java.util.HashMap)69 Map (java.util.Map)65 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)64 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)63 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)56 ParallelTest (com.hazelcast.test.annotation.ParallelTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)46