Search in sources :

Example 1 with CloseableLocalWebSocketSession

use of org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession in project jetty.project by eclipse.

the class EventDriverTest method testAnnotated_ByteArray.

@Test
public void testAnnotated_ByteArray() throws Exception {
    AnnotatedBinaryArraySocket socket = new AnnotatedBinaryArraySocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingFrame(makeBinaryFrame("Hello World", true));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(3);
        socket.capture.pop().assertEventStartsWith("onConnect");
        socket.capture.pop().assertEvent("onBinary([11],0,11)");
        socket.capture.pop().assertEventStartsWith("onClose(1000,");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AnnotatedBinaryArraySocket(examples.AnnotatedBinaryArraySocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 2 with CloseableLocalWebSocketSession

use of org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession 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 3 with CloseableLocalWebSocketSession

use of org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession in project jetty.project by eclipse.

the class EventDriverTest method testAnnotated_Error.

@Test
public void testAnnotated_Error() throws Exception {
    AnnotatedTextSocket socket = new AnnotatedTextSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingError(new WebSocketException("oof"));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(3);
        socket.capture.pop().assertEventStartsWith("onConnect");
        socket.capture.pop().assertEventStartsWith("onError(WebSocketException: oof)");
        socket.capture.pop().assertEventStartsWith("onClose(1000,");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AnnotatedTextSocket(examples.AnnotatedTextSocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 4 with CloseableLocalWebSocketSession

use of org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession in project jetty.project by eclipse.

the class EventDriverTest method testAnnotated_Frames.

@Test
public void testAnnotated_Frames() throws Exception {
    AnnotatedFramesSocket socket = new AnnotatedFramesSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingFrame(new PingFrame().setPayload("PING"));
        driver.incomingFrame(new TextFrame().setPayload("Text Me"));
        driver.incomingFrame(new BinaryFrame().setPayload("Hello Bin"));
        driver.incomingFrame(new CloseInfo(StatusCode.SHUTDOWN, "testcase").asFrame());
        socket.capture.assertEventCount(6);
        socket.capture.pop().assertEventStartsWith("onConnect(");
        socket.capture.pop().assertEventStartsWith("onFrame(PING[");
        socket.capture.pop().assertEventStartsWith("onFrame(TEXT[");
        socket.capture.pop().assertEventStartsWith("onFrame(BINARY[");
        socket.capture.pop().assertEventStartsWith("onFrame(CLOSE[");
        socket.capture.pop().assertEventStartsWith("onClose(1001,");
    }
}
Also used : AnnotatedFramesSocket(examples.AnnotatedFramesSocket) LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 5 with CloseableLocalWebSocketSession

use of org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession 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

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)8 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Test (org.junit.Test)8 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)3 ListenerPingPongSocket (examples.ListenerPingPongSocket)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 AdapterConnectCloseSocket (examples.AdapterConnectCloseSocket)1 AnnotatedBinaryArraySocket (examples.AnnotatedBinaryArraySocket)1 AnnotatedBinaryStreamSocket (examples.AnnotatedBinaryStreamSocket)1 AnnotatedFramesSocket (examples.AnnotatedFramesSocket)1 AnnotatedTextSocket (examples.AnnotatedTextSocket)1 ListenerBasicSocket (examples.ListenerBasicSocket)1 WebSocketException (org.eclipse.jetty.websocket.api.WebSocketException)1 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)1