use of org.eclipse.jetty.websocket.common.test.BlockheadClient 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();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketCloseTest method fastClose.
@SuppressWarnings("Duplicates")
private void fastClose() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("fastclose");
client.setTimeout(1, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.readFrames(1, 1, TimeUnit.SECONDS);
CloseInfo close = new CloseInfo(StatusCode.NORMAL, "Normal");
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.NORMAL));
// Notify server of close handshake
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Fast Close Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Fast Close.statusCode", closeSocket.closeStatusCode, is(StatusCode.NORMAL));
}
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketCloseTest method dropConnection.
@SuppressWarnings("Duplicates")
private void dropConnection() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("container");
client.setTimeout(1, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.disconnect();
}
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketCloseTest method fastFail.
private void fastFail() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("fastfail");
client.setTimeout(1, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.readFrames(1, 1, TimeUnit.SECONDS);
CloseInfo close = new CloseInfo(StatusCode.NORMAL, "Normal");
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Fast Fail Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Fast Fail.statusCode", closeSocket.closeStatusCode, is(StatusCode.SERVER_ERROR));
assertThat("Fast Fail.errors", closeSocket.errors.size(), is(1));
}
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketInvalidVersionTest method testRequestVersion29.
/**
* Test the requirement of responding with an http 400 when using a Sec-WebSocket-Version that is unsupported.
* @throws Exception on test failure
*/
@Test
public void testRequestVersion29() throws Exception {
@SuppressWarnings("resource") BlockheadClient client = new BlockheadClient(server.getServerUri());
// intentionally bad version
client.setVersion(29);
try {
client.connect();
client.sendStandardRequest();
HttpResponse response = client.readResponseHeader();
Assert.assertThat("Response Status Code", response.getStatusCode(), is(400));
Assert.assertThat("Response Status Reason", response.getStatusReason(), containsString("Unsupported websocket version specification"));
Assert.assertThat("Response Versions", response.getHeader("Sec-WebSocket-Version"), is("13"));
} finally {
client.disconnect();
}
}
Aggregations