Search in sources :

Example 1 with Ignore

use of org.junit.Ignore in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testExternalServer.

@Ignore
@Test
public void testExternalServer() throws Exception {
    HTTP2Client http2Client = new HTTP2Client();
    SslContextFactory sslContextFactory = new SslContextFactory();
    HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
    Executor executor = new QueuedThreadPool();
    httpClient.setExecutor(executor);
    httpClient.start();
    //        ContentResponse response = httpClient.GET("https://http2.akamai.com/");
    ContentResponse response = httpClient.GET("https://webtide.com/");
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    httpClient.stop();
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Executor(java.util.concurrent.Executor) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Ignore

use of org.junit.Ignore in project jetty.project by eclipse.

the class SelectChannelEndPointTest method testRejectedExecution.

// TODO make this test reliable
@Test
@Ignore
public void testRejectedExecution() throws Exception {
    _manager.stop();
    _threadPool.stop();
    final CountDownLatch latch = new CountDownLatch(1);
    BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(4);
    _threadPool = new QueuedThreadPool(4, 4, 60000, q);
    _manager = new SelectorManager(_threadPool, _scheduler, 1) {

        @Override
        protected EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey selectionKey) throws IOException {
            SocketChannelEndPoint endp = new SocketChannelEndPoint(channel, selector, selectionKey, getScheduler());
            _lastEndPoint = endp;
            _lastEndPointLatch.countDown();
            return endp;
        }

        @Override
        public Connection newConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) throws IOException {
            return new TestConnection(endpoint, latch);
        }
    };
    _threadPool.start();
    _manager.start();
    AtomicInteger timeout = new AtomicInteger();
    AtomicInteger rejections = new AtomicInteger();
    AtomicInteger echoed = new AtomicInteger();
    CountDownLatch closed = new CountDownLatch(20);
    for (int i = 0; i < 20; i++) {
        new Thread() {

            public void run() {
                try (Socket client = newClient()) {
                    client.setSoTimeout(5000);
                    SocketChannel server = _connector.accept();
                    server.configureBlocking(false);
                    _manager.accept(server);
                    // Write client to server
                    client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
                    client.getOutputStream().flush();
                    client.shutdownOutput();
                    // Verify echo server to client
                    for (char c : "HelloWorld".toCharArray()) {
                        int b = client.getInputStream().read();
                        assertTrue(b > 0);
                        assertEquals(c, (char) b);
                    }
                    assertEquals(-1, client.getInputStream().read());
                    echoed.incrementAndGet();
                } catch (SocketTimeoutException x) {
                    x.printStackTrace();
                    timeout.incrementAndGet();
                } catch (Throwable x) {
                    rejections.incrementAndGet();
                } finally {
                    closed.countDown();
                }
            }
        }.start();
    }
    // unblock the handling
    latch.countDown();
    // wait for all clients to complete or fail
    closed.await();
    // assert some clients must have been rejected
    Assert.assertThat(rejections.get(), Matchers.greaterThan(0));
    // but not all of them
    Assert.assertThat(rejections.get(), Matchers.lessThan(20));
    // none should have timed out
    Assert.assertThat(timeout.get(), Matchers.equalTo(0));
    // and the rest should have worked
    Assert.assertThat(echoed.get(), Matchers.equalTo(20 - rejections.get()));
    // and the selector is still working for new requests
    try (Socket client = newClient()) {
        client.setSoTimeout(5000);
        SocketChannel server = _connector.accept();
        server.configureBlocking(false);
        _manager.accept(server);
        // Write client to server
        client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
        client.getOutputStream().flush();
        client.shutdownOutput();
        // Verify echo server to client
        for (char c : "HelloWorld".toCharArray()) {
            int b = client.getInputStream().read();
            assertTrue(b > 0);
            assertEquals(c, (char) b);
        }
        assertEquals(-1, client.getInputStream().read());
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) SocketTimeoutException(java.net.SocketTimeoutException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) SelectableChannel(java.nio.channels.SelectableChannel) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Socket(java.net.Socket) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Ignore

use of org.junit.Ignore in project jetty.project by eclipse.

the class ForwardProxyTLSServerTest method testExternalProxy.

@Test
@Ignore("External Proxy Server no longer stable enough for testing")
public void testExternalProxy() throws Exception {
    // Free proxy server obtained from http://hidemyass.com/proxy-list/
    String proxyHost = "81.208.25.53";
    int proxyPort = 3128;
    try {
        new Socket(proxyHost, proxyPort).close();
    } catch (Throwable x) {
        Assume.assumeNoException(x);
    }
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.start();
    HttpClient httpClient = new HttpClient(newSslContextFactory());
    httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort));
    httpClient.start();
    try {
        ContentResponse response = httpClient.newRequest("https://www.google.com").timeout(20, TimeUnit.SECONDS).send();
        Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    } finally {
        httpClient.stop();
    }
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Socket(java.net.Socket) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Ignore

use of org.junit.Ignore in project jetty.project by eclipse.

the class RequestTest method testMultiPartFormDataReadInputThenParams.

@Test
@Ignore("See issue #1175")
public void testMultiPartFormDataReadInputThenParams() throws Exception {
    final File tmpdir = MavenTestingUtils.getTargetTestingDir("multipart");
    FS.ensureEmpty(tmpdir);
    Handler handler = new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            if (baseRequest.getDispatcherType() != DispatcherType.REQUEST)
                return;
            // Fake a @MultiPartConfig'd servlet endpoint
            MultipartConfigElement multipartConfig = new MultipartConfigElement(tmpdir.getAbsolutePath());
            request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, multipartConfig);
            // Normal processing
            baseRequest.setHandled(true);
            // Fake the commons-fileupload behavior
            int length = request.getContentLength();
            InputStream in = request.getInputStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            // KEY STEP (Don't Change!) commons-fileupload does not read to EOF
            IO.copy(in, out, length);
            // Record what happened as servlet response headers
            response.setIntHeader("x-request-content-length", request.getContentLength());
            response.setIntHeader("x-request-content-read", out.size());
            // uri query parameter
            String foo = request.getParameter("foo");
            // form-data content parameter
            String bar = request.getParameter("bar");
            response.setHeader("x-foo", foo == null ? "null" : foo);
            response.setHeader("x-bar", bar == null ? "null" : bar);
        }
    };
    _server.stop();
    _server.setHandler(handler);
    _server.start();
    String multipart = "--AaBbCc\r\n" + "content-disposition: form-data; name=\"bar\"\r\n" + "\r\n" + "BarContent\r\n" + "--AaBbCc\r\n" + "content-disposition: form-data; name=\"stuff\"\r\n" + "Content-Type: text/plain;charset=ISO-8859-1\r\n" + "\r\n" + "000000000000000000000000000000000000000000000000000\r\n" + "--AaBbCc--\r\n";
    String request = "POST /?foo=FooUri HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: multipart/form-data; boundary=\"AaBbCc\"\r\n" + "Content-Length: " + multipart.getBytes().length + "\r\n" + "Connection: close\r\n" + "\r\n" + multipart;
    HttpTester.Response response = HttpTester.parseResponse(_connector.getResponse(request));
    // It should always be possible to read query string
    assertThat("response.x-foo", response.get("x-foo"), is("FooUri"));
    // Not possible to read request content parameters?
    // TODO: should this work?
    assertThat("response.x-bar", response.get("x-bar"), is("null"));
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) HttpTester(org.eclipse.jetty.http.HttpTester) HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartConfigElement(javax.servlet.MultipartConfigElement) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Ignore

use of org.junit.Ignore in project jetty.project by eclipse.

the class SslUploadTest method test.

@Test
@Ignore
public void test() throws Exception {
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    SslContextFactory ctx = connector.getConnectionFactory(SslConnectionFactory.class).getSslContextFactory();
    try (InputStream stream = new FileInputStream(ctx.getKeyStorePath())) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    final SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort());
    // Simulate async close
    /*
        new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    sleep(100);
                    socket.close();
                }
                catch (IOException x)
                {
                    x.printStackTrace();
                }
                catch (InterruptedException x)
                {
                    Thread.currentThread().interrupt();
                }
            }
        }.start();
        */
    long start = System.nanoTime();
    OutputStream out = socket.getOutputStream();
    out.write("POST / HTTP/1.1\r\n".getBytes());
    out.write("Host: localhost\r\n".getBytes());
    out.write("Content-Length: 16777216\r\n".getBytes());
    out.write("Content-Type: bytes\r\n".getBytes());
    out.write("Connection: close\r\n".getBytes());
    out.write("\r\n".getBytes());
    out.flush();
    byte[] requestContent = new byte[16777216];
    Arrays.fill(requestContent, (byte) 120);
    out.write(requestContent);
    out.flush();
    InputStream in = socket.getInputStream();
    String response = IO.toString(in);
    assertTrue(response.indexOf("200") > 0);
    // System.err.println(response);
    // long end = System.nanoTime();
    // System.out.println("upload time: " + TimeUnit.NANOSECONDS.toMillis(end - start));
    assertEquals(requestContent.length, total);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) SSLContext(javax.net.ssl.SSLContext) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Ignore (org.junit.Ignore)5092 Test (org.junit.Test)4807 File (java.io.File)445 ArrayList (java.util.ArrayList)374 IOException (java.io.IOException)217 HashMap (java.util.HashMap)187 List (java.util.List)171 CountDownLatch (java.util.concurrent.CountDownLatch)118 Map (java.util.Map)103 LocalDate (java.time.LocalDate)94 Dataset (org.apache.jena.query.Dataset)93 InputStream (java.io.InputStream)89 Date (java.util.Date)88 Random (java.util.Random)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)83 Properties (java.util.Properties)78 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)78 HashSet (java.util.HashSet)71 ByteArrayOutputStream (java.io.ByteArrayOutputStream)70 ExecutorService (java.util.concurrent.ExecutorService)70