Search in sources :

Example 16 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.

the class TestABCase6 method testCase6_1_2.

/**
     * text message, 0 length, 3 fragments
     * @throws Exception on test failure
     */
@Test
public void testCase6_1_2() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame());
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        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)

Example 17 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.

the class TestABCase6 method testCase6_2_4.

/**
     * valid utf8 text message, many fragments (1 byte each)
     * @throws Exception on test failure
     */
@Test
public void testCase6_2_4() throws Exception {
    byte[] msg = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5");
    List<WebSocketFrame> send = new ArrayList<>();
    fragmentText(send, msg);
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 18 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.

the class MisbehavingClassTest method testListenerRuntimeOnConnect.

@Test
public void testListenerRuntimeOnConnect() throws Exception {
    try (IBlockheadClient client = new BlockheadClient(server.getServerUri());
        StacklessLogging scope = new StacklessLogging(ListenerRuntimeOnConnectSocket.class, WebSocketSession.class)) {
        client.setProtocols("listener-runtime-connect");
        client.setTimeout(1, TimeUnit.SECONDS);
        ListenerRuntimeOnConnectSocket socket = badSocketsServlet.listenerRuntimeConnect;
        socket.reset();
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
        CloseInfo close = new CloseInfo(frame);
        assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
        // respond with close
        client.write(close.asFrame());
        // ensure server socket got close event
        assertThat("Close Latch", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
        assertThat("closeStatusCode", socket.closeStatusCode, is(StatusCode.SERVER_ERROR));
        // Validate errors
        assertThat("socket.onErrors", socket.errors.size(), is(1));
        Throwable cause = socket.errors.pop();
        assertThat("Error type", cause, instanceOf(RuntimeException.class));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 19 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.

the class TestABCase6_GoodUTF method assertEchoTextMessage.

@Test
public void assertEchoTextMessage() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(msg));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(msg)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 20 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.

the class TestABCase7 method testCase7_1_5.

/**
     * Text fin=false, close, then continuation fin=true
     * @throws Exception on test failure
     */
@Test
public void testCase7_1_5() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("an").setFin(false));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    send.add(new ContinuationFrame().setPayload("ticipation").setFin(true));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
        fuzzer.expectNoMoreFrames();
    }
}
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)

Aggregations

WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)185 Test (org.junit.Test)169 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)118 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)112 ArrayList (java.util.ArrayList)111 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)108 ByteBuffer (java.nio.ByteBuffer)79 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)51 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)37 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)36 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)36 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)25 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)17 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)17 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)14 URI (java.net.URI)12 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6