Search in sources :

Example 66 with WebSocketFrame

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

the class TestABCase1 method testCase1_1_2.

/**
     * Echo 125 byte TEXT message (uses small 7-bit payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_1_2() throws Exception {
    byte[] payload = new byte[125];
    Arrays.fill(payload, (byte) '*');
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 67 with WebSocketFrame

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

the class TestABCase2 method testCase2_1.

/**
     * Ping without payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_1() throws Exception {
    WebSocketFrame send = new PingFrame();
    WebSocketFrame expect = new PongFrame();
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) Test(org.junit.Test)

Example 68 with WebSocketFrame

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

the class TestABCase2 method testCase2_3.

/**
     * Ping with small binary (non-utf8) payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_3() throws Exception {
    byte[] payload = new byte[] { 0x00, (byte) 0xFF, (byte) 0xFE, (byte) 0xFD, (byte) 0xFC, (byte) 0xFB, 0x00, (byte) 0xFF };
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new PingFrame().setPayload(payload));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new PongFrame().setPayload(copyOf(payload)));
    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 : 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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 69 with WebSocketFrame

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

the class TestABCase2 method testCase2_5.

/**
     * Ping with 126 byte binary payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_5() throws Exception {
    try (StacklessLogging scope = new StacklessLogging(Parser.class)) {
        // intentionally too big
        byte[] payload = new byte[126];
        Arrays.fill(payload, (byte) '5');
        ByteBuffer buf = ByteBuffer.wrap(payload);
        List<WebSocketFrame> send = new ArrayList<>();
        // trick websocket frame into making extra large payload for ping
        send.add(new BadFrame(OpCode.PING).setPayload(buf));
        send.add(new CloseInfo(StatusCode.NORMAL, "Test 2.5").asFrame());
        List<WebSocketFrame> expect = new ArrayList<>();
        expect.add(new CloseInfo(StatusCode.PROTOCOL).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) 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)

Example 70 with WebSocketFrame

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

the class TestABCase2 method testCase2_7.

/**
     * Unsolicited pong frame without payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_7() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    // unsolicited pong
    send.add(new PongFrame());
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    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);
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) 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