Search in sources :

Example 36 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase5 method testCase5_4.

/**
     * Send text fragmented in 2 packets (framewise)
     * @throws Exception on test failure
     */
@Test
public void testCase5_4() 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.PER_FRAME);
        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)

Example 37 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase5 method testCase5_19.

/**
     * send text message fragmented in 5 frames, with 2 pings and wait between.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase5_19() throws Exception {
    // phase 1
    List<WebSocketFrame> send1 = new ArrayList<>();
    send1.add(new TextFrame().setPayload("f1").setFin(false));
    send1.add(new ContinuationFrame().setPayload(",f2").setFin(false));
    send1.add(new PingFrame().setPayload("pong-1"));
    List<WebSocketFrame> expect1 = new ArrayList<>();
    expect1.add(new PongFrame().setPayload("pong-1"));
    // phase 2
    List<WebSocketFrame> send2 = new ArrayList<>();
    send2.add(new ContinuationFrame().setPayload(",f3").setFin(false));
    send2.add(new ContinuationFrame().setPayload(",f4").setFin(false));
    send2.add(new PingFrame().setPayload("pong-2"));
    send2.add(new ContinuationFrame().setPayload(",f5").setFin(true));
    send2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect2 = new ArrayList<>();
    expect2.add(new PongFrame().setPayload("pong-2"));
    expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
    expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        // phase 1
        fuzzer.send(send1);
        fuzzer.expect(expect1);
        // delay
        TimeUnit.SECONDS.sleep(1);
        // phase 2
        fuzzer.send(send2);
        fuzzer.expect(expect2);
    }
}
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) 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) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 38 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase5 method testCase5_6.

/**
     * Send text fragmented in 2 packets, with ping between them
     * @throws Exception on test failure
     */
@Test
public void testCase5_6() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("hello, ").setFin(false));
    send.add(new PingFrame().setPayload("ping"));
    send.add(new ContinuationFrame().setPayload("world").setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new PongFrame().setPayload("ping"));
    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.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) 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)

Example 39 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase3 method testCase3_3.

/**
     * Send small text frame, send again with (RSV1 & RSV2), then ping, with no extensions defined.
     * @throws Exception on test failure
     */
@Test
public void testCase3_3() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("small"));
    // intentionally bad
    send.add(new TextFrame().setPayload("small").setRsv1(true).setRsv2(true));
    send.add(new PingFrame().setPayload("ping"));
    List<WebSocketFrame> expect = new ArrayList<>();
    // echo on good frame
    expect.add(new TextFrame().setPayload("small"));
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging logging = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 40 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase3 method testCase3_4.

/**
     * Send small text frame, send again with (RSV3), then ping, with no extensions defined.
     * @throws Exception on test failure
     */
@Test
public void testCase3_4() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("small"));
    // intentionally bad
    send.add(new TextFrame().setPayload("small").setRsv3(true));
    send.add(new PingFrame().setPayload("ping"));
    List<WebSocketFrame> expect = new ArrayList<>();
    // echo on good frame
    expect.add(new TextFrame().setPayload("small"));
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging logging = 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) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)142 Test (org.junit.Test)130 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)109 ArrayList (java.util.ArrayList)69 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)68 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)59 ByteBuffer (java.nio.ByteBuffer)54 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)38 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)35 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)33 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)23 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)14 URI (java.net.URI)13 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)8 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)6 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5