Search in sources :

Example 31 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class HttpClientStreamTest method testUploadWithDeferredContentProviderFromInputStream.

@Slow
@Test
public void testUploadWithDeferredContentProviderFromInputStream() throws Exception {
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            IO.copy(request.getInputStream(), new ByteArrayOutputStream());
        }
    });
    final CountDownLatch latch = new CountDownLatch(1);
    try (DeferredContentProvider content = new DeferredContentProvider()) {
        client.newRequest("localhost", connector.getLocalPort()).scheme(getScheme()).content(content).send(result -> {
            if (result.isSucceeded() && result.getResponse().getStatus() == 200)
                latch.countDown();
        });
        // Make sure we provide the content *after* the request has been "sent".
        Thread.sleep(1000);
        try (ByteArrayInputStream input = new ByteArrayInputStream(new byte[1024])) {
            byte[] buffer = new byte[200];
            int read;
            while ((read = input.read(buffer)) >= 0) content.offer(ByteBuffer.wrap(buffer, 0, read));
        }
    }
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : Request(org.eclipse.jetty.server.Request) HttpServletResponse(javax.servlet.http.HttpServletResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeferredContentProvider(org.eclipse.jetty.client.util.DeferredContentProvider) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 32 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class HttpClientContinueTest method test_Expect100Continue_WithDeferredContent_Respond100Continue.

@Slow
@Test
public void test_Expect100Continue_WithDeferredContent_Respond100Continue() throws Exception {
    start(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            // Send 100-Continue and echo the content
            IO.copy(request.getInputStream(), response.getOutputStream());
        }
    });
    final byte[] chunk1 = new byte[] { 0, 1, 2, 3 };
    final byte[] chunk2 = new byte[] { 4, 5, 6, 7 };
    final byte[] data = new byte[chunk1.length + chunk2.length];
    System.arraycopy(chunk1, 0, data, 0, chunk1.length);
    System.arraycopy(chunk2, 0, data, chunk1.length, chunk2.length);
    final CountDownLatch latch = new CountDownLatch(1);
    DeferredContentProvider content = new DeferredContentProvider();
    client.newRequest(newURI()).header(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()).content(content).send(new BufferingResponseListener() {

        @Override
        public void onComplete(Result result) {
            Assert.assertArrayEquals(data, getContent());
            latch.countDown();
        }
    });
    Thread.sleep(1000);
    content.offer(ByteBuffer.wrap(chunk1));
    Thread.sleep(1000);
    content.offer(ByteBuffer.wrap(chunk2));
    content.close();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Result(org.eclipse.jetty.client.api.Result) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) DeferredContentProvider(org.eclipse.jetty.client.util.DeferredContentProvider) BufferingResponseListener(org.eclipse.jetty.client.util.BufferingResponseListener) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 33 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class HttpClientTest method testRequestIdleTimeout.

@Slow
@Test
public void testRequestIdleTimeout() 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) 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 34 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class QueuedThreadPoolTest method testShrink.

@Test
@Slow
public void testShrink() throws Exception {
    final AtomicInteger sleep = new AtomicInteger(100);
    Runnable job = new Runnable() {

        public void run() {
            try {
                Thread.sleep(sleep.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    QueuedThreadPool tp = new QueuedThreadPool();
    tp.setMinThreads(2);
    tp.setMaxThreads(10);
    tp.setIdleTimeout(400);
    tp.setThreadsPriority(Thread.NORM_PRIORITY - 1);
    tp.start();
    waitForIdle(tp, 2);
    waitForThreads(tp, 2);
    sleep.set(200);
    tp.execute(job);
    tp.execute(job);
    for (int i = 0; i < 20; i++) tp.execute(job);
    waitForThreads(tp, 10);
    waitForIdle(tp, 0);
    sleep.set(5);
    for (int i = 0; i < 500; i++) {
        tp.execute(job);
        Thread.sleep(10);
    }
    waitForThreads(tp, 2);
    waitForIdle(tp, 2);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 35 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class SchedulerTest method testBenchmark.

@Test
@Slow
@Ignore
public void testBenchmark() throws Exception {
    schedule(2000, 10000, 2000, 50);
    PlatformMonitor benchmark = new PlatformMonitor();
    PlatformMonitor.Start start = benchmark.start();
    System.err.println(start);
    System.err.println(_scheduler);
    schedule(2000, 30000, 2000, 50);
    PlatformMonitor.Stop stop = benchmark.stop();
    System.err.println(stop);
}
Also used : PlatformMonitor(org.eclipse.jetty.toolchain.perf.PlatformMonitor) Ignore(org.junit.Ignore) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Aggregations

Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)37 Test (org.junit.Test)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 IOException (java.io.IOException)11 Result (org.eclipse.jetty.client.api.Result)11 ServletException (javax.servlet.ServletException)10 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)10 Request (org.eclipse.jetty.client.api.Request)9 Socket (java.net.Socket)7 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 Response (org.eclipse.jetty.client.api.Response)6 Connection (org.eclipse.jetty.client.api.Connection)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5 BufferingResponseListener (org.eclipse.jetty.client.util.BufferingResponseListener)5 Request (org.eclipse.jetty.server.Request)5 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)5 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)5