Search in sources :

Example 96 with CloseInfo

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

the class TestABCase9 method assertSlowFrameEcho.

private void assertSlowFrameEcho(byte opcode, int overallMsgSize, int segmentSize) throws Exception {
    byte[] msg = new byte[overallMsgSize];
    Arrays.fill(msg, (byte) 'M');
    ByteBuffer buf = ByteBuffer.wrap(msg);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(toDataFrame(opcode).setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(toDataFrame(opcode).setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(segmentSize);
        fuzzer.send(send);
        fuzzer.expect(expect, 8, TimeUnit.SECONDS);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 97 with CloseInfo

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

the class TestABCase9 method testCase9_2_2.

/**
     * Echo 256KB binary message (1 frame)
     * @throws Exception on test failure
     */
@Test
public void testCase9_2_2() throws Exception {
    byte[] data = new byte[256 * KBYTE];
    Arrays.fill(data, (byte) 0x22);
    ByteBuffer buf = ByteBuffer.wrap(data);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new BinaryFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new BinaryFrame().setPayload(clone(buf)));
    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) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 98 with CloseInfo

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

the class TestABCase9 method testCase9_1_2.

/**
     * Echo 256KB text message (1 frame)
     * @throws Exception on test failure
     */
@Test
public void testCase9_1_2() throws Exception {
    byte[] utf = new byte[256 * KBYTE];
    Arrays.fill(utf, (byte) 'y');
    ByteBuffer buf = ByteBuffer.wrap(utf);
    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(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 99 with CloseInfo

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

the class TestABCase9 method assertMultiFrameEcho.

private void assertMultiFrameEcho(byte opcode, int overallMsgSize, int fragmentSize) throws Exception {
    byte[] msg = new byte[overallMsgSize];
    Arrays.fill(msg, (byte) 'M');
    List<WebSocketFrame> send = new ArrayList<>();
    byte[] frag;
    int remaining = msg.length;
    int offset = 0;
    boolean fin;
    ByteBuffer buf;
    ;
    byte op = opcode;
    while (remaining > 0) {
        int len = Math.min(remaining, fragmentSize);
        frag = new byte[len];
        System.arraycopy(msg, offset, frag, 0, len);
        remaining -= len;
        fin = (remaining <= 0);
        buf = ByteBuffer.wrap(frag);
        send.add(toDataFrame(op).setPayload(buf).setFin(fin));
        offset += len;
        op = OpCode.CONTINUATION;
    }
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(toDataFrame(opcode).setPayload(copyOf(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, 8, TimeUnit.SECONDS);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 100 with CloseInfo

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

the class TestABCase9 method testCase9_1_4.

/**
     * Echo 4MB text message (1 frame)
     * @throws Exception on test failure
     */
@Test
public void testCase9_1_4() throws Exception {
    byte[] utf = new byte[4 * MBYTE];
    Arrays.fill(utf, (byte) 'y');
    ByteBuffer buf = ByteBuffer.wrap(utf);
    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(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect, 8, TimeUnit.SECONDS);
    }
}
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)

Aggregations

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)151 Test (org.junit.Test)129 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)118 ArrayList (java.util.ArrayList)104 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)68 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)55 ByteBuffer (java.nio.ByteBuffer)48 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)30 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)27 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)17 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)14 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)10 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4