Search in sources :

Example 11 with Slow

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

the class TestABCase5 method testCase5_19.

/**
     * send text message fragmented in 5 frames, with 2 pings and wait between.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase5_19() throws Exception {
    // phase 1
    List<WebSocketFrame> send1 = new ArrayList<>();
    send1.add(new TextFrame().setPayload("f1").setFin(false));
    send1.add(new ContinuationFrame().setPayload(",f2").setFin(false));
    send1.add(new PingFrame().setPayload("pong-1"));
    List<WebSocketFrame> expect1 = new ArrayList<>();
    expect1.add(new PongFrame().setPayload("pong-1"));
    // phase 2
    List<WebSocketFrame> send2 = new ArrayList<>();
    send2.add(new ContinuationFrame().setPayload(",f3").setFin(false));
    send2.add(new ContinuationFrame().setPayload(",f4").setFin(false));
    send2.add(new PingFrame().setPayload("pong-2"));
    send2.add(new ContinuationFrame().setPayload(",f5").setFin(true));
    send2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect2 = new ArrayList<>();
    expect2.add(new PongFrame().setPayload("pong-2"));
    expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
    expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        // phase 1
        fuzzer.send(send1);
        fuzzer.expect(expect1);
        // delay
        TimeUnit.SECONDS.sleep(1);
        // phase 2
        fuzzer.send(send2);
        fuzzer.expect(expect2);
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 12 with Slow

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

the class HttpClientTimeoutTest method testTimeoutIsCancelledOnSuccess.

@Slow
@Test
public void testTimeoutIsCancelledOnSuccess() throws Exception {
    long timeout = 1000;
    start(new TimeoutHandler(timeout));
    final CountDownLatch latch = new CountDownLatch(1);
    final byte[] content = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).content(new InputStreamContentProvider(new ByteArrayInputStream(content))).timeout(2 * timeout, TimeUnit.MILLISECONDS);
    request.send(new BufferingResponseListener() {

        @Override
        public void onComplete(Result result) {
            Assert.assertFalse(result.isFailed());
            Assert.assertArrayEquals(content, getContent());
            latch.countDown();
        }
    });
    Assert.assertTrue(latch.await(3 * timeout, TimeUnit.MILLISECONDS));
    TimeUnit.MILLISECONDS.sleep(2 * timeout);
    Assert.assertNull(request.getAbortCause());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) CountDownLatch(java.util.concurrent.CountDownLatch) BufferingResponseListener(org.eclipse.jetty.client.util.BufferingResponseListener) Result(org.eclipse.jetty.client.api.Result) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 13 with Slow

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

the class HttpClientTimeoutTest method testTimeoutOnQueuedRequest.

@Slow
@Test
public void testTimeoutOnQueuedRequest() throws Exception {
    long timeout = 1000;
    start(new TimeoutHandler(3 * timeout));
    // Only one connection so requests get queued
    client.setMaxConnectionsPerDestination(1);
    // The first request has a long timeout
    final CountDownLatch firstLatch = new CountDownLatch(1);
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(4 * timeout, TimeUnit.MILLISECONDS);
    request.send(new Response.CompleteListener() {

        @Override
        public void onComplete(Result result) {
            Assert.assertFalse(result.isFailed());
            firstLatch.countDown();
        }
    });
    // Second request has a short timeout and should fail in the queue
    final CountDownLatch secondLatch = new CountDownLatch(1);
    request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(timeout, TimeUnit.MILLISECONDS);
    request.send(new Response.CompleteListener() {

        @Override
        public void onComplete(Result result) {
            Assert.assertTrue(result.isFailed());
            secondLatch.countDown();
        }
    });
    Assert.assertTrue(secondLatch.await(2 * timeout, TimeUnit.MILLISECONDS));
    // The second request must fail before the first request has completed
    Assert.assertTrue(firstLatch.getCount() > 0);
    Assert.assertTrue(firstLatch.await(5 * timeout, TimeUnit.MILLISECONDS));
}
Also used : Response(org.eclipse.jetty.client.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 14 with Slow

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

the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_IncompleteFlush.

@Slow
@Test
public void test_Send_NoRequestContent_IncompleteFlush() throws Exception {
    ByteArrayEndPoint endPoint = new ByteArrayEndPoint("", 16);
    HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
    destination.start();
    HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
    Request request = client.newRequest(URI.create("http://localhost/"));
    connection.send(request, null);
    // This take will free space in the buffer and allow for the write to complete
    StringBuilder builder = new StringBuilder(endPoint.takeOutputString());
    // Wait for the write to complete
    TimeUnit.SECONDS.sleep(1);
    String chunk = endPoint.takeOutputString();
    while (chunk.length() > 0) {
        builder.append(chunk);
        chunk = endPoint.takeOutputString();
    }
    String requestString = builder.toString();
    Assert.assertTrue(requestString.startsWith("GET "));
    Assert.assertTrue(requestString.endsWith("\r\n\r\n"));
}
Also used : Origin(org.eclipse.jetty.client.Origin) Promise(org.eclipse.jetty.util.Promise) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 15 with Slow

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

the class HttpClientTimeoutTest method testTimeoutOnListenerWithExplicitConnection.

@Slow
@Test
public void testTimeoutOnListenerWithExplicitConnection() throws Exception {
    long timeout = 1000;
    start(new TimeoutHandler(2 * timeout));
    final CountDownLatch latch = new CountDownLatch(1);
    Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
    FuturePromise<Connection> futureConnection = new FuturePromise<>();
    destination.newConnection(futureConnection);
    try (Connection connection = futureConnection.get(5, TimeUnit.SECONDS)) {
        Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(timeout, TimeUnit.MILLISECONDS);
        connection.send(request, new Response.CompleteListener() {

            @Override
            public void onComplete(Result result) {
                Assert.assertTrue(result.isFailed());
                latch.countDown();
            }
        });
        Assert.assertTrue(latch.await(3 * timeout, TimeUnit.MILLISECONDS));
    }
}
Also used : Response(org.eclipse.jetty.client.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Destination(org.eclipse.jetty.client.api.Destination) FuturePromise(org.eclipse.jetty.util.FuturePromise) Connection(org.eclipse.jetty.client.api.Connection) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) 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