Search in sources :

Example 1 with LocalWebSocketSession

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

the class MessageWriterTest method setupSession.

@Before
public void setupSession() throws Exception {
    policy = WebSocketPolicy.newServerPolicy();
    policy.setInputBufferSize(1024);
    policy.setMaxTextMessageBufferSize(1024);
    // Container
    WebSocketContainerScope containerScope = new SimpleContainerScope(policy, bufferPool);
    // Event Driver factory
    EventDriverFactory factory = new EventDriverFactory(containerScope);
    // local socket
    EventDriver driver = factory.wrap(new TrackingSocket("local"));
    // remote socket
    socket = new TrackingSocket("remote");
    OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
    session = new LocalWebSocketSession(containerScope, testname, driver);
    session.setPolicy(policy);
    // talk to our remote socket
    session.setOutgoingHandler(socketPipe);
    // start session
    session.start();
    // open connection
    session.open();
}
Also used : EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) EventDriverFactory(org.eclipse.jetty.websocket.common.events.EventDriverFactory) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) OutgoingFrames(org.eclipse.jetty.websocket.api.extensions.OutgoingFrames) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) Before(org.junit.Before)

Example 2 with LocalWebSocketSession

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

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

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

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

the class MessageOutputStreamTest method setupSession.

@Before
public void setupSession() throws Exception {
    policy = WebSocketPolicy.newServerPolicy();
    policy.setInputBufferSize(1024);
    policy.setMaxBinaryMessageBufferSize(1024);
    // Container
    WebSocketContainerScope containerScope = new SimpleContainerScope(policy, bufferPool);
    // Event Driver factory
    EventDriverFactory factory = new EventDriverFactory(containerScope);
    // local socket
    EventDriver driver = factory.wrap(new TrackingSocket("local"));
    // remote socket
    socket = new TrackingSocket("remote");
    OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
    session = new LocalWebSocketSession(containerScope, testname, driver);
    session.setPolicy(policy);
    // talk to our remote socket
    session.setOutgoingHandler(socketPipe);
    // start session
    session.start();
    // open connection
    session.open();
}
Also used : EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) EventDriverFactory(org.eclipse.jetty.websocket.common.events.EventDriverFactory) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) OutgoingFrames(org.eclipse.jetty.websocket.api.extensions.OutgoingFrames) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) Before(org.junit.Before)

Aggregations

LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)10 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)8 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 Test (org.junit.Test)8 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)3 ListenerPingPongSocket (examples.ListenerPingPongSocket)2 OutgoingFrames (org.eclipse.jetty.websocket.api.extensions.OutgoingFrames)2 EventDriver (org.eclipse.jetty.websocket.common.events.EventDriver)2 EventDriverFactory (org.eclipse.jetty.websocket.common.events.EventDriverFactory)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)2 WebSocketContainerScope (org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope)2 Before (org.junit.Before)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