Search in sources :

Example 6 with CloseableLocalWebSocketSession

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

the class EventDriverTest method testAdapter_ConnectClose.

@Test
public void testAdapter_ConnectClose() throws Exception {
    AdapterConnectCloseSocket socket = new AdapterConnectCloseSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(2);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AdapterConnectCloseSocket(examples.AdapterConnectCloseSocket) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 7 with CloseableLocalWebSocketSession

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

the class EventDriverTest method testAnnotated_InputStream.

@Test
public void testAnnotated_InputStream() throws IOException, TimeoutException, InterruptedException {
    AnnotatedBinaryStreamSocket socket = new AnnotatedBinaryStreamSocket();
    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().assertEventRegex("^onBinary\\(.*InputStream.*");
        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) AnnotatedBinaryStreamSocket(examples.AnnotatedBinaryStreamSocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 8 with CloseableLocalWebSocketSession

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

the class EventDriverTest method testListenerBasic_Text.

@Test
public void testListenerBasic_Text() throws Exception {
    ListenerBasicSocket socket = new ListenerBasicSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.start();
        conn.open();
        driver.incomingFrame(new TextFrame().setPayload("Hello World"));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(3);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketText(\"Hello World\")");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose(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) ListenerBasicSocket(examples.ListenerBasicSocket) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) 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