Search in sources :

Example 21 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame 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 22 with ContinuationFrame

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

the class TestABCase5 method testCase5_1.

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

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame 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 24 with ContinuationFrame

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

the class PerMessageDeflateExtensionTest method testDraft21_Hello_UnCompressedBlock_Fragmented.

/**
     * Decode payload example as seen in draft-ietf-hybi-permessage-compression-21.
     * <p>
     * Section 8.2.3.1: A message compressed using 1 compressed DEFLATE block (with fragmentation)
     */
@Test
public void testDraft21_Hello_UnCompressedBlock_Fragmented() {
    Tester tester = clientExtensions.newTester("permessage-deflate");
    tester.assertNegotiated("permessage-deflate");
    // basic, 1 block, compressed with 0 compression level (aka, uncompressed).
    tester.parseIncomingHex(// Fragment 1
    "0x41 0x03 0xf2 0x48 0xcd", // Fragment 2
    "0x80 0x04 0xc9 0xc9 0x07 0x00");
    tester.assertHasFrames(new TextFrame().setPayload("He").setFin(false), new ContinuationFrame().setPayload("llo").setFin(true));
}
Also used : Tester(org.eclipse.jetty.websocket.common.extensions.ExtensionTool.Tester) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) AbstractExtensionTest(org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest) Test(org.junit.Test)

Example 25 with ContinuationFrame

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

the class FragmentExtensionTest method testOutgoingFramesByMaxLength.

/**
     * Verify that outgoing text frames are fragmented by the maxLength configuration.
     * @throws IOException on test failure
     */
@Test
public void testOutgoingFramesByMaxLength() throws IOException {
    OutgoingFramesCapture capture = new OutgoingFramesCapture();
    FragmentExtension ext = new FragmentExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(WebSocketPolicy.newServerPolicy());
    ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=20");
    ext.setConfig(config);
    ext.setNextOutgoingFrames(capture);
    // Quote
    List<String> quote = new ArrayList<>();
    quote.add("No amount of experimentation can ever prove me right;");
    quote.add("a single experiment can prove me wrong.");
    quote.add("-- Albert Einstein");
    // Write quote as separate frames
    for (String section : quote) {
        Frame frame = new TextFrame().setPayload(section);
        ext.outgoingFrame(frame, null, BatchMode.OFF);
    }
    // Expected Frames
    List<WebSocketFrame> expectedFrames = new ArrayList<>();
    expectedFrames.add(new TextFrame().setPayload("No amount of experim").setFin(false));
    expectedFrames.add(new ContinuationFrame().setPayload("entation can ever pr").setFin(false));
    expectedFrames.add(new ContinuationFrame().setPayload("ove me right;").setFin(true));
    expectedFrames.add(new TextFrame().setPayload("a single experiment ").setFin(false));
    expectedFrames.add(new ContinuationFrame().setPayload("can prove me wrong.").setFin(true));
    expectedFrames.add(new TextFrame().setPayload("-- Albert Einstein").setFin(true));
    // capture.dump();
    int len = expectedFrames.size();
    capture.assertFrameCount(len);
    String prefix;
    LinkedList<WebSocketFrame> frames = capture.getFrames();
    for (int i = 0; i < len; i++) {
        prefix = "Frame[" + i + "]";
        WebSocketFrame actualFrame = frames.get(i);
        WebSocketFrame expectedFrame = expectedFrames.get(i);
        // System.out.printf("actual: %s%n",actualFrame);
        // System.out.printf("expect: %s%n",expectedFrame);
        // Validate Frame
        Assert.assertThat(prefix + ".opcode", actualFrame.getOpCode(), is(expectedFrame.getOpCode()));
        Assert.assertThat(prefix + ".fin", actualFrame.isFin(), is(expectedFrame.isFin()));
        Assert.assertThat(prefix + ".rsv1", actualFrame.isRsv1(), is(expectedFrame.isRsv1()));
        Assert.assertThat(prefix + ".rsv2", actualFrame.isRsv2(), is(expectedFrame.isRsv2()));
        Assert.assertThat(prefix + ".rsv3", actualFrame.isRsv3(), is(expectedFrame.isRsv3()));
        // Validate Payload
        ByteBuffer expectedData = expectedFrame.getPayload().slice();
        ByteBuffer actualData = actualFrame.getPayload().slice();
        Assert.assertThat(prefix + ".payloadLength", actualData.remaining(), is(expectedData.remaining()));
        ByteBufferAssert.assertEquals(prefix + ".payload", expectedData, actualData);
    }
}
Also used : WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) FragmentExtension(org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension) ByteBuffer(java.nio.ByteBuffer) OutgoingFramesCapture(org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) Test(org.junit.Test)

Aggregations

ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)39 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)31 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)29 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)26 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)26 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)20 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)11 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 ByteBuffer (java.nio.ByteBuffer)8 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)4 DataFrame (org.eclipse.jetty.websocket.common.frames.DataFrame)4 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)3 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)3 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)3 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)2 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)2 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)1 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)1