Search in sources :

Example 41 with PingFrame

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

the class TestABCase4 method testCase4_2_3.

/**
     * Send small text, then frame with opcode 13 (reserved), then ping
     * @throws Exception on test failure
     */
@Test
public void testCase4_2_3() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("hello"));
    // intentionally bad
    send.add(new BadFrame((byte) 13));
    send.add(new PingFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    // echo
    expect.add(new TextFrame().setPayload("hello"));
    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.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) 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 42 with PingFrame

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

the class TestABCase7 method testCase7_1_3.

/**
     * Close frame, then ping frame (no pong received)
     * @throws Exception on test failure
     */
@Test
public void testCase7_1_3() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    send.add(new PingFrame().setPayload("out of band ping"));
    List<WebSocketFrame> expect = new ArrayList<>();
    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);
        fuzzer.expectNoMoreFrames();
    }
}
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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 43 with PingFrame

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

the class TestABCase2 method testCase2_11.

/**
     * 10 pings, sent slowly
     * @throws Exception on test failure
     */
@Test
public void testCase2_11() throws Exception {
    // send 10 pings (slowly) each with unique payload
    // send close
    // expect 10 pongs with OUR payload
    // expect close
    int pingCount = 10;
    List<WebSocketFrame> send = new ArrayList<>();
    List<WebSocketFrame> expect = new ArrayList<>();
    for (int i = 0; i < pingCount; i++) {
        String payload = String.format("ping-%d[%X]", i, i);
        send.add(new PingFrame().setPayload(payload));
        expect.add(new PongFrame().setPayload(payload));
    }
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(5);
        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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 44 with PingFrame

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

the class TestABCase2 method testCase2_4.

/**
     * Ping with 125 byte binary payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_4() throws Exception {
    byte[] payload = new byte[125];
    Arrays.fill(payload, (byte) 0xFE);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new PingFrame().setPayload(payload));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new PongFrame().setPayload(copyOf(payload)));
    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 : 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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 45 with PingFrame

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

the class TestABCase2 method testCase2_6.

/**
     * Ping with 125 byte binary payload (slow send)
     * @throws Exception on test failure
     */
@Test
public void testCase2_6() throws Exception {
    byte[] payload = new byte[125];
    Arrays.fill(payload, (byte) '6');
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new PingFrame().setPayload(payload));
    send.add(new CloseInfo(StatusCode.NORMAL, "Test 2.6").asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new PongFrame().setPayload(copyOf(payload)));
    expect.add(new CloseInfo(StatusCode.NORMAL, "Test 2.6").asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(1);
        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) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)48 Test (org.junit.Test)45 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)33 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)30 ArrayList (java.util.ArrayList)28 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)27 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)24 ByteBuffer (java.nio.ByteBuffer)19 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)17 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)14 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)4 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)4 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)4 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)3 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)3 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)3 ListenerPingPongSocket (examples.ListenerPingPongSocket)2 AbstractExtensionTest (org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest)2 FragmentExtension (org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension)2