use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class TestABCase2 method testGenerate125OctetPingCase2_4.
@Test
public void testGenerate125OctetPingCase2_4() {
byte[] bytes = new byte[125];
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = Integer.valueOf(Integer.toOctalString(i)).byteValue();
}
WebSocketFrame pingFrame = new PingFrame().setPayload(bytes);
ByteBuffer actual = UnitGenerator.generate(pingFrame);
ByteBuffer expected = ByteBuffer.allocate(bytes.length + 32);
expected.put(new byte[] { (byte) 0x89 });
// no masking
byte b = 0x00;
b |= bytes.length & 0x7F;
expected.put(b);
expected.put(bytes);
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class TestABCase2 method testGenerateOversizedBinaryPingCase2_5_B.
@Test(expected = WebSocketException.class)
public void testGenerateOversizedBinaryPingCase2_5_B() {
byte[] bytes = new byte[126];
Arrays.fill(bytes, (byte) 0x00);
PingFrame pingFrame = new PingFrame();
// should throw exception
pingFrame.setPayload(ByteBuffer.wrap(bytes));
// FIXME: Remove? UnitGenerator.generate(pingFrame);
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testOutgoingPing.
/**
* Outgoing PING (Control Frame) should pass through extension unmodified
* @throws IOException on test failure
*/
@Test
public void testOutgoingPing() throws IOException {
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
// Setup capture of outgoing frames
OutgoingFramesCapture capture = new OutgoingFramesCapture();
// Wire up stack
ext.setNextOutgoingFrames(capture);
String payload = "Are you there?";
Frame ping = new PingFrame().setPayload(payload);
ext.outgoingFrame(ping, null, BatchMode.OFF);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.PING, 1);
WebSocketFrame actual = capture.getFrames().getFirst();
Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.PING));
Assert.assertThat("Frame.fin", actual.isFin(), is(true));
Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer(payload, StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testIncomingPing.
/**
* Incoming PING (Control Frame) should pass through extension unmodified
*/
@Test
public void testIncomingPing() {
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
// Wire up stack
ext.setNextIncomingFrames(capture);
String payload = "Are you there?";
Frame ping = new PingFrame().setPayload(payload);
ext.incomingFrame(ping);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.PING, 1);
WebSocketFrame actual = capture.getFrames().poll();
Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.PING));
Assert.assertThat("Frame.fin", actual.isFin(), is(true));
Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer(payload, StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame 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,");
}
}
Aggregations