Search in sources :

Example 16 with PongFrame

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

use of org.eclipse.jetty.websocket.common.frames.PongFrame 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)

Example 18 with PongFrame

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

the class TestABCase2 method testCase2_10.

/**
     * 10 pings
     * @throws Exception on test failure
     */
@Test
public void testCase2_10() throws Exception {
    // send 10 pings each with unique payload
    // send close
    // expect 10 pongs with our unique 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.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 19 with PongFrame

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

the class TestABCase2 method testCase2_2.

/**
     * Ping with small text payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_2() throws Exception {
    byte[] payload = StringUtil.getUtf8Bytes("Hello world");
    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 20 with PongFrame

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

the class WebSocketFrame method copy.

public static WebSocketFrame copy(Frame original) {
    WebSocketFrame copy;
    switch(original.getOpCode()) {
        case OpCode.BINARY:
            copy = new BinaryFrame();
            break;
        case OpCode.TEXT:
            copy = new TextFrame();
            break;
        case OpCode.CLOSE:
            copy = new CloseFrame();
            break;
        case OpCode.CONTINUATION:
            copy = new ContinuationFrame();
            break;
        case OpCode.PING:
            copy = new PingFrame();
            break;
        case OpCode.PONG:
            copy = new PongFrame();
            break;
        default:
            throw new IllegalArgumentException("Cannot copy frame with opcode " + original.getOpCode() + " - " + original);
    }
    copy.copyHeaders(original);
    ByteBuffer payload = original.getPayload();
    if (payload != null) {
        ByteBuffer payloadCopy = ByteBuffer.allocate(payload.remaining());
        payloadCopy.put(payload.slice()).flip();
        copy.setPayload(payloadCopy);
    }
    return copy;
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)24 Test (org.junit.Test)21 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)19 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)19 ArrayList (java.util.ArrayList)18 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)17 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)17 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)9 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)9 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)7 ByteBuffer (java.nio.ByteBuffer)3 ListenerPingPongSocket (examples.ListenerPingPongSocket)2 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)2 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)2 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)2 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)2 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)1 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)1 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)1 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)1