Search in sources :

Example 76 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo 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 77 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo 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 78 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase7_3 method testCase7_3_5GenerateCloseWithStatusMaxReason.

@Test
public void testCase7_3_5GenerateCloseWithStatusMaxReason() {
    StringBuilder message = new StringBuilder();
    for (int i = 0; i < 123; ++i) {
        message.append("*");
    }
    CloseInfo close = new CloseInfo(1000, message.toString());
    ByteBuffer actual = UnitGenerator.generate(close.asFrame());
    ByteBuffer expected = ByteBuffer.allocate(132);
    byte[] messageBytes = message.toString().getBytes(StandardCharsets.UTF_8);
    expected.put(new byte[] { (byte) 0x88 });
    // no masking
    byte b = 0x00;
    b |= (messageBytes.length + 2) & 0x7F;
    expected.put(b);
    expected.putShort((short) 1000);
    expected.put(messageBytes);
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 79 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase7_3 method testCase7_3_4GenerateCloseWithStatusReason.

@Test
public void testCase7_3_4GenerateCloseWithStatusReason() {
    String message = "bad cough";
    byte[] messageBytes = message.getBytes();
    CloseInfo close = new CloseInfo(1000, message);
    ByteBuffer actual = UnitGenerator.generate(close.asFrame());
    ByteBuffer expected = ByteBuffer.allocate(32);
    expected.put(new byte[] { (byte) 0x88 });
    // no masking
    byte b = 0x00;
    b |= (message.length() + 2) & 0x7F;
    expected.put(b);
    expected.putShort((short) 1000);
    expected.put(messageBytes);
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 80 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase7_3 method testCase7_3_3GenerateCloseWithStatus.

@Test
public void testCase7_3_3GenerateCloseWithStatus() {
    CloseInfo close = new CloseInfo(1000);
    ByteBuffer actual = UnitGenerator.generate(close.asFrame());
    ByteBuffer expected = ByteBuffer.allocate(5);
    expected.put(new byte[] { (byte) 0x88, (byte) 0x02, 0x03, (byte) 0xe8 });
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)151 Test (org.junit.Test)129 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)118 ArrayList (java.util.ArrayList)104 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)68 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)55 ByteBuffer (java.nio.ByteBuffer)48 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)30 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)27 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)17 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)14 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)10 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4