use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketServerSessionTest method testUpgradeRequestResponse.
@Test
public void testUpgradeRequestResponse() throws Exception {
URI uri = server.getServerUri().resolve("/test?snack=cashews&amount=handful&brand=off");
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
// Ask the server socket for specific parameter map info
client.write(new TextFrame().setPayload("getParameterMap|snack"));
client.write(new TextFrame().setPayload("getParameterMap|amount"));
client.write(new TextFrame().setPayload("getParameterMap|brand"));
// intentionally invalid
client.write(new TextFrame().setPayload("getParameterMap|cost"));
// Read frame (hopefully text frame)
EventQueue<WebSocketFrame> frames = client.readFrames(4, 5, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
Assert.assertThat("Parameter Map[snack]", tf.getPayloadAsUTF8(), is("[cashews]"));
tf = frames.poll();
Assert.assertThat("Parameter Map[amount]", tf.getPayloadAsUTF8(), is("[handful]"));
tf = frames.poll();
Assert.assertThat("Parameter Map[brand]", tf.getPayloadAsUTF8(), is("[off]"));
tf = frames.poll();
Assert.assertThat("Parameter Map[cost]", tf.getPayloadAsUTF8(), is("<null>"));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testInternalError.
/**
* Test the requirement of responding with server terminated close code 1011 when there is an unhandled (internal server error) being produced by the
* WebSocket POJO.
* @throws Exception on test failure
*/
@Test
public void testInternalError() throws Exception {
try (BlockheadClient client = new BlockheadClient(server.getServerUri());
StacklessLogging stackless = new StacklessLogging(EventDriver.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
try (StacklessLogging context = new StacklessLogging(EventDriver.class)) {
// Generate text frame
client.write(new TextFrame().setPayload("CRASH"));
// Read frame (hopefully close frame)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
Frame cf = frames.poll();
CloseInfo close = new CloseInfo(cf);
Assert.assertThat("Close Frame.status code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
}
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class ManyConnectionsCleanupTest method fastClose.
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 ManyConnectionsCleanupTest 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,2,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 ChromeTest method testUpgradeWithWebkitDeflateExtension.
@Test
public void testUpgradeWithWebkitDeflateExtension() throws Exception {
Assume.assumeTrue("Server has x-webkit-deflate-frame registered", server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame"));
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.addExtensions("x-webkit-deflate-frame");
client.setProtocols("chat");
client.connect();
client.sendStandardRequest();
HttpResponse response = client.expectUpgradeResponse();
Assert.assertThat("Response", response.getExtensionsHeader(), containsString("x-webkit-deflate-frame"));
// Generate text frame
String msg = "this is an echo ... cho ... ho ... o";
client.write(new TextFrame().setPayload(msg));
// Read frame (hopefully text frame)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg));
} finally {
client.close();
}
}
Aggregations