Search in sources :

Example 1 with ListenerPingPongSocket

use of examples.ListenerPingPongSocket in project jetty.project by eclipse.

the class EventDriverTest method testListenerPingPong.

@Test
public void testListenerPingPong() throws Exception {
    ListenerPingPongSocket socket = new ListenerPingPongSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.start();
        conn.open();
        driver.incomingFrame(new PingFrame().setPayload("PING"));
        driver.incomingFrame(new PongFrame().setPayload("PONG"));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(4);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketPing(");
        socket.capture.pop().assertEventStartsWith("onWebSocketPong(");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose(1000,");
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) ListenerPingPongSocket(examples.ListenerPingPongSocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 2 with ListenerPingPongSocket

use of examples.ListenerPingPongSocket in project jetty.project by eclipse.

the class EventDriverTest method testListenerEmptyPingPong.

@Test
public void testListenerEmptyPingPong() throws Exception {
    ListenerPingPongSocket socket = new ListenerPingPongSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.start();
        conn.open();
        driver.incomingFrame(new PingFrame());
        driver.incomingFrame(new PongFrame());
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(4);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketPing(");
        socket.capture.pop().assertEventStartsWith("onWebSocketPong(");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose(1000,");
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) ListenerPingPongSocket(examples.ListenerPingPongSocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

ListenerPingPongSocket (examples.ListenerPingPongSocket)2 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)2 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)2 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)2 Test (org.junit.Test)2