Search in sources :

Example 21 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase7_BadStatusCodes method testBadStatusCode.

/**
     * just the close code, no reason
     * @throws Exception on test failure
     */
@Test
public void testBadStatusCode() throws Exception {
    ByteBuffer payload = ByteBuffer.allocate(256);
    BufferUtil.clearToFill(payload);
    payload.putChar((char) statusCode);
    BufferUtil.flipToFlush(payload, 0);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseFrame().setPayload(payload.slice()));
    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);
        fuzzer.expectNoMoreFrames();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 22 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase7_GoodStatusCodes method testStatusCode.

/**
     * just the close code, no reason
     * @throws Exception on test failure
     */
@Test
public void testStatusCode() throws Exception {
    ByteBuffer payload = ByteBuffer.allocate(256);
    BufferUtil.clearToFill(payload);
    payload.putChar((char) statusCode);
    BufferUtil.flipToFlush(payload, 0);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseFrame().setPayload(payload.slice()));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseFrame().setPayload(clone(payload)));
    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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 23 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase9 method testCase9_2_1.

/**
     * Echo 64KB binary message (1 frame)
     * @throws Exception on test failure
     */
@Test
public void testCase9_2_1() throws Exception {
    byte[] data = new byte[64 * KBYTE];
    Arrays.fill(data, (byte) 0x21);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new BinaryFrame().setPayload(data));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new BinaryFrame().setPayload(copyOf(data)));
    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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 24 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase9 method testCase9_1_1.

/**
     * Echo 64KB text message (1 frame)
     * @throws Exception on test failure
     */
@Test
public void testCase9_1_1() throws Exception {
    byte[] utf = new byte[64 * KBYTE];
    Arrays.fill(utf, (byte) 'y');
    String msg = StringUtil.toUTF8String(utf, 0, utf.length);
    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(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 25 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase5 method testCase5_5.

/**
     * Send text fragmented in 2 packets (slowly)
     * @throws Exception on test failure
     */
@Test
public void testCase5_5() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("hello, ").setFin(false));
    send.add(new ContinuationFrame().setPayload("world").setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload("hello, world"));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(1);
        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) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) 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