Search in sources :

Example 6 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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));
        }
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 7 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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();
        }
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient)

Example 8 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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));
        }
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 9 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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>"));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 10 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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));
        }
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Aggregations

BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)24 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)24 Test (org.junit.Test)18 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)16 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)13 URI (java.net.URI)11 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)10 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)9 HttpResponse (org.eclipse.jetty.websocket.common.test.HttpResponse)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 StdErrLog (org.eclipse.jetty.util.log.StdErrLog)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1