Search in sources :

Example 11 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient 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));
        }
    }
}
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 12 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient in project jetty.project by eclipse.

the class ConfiguratorTest method testUniqueUserPropsConfigurator.

@Test
public void testUniqueUserPropsConfigurator() throws Exception {
    URI uri = baseServerUri.resolve("/unique-user-props");
    // First request
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("apple"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [apple] = \"fruit from tree\""));
    }
    // Second request
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("apple"));
        client.write(new TextFrame().setPayload("blueberry"));
        EventQueue<WebSocketFrame> frames = client.readFrames(2, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        // should have no value
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [apple] = <null>"));
        frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [blueberry] = \"fruit from bush\""));
    }
}
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 13 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient in project jetty.project by eclipse.

the class ConfiguratorTest method testNoExtensionsConfigurator.

@Test
public void testNoExtensionsConfigurator() throws Exception {
    URI uri = baseServerUri.resolve("/no-extensions");
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addExtensions("identity");
        client.connect();
        client.sendStandardRequest();
        HttpResponse response = client.expectUpgradeResponse();
        assertThat("response.extensions", response.getExtensionsHeader(), nullValue());
        client.write(new TextFrame().setPayload("NegoExts"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        assertThat("Frame Response", frame.getPayloadAsUTF8(), is("negotiatedExtensions=[]"));
    }
}
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) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 14 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient in project jetty.project by eclipse.

the class ConfiguratorTest method testUserPropsAddress.

@Test
public void testUserPropsAddress() throws Exception {
    URI uri = baseServerUri.resolve("/addr");
    // First request
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        InetSocketAddress expectedLocal = client.getLocalSocketAddress();
        InetSocketAddress expectedRemote = client.getRemoteSocketAddress();
        client.write(new TextFrame().setPayload("addr"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        StringWriter expected = new StringWriter();
        PrintWriter out = new PrintWriter(expected);
        // local <-> remote are opposite on server (duh)
        out.printf("[javax.websocket.endpoint.localAddress] = %s%n", toSafeAddr(expectedRemote));
        out.printf("[javax.websocket.endpoint.remoteAddress] = %s%n", toSafeAddr(expectedLocal));
        out.printf("[found.local] = %s%n", toSafeAddr(expectedRemote));
        out.printf("[found.remote] = %s%n", toSafeAddr(expectedLocal));
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is(expected.toString()));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StringWriter(java.io.StringWriter) InetSocketAddress(java.net.InetSocketAddress) 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) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 15 with IBlockheadClient

use of org.eclipse.jetty.websocket.common.test.IBlockheadClient in project jetty.project by eclipse.

the class ConfiguratorTest method testProtocol_Single.

/**
     * Test of Sec-WebSocket-Protocol, as seen in RFC-6455, 1 protocol
     * @throws Exception on test failure
     */
@Test
public void testProtocol_Single() throws Exception {
    URI uri = baseServerUri.resolve("/protocols");
    ProtocolsConfigurator.seenProtocols.set(null);
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("Sec-WebSocket-Protocol: echo\r\n");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("getProtocols"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested Protocols: [\"echo\"]"));
    }
}
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)

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