Search in sources :

Example 6 with Slow

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

the class SlowClientTest method testClientSlowToSend.

@Test
@Slow
public void testClientSlowToSend() throws Exception {
    JettyTrackingSocket tsocket = new JettyTrackingSocket();
    client.getPolicy().setIdleTimeout(60000);
    URI wsUri = server.getWsUri();
    Future<Session> future = client.connect(tsocket, wsUri);
    IBlockheadServerConnection sconnection = server.accept();
    sconnection.setSoTimeout(60000);
    sconnection.upgrade();
    // Confirm connected
    future.get(30, TimeUnit.SECONDS);
    tsocket.waitForConnected(30, TimeUnit.SECONDS);
    int messageCount = 10;
    // Setup server read thread
    ServerReadThread reader = new ServerReadThread(sconnection, messageCount);
    reader.start();
    // Have client write slowly.
    ClientWriteThread writer = new ClientWriteThread(tsocket.getSession());
    writer.setMessageCount(messageCount);
    writer.setMessage("Hello");
    writer.setSlowness(10);
    writer.start();
    writer.join();
    reader.waitForExpectedMessageCount(1, TimeUnit.MINUTES);
    // Verify receive
    Assert.assertThat("Frame Receive Count", reader.getFrameCount(), is(messageCount));
    // Close
    tsocket.getSession().close(StatusCode.NORMAL, "Done");
    Assert.assertTrue("Client Socket Closed", tsocket.closeLatch.await(3, TimeUnit.MINUTES));
    tsocket.assertCloseCode(StatusCode.NORMAL);
    // stop reading
    reader.cancel();
}
Also used : IBlockheadServerConnection(org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 7 with Slow

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

the class TestABCase6 method testCase6_4_3.

/**
     * invalid text message, 1 frame/fragment (slowly, and split within code points)
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_3() throws Exception {
    // Disable Long Stacks from Parser (we know this test will throw an exception)
    try (StacklessLogging scope = new StacklessLogging(Parser.class)) {
        ByteBuffer payload = ByteBuffer.allocate(64);
        BufferUtil.clearToFill(payload);
        // good
        payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5"));
        // INVALID
        payload.put(TypeUtil.fromHexString("f4908080"));
        // good
        payload.put(TypeUtil.fromHexString("656469746564"));
        BufferUtil.flipToFlush(payload, 0);
        List<WebSocketFrame> send = new ArrayList<>();
        send.add(new TextFrame().setPayload(payload));
        send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
        List<WebSocketFrame> expect = new ArrayList<>();
        expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
        try (Fuzzer fuzzer = new Fuzzer(this)) {
            fuzzer.connect();
            ByteBuffer net = fuzzer.asNetworkBuffer(send);
            int[] splits = { 17, 21, net.limit() };
            // Header + good UTF
            ByteBuffer part1 = net.slice();
            part1.limit(splits[0]);
            // invalid UTF
            ByteBuffer part2 = net.slice();
            part2.position(splits[0]);
            part2.limit(splits[1]);
            // good UTF
            ByteBuffer part3 = net.slice();
            part3.position(splits[1]);
            part3.limit(splits[2]);
            // the header + good utf
            fuzzer.send(part1);
            TimeUnit.MILLISECONDS.sleep(500);
            // the bad UTF
            fuzzer.send(part2);
            TimeUnit.MILLISECONDS.sleep(500);
            // the rest (shouldn't work)
            fuzzer.send(part3);
            fuzzer.expect(expect);
        }
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 8 with Slow

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

the class TestABCase6 method testCase6_4_2.

/**
     * invalid text message, 3 fragments.
     * <p>
     * fragment #1 is valid and ends in the middle of an incomplete code point.
     * <p>
     * fragment #2 finishes the UTF8 code point but it is invalid
     * <p>
     * fragment #3 contains the remainder of the message.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_2() throws Exception {
    // split code point
    byte[] part1 = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4");
    // continue code point & invalid
    byte[] part2 = Hex.asByteArray("90");
    // continue code point & finish
    byte[] part3 = Hex.asByteArray("8080656469746564");
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) 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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 9 with Slow

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

the class TestABCase6 method testCase6_4_4.

/**
     * invalid text message, 1 frame/fragment (slowly, and split within code points)
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_4() throws Exception {
    byte[] invalid = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(ByteBuffer.wrap(invalid)));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging scope = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        ByteBuffer net = fuzzer.asNetworkBuffer(send);
        fuzzer.send(net, 6);
        fuzzer.send(net, 11);
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(net, 1);
        TimeUnit.SECONDS.sleep(1);
        // the rest
        fuzzer.send(net, 100);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 10 with Slow

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

the class TestABCase6 method testCase6_4_1.

/**
     * invalid text message, 3 fragments.
     * <p>
     * fragment #1 and fragment #3 are both valid in themselves.
     * <p>
     * fragment #2 contains the invalid utf8 code point.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_1() throws Exception {
    byte[] part1 = StringUtil.getUtf8Bytes("κόσμε");
    // invalid
    byte[] part2 = Hex.asByteArray("F4908080");
    byte[] part3 = StringUtil.getUtf8Bytes("edited");
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) 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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) 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