use of org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule in project jetty.project by eclipse.
the class TooFastClientTest method testUpgradeWithSmallFrames.
@Test
@Ignore("RELEASE")
public void testUpgradeWithSmallFrames() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.connect();
// Create ByteBuffer representing the initial opening network packet from the client
ByteBuffer initialPacket = ByteBuffer.allocate(4096);
BufferUtil.clearToFill(initialPacket);
// Add upgrade request to packet
StringBuilder upgradeRequest = client.generateUpgradeRequest();
ByteBuffer upgradeBuffer = BufferUtil.toBuffer(upgradeRequest.toString(), StandardCharsets.UTF_8);
initialPacket.put(upgradeBuffer);
// Add text frames
Generator generator = new Generator(WebSocketPolicy.newClientPolicy(), new LeakTrackingBufferPoolRule("Generator"));
String msg1 = "Echo 1";
String msg2 = "This is also an echooooo!";
TextFrame frame1 = new TextFrame().setPayload(msg1);
TextFrame frame2 = new TextFrame().setPayload(msg2);
// Need to set frame mask (as these are client frames)
byte[] mask = new byte[] { 0x11, 0x22, 0x33, 0x44 };
frame1.setMask(mask);
frame2.setMask(mask);
generator.generateWholeFrame(frame1, initialPacket);
generator.generateWholeFrame(frame2, initialPacket);
// Write packet to network
BufferUtil.flipToFlush(initialPacket, 0);
client.writeRaw(initialPacket);
// Expect upgrade
client.expectUpgradeResponse();
// Read frames (hopefully text frames)
EventQueue<WebSocketFrame> frames = client.readFrames(2, 1, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
Assert.assertThat("Text Frame/msg1", tf.getPayloadAsUTF8(), is(msg1));
tf = frames.poll();
Assert.assertThat("Text Frame/msg2", tf.getPayloadAsUTF8(), is(msg2));
} finally {
client.close();
}
}
Aggregations