Search in sources :

Example 66 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer 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 67 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer 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 68 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer 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 69 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer 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 70 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer 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

WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)108 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)108 ArrayList (java.util.ArrayList)106 Test (org.junit.Test)106 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)59 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)45 ByteBuffer (java.nio.ByteBuffer)43 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)27 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)26 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)17 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)15 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5