Package org.eclipse.jetty.websocket.common.test.BlockheadServer

Examples of org.eclipse.jetty.websocket.common.test.BlockheadServer.ServerConnection


            JettyTrackingSocket wsocket = new JettyTrackingSocket();

            URI wsUri = server.getWsUri();
            Future<Session> future = fact.connect(wsocket,wsUri);

            ServerConnection ssocket = server.accept();
            ssocket.upgrade();

            future.get(500,TimeUnit.MILLISECONDS);

            Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));
View Full Code Here


            JettyTrackingSocket wsocket = new JettyTrackingSocket();

            URI wsUri = server.getWsUri();
            Future<Session> future = factSmall.connect(wsocket,wsUri);

            ServerConnection ssocket = server.accept();
            ssocket.upgrade();

            future.get(500,TimeUnit.MILLISECONDS);

            Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));

            int length = bufferSize + (bufferSize / 2); // 1.5 times buffer size
            ssocket.write(0x80 | 0x01); // FIN + TEXT
            ssocket.write(0x7E); // No MASK and 2 bytes length
            ssocket.write(length >> 8); // first length byte
            ssocket.write(length & 0xFF); // second length byte
            for (int i = 0; i < length; ++i)
            {
                ssocket.write('x');
            }
            ssocket.flush();

            Assert.assertTrue(wsocket.dataLatch.await(1000,TimeUnit.SECONDS));
        }
        finally
        {
View Full Code Here

            URI wsUri = server.getWsUri();
            ClientUpgradeRequest request = new ClientUpgradeRequest();
            request.setSubProtocols("echo");
            Future<Session> future = client.connect(cliSock,wsUri,request);

            final ServerConnection srvSock = server.accept();
            srvSock.upgrade();

            Session sess = future.get(500,TimeUnit.MILLISECONDS);
            Assert.assertThat("Session",sess,notNullValue());
            Assert.assertThat("Session.open",sess.isOpen(),is(true));
            Assert.assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue());
            Assert.assertThat("Session.upgradeResponse",sess.getUpgradeResponse(),notNullValue());

            cliSock.assertWasOpened();
            cliSock.assertNotClosed();

            Assert.assertThat("client.connectionManager.sessions.size",client.getConnectionManager().getSessions().size(),is(1));

            RemoteEndpoint remote = cliSock.getSession().getRemote();
            remote.sendStringByFuture("Hello World!");
            if (remote.getBatchMode() == BatchMode.ON)
                remote.flush();
            srvSock.echoMessage(1,500,TimeUnit.MILLISECONDS);
            // wait for response from server
            cliSock.waitForMessage(500,TimeUnit.MILLISECONDS);
           
            Set<WebSocketSession> open = client.getOpenSessions();
            Assert.assertThat("Open Sessions.size", open.size(), is(1));

            cliSock.assertMessage("Hello World!");
            cliSock.close();
            srvSock.close();
           
            cliSock.waitForClose(500,TimeUnit.MILLISECONDS);
            open = client.getOpenSessions();
            Assert.assertThat("Open Sessions.size", open.size(), is(0));
        }
View Full Code Here

        // Client connects
        CookieTrackingSocket clientSocket = new CookieTrackingSocket();
        Future<Session> clientConnectFuture = client.connect(clientSocket,server.getWsUri());

        // Server accepts connect
        ServerConnection serverConn = server.accept();

        // client confirms upgrade and receipt of frame
        String serverCookies = confirmClientUpgradeAndCookies(clientSocket,clientConnectFuture,serverConn);

        Assert.assertThat("Cookies seen at server side",serverCookies,containsString("hello=\"world\""));
View Full Code Here

        // Client connects
        CookieTrackingSocket clientSocket = new CookieTrackingSocket();
        Future<Session> clientConnectFuture = client.connect(clientSocket,server.getWsUri(),request);

        // Server accepts connect
        ServerConnection serverConn = server.accept();

        // client confirms upgrade and receipt of frame
        String serverCookies = confirmClientUpgradeAndCookies(clientSocket,clientConnectFuture,serverConn);

        Assert.assertThat("Cookies seen at server side",serverCookies,containsString("hello=\"world\""));
View Full Code Here

            // Open connection
            URI wsURI = server.getWsUri();
            client.connect(websocket,wsURI);

            // Accept incoming connection
            ServerConnection socket = server.accept();
            socket.setSoTimeout(2000); // timeout

            // Issue upgrade
            // Add the extra problematic header that triggers bug found in jetty-io
            socket.addResponseHeader("Transfer-Encoding","chunked");
            socket.upgrade();

            // Wait for proper upgrade
            Assert.assertTrue("Timed out waiting for Client side WebSocket open event",websocket.openLatch.await(1,TimeUnit.SECONDS));

            // Have server write frame.
            byte payload[] = new byte[bufferSize / 2];
            Arrays.fill(payload,(byte)'x');
            ByteBuffer serverFrame = BufferUtil.allocate(bufferSize);
            BufferUtil.flipToFill(serverFrame);
            serverFrame.put((byte)(0x80 | 0x01)); // FIN + TEXT
            serverFrame.put((byte)0x7E); // No MASK and 2 bytes length
            serverFrame.put((byte)(payload.length >> 8)); // first length byte
            serverFrame.put((byte)(payload.length & 0xFF)); // second length byte
            serverFrame.put(payload);
            BufferUtil.flipToFlush(serverFrame,0);
            byte buf[] = BufferUtil.toArray(serverFrame);
            socket.write(buf,0,buf.length);
            socket.flush();

            Assert.assertTrue(websocket.dataLatch.await(1000,TimeUnit.SECONDS));
        }
        finally
        {
View Full Code Here

        JettyTrackingSocket wsocket = new JettyTrackingSocket();

        URI wsUri = server.getWsUri();
        Future<Session> future = client.connect(wsocket,wsUri);

        ServerConnection ssocket = server.accept();
        ssocket.upgrade();

        // Validate that we are connected
        future.get(500,TimeUnit.MILLISECONDS);
        wsocket.waitForConnected(500,TimeUnit.MILLISECONDS);
View Full Code Here

        JettyTrackingSocket wsocket = new JettyTrackingSocket();

        URI wsUri = server.getWsUri();
        Future<Session> future = client.connect(wsocket,wsUri);

        ServerConnection ssocket = server.accept();
        ssocket.upgrade();

        // Validate that we are connected
        future.get(500,TimeUnit.MILLISECONDS);
        wsocket.waitForConnected(500,TimeUnit.MILLISECONDS);

        // Have server disconnect abruptly
        ssocket.disconnect();

        // Wait for close (as response to idle timeout)
        wsocket.waitForClose(10,TimeUnit.SECONDS);

        // Client Socket should see a close event, with status NO_CLOSE
View Full Code Here

        client.setMaxIdleTimeout(60000);

        URI wsUri = server.getWsUri();
        Future<Session> future = client.connect(tsocket,wsUri);

        ServerConnection sconnection = server.accept();
        sconnection.setSoTimeout(60000);
        sconnection.upgrade();

        // Confirm connected
        future.get(500,TimeUnit.MILLISECONDS);
        tsocket.waitForConnected(500,TimeUnit.MILLISECONDS);
View Full Code Here

        client.setMaxIdleTimeout(60000);

        URI wsUri = server.getWsUri();
        Future<Session> clientConnectFuture = client.connect(clientSocket,wsUri);

        ServerConnection serverConn = server.accept();
        serverConn.setSoTimeout(60000);
        serverConn.upgrade();

        // Confirm connected
        clientConnectFuture.get(500,TimeUnit.MILLISECONDS);
        clientSocket.waitForConnected(500,TimeUnit.MILLISECONDS);

        // Have server write slowly.
        int messageCount = 1000;

        ServerWriteThread writer = new ServerWriteThread(serverConn);
        writer.setMessageCount(messageCount);
        writer.setMessage("Hello");
        writer.setSlowness(10);
        writer.start();
        writer.join();

        // Verify receive
        Assert.assertThat("Message Receive Count",clientSocket.messageQueue.size(),is(messageCount));

        // Close
        serverConn.close(StatusCode.NORMAL);

        Assert.assertTrue("Client Socket Closed",clientSocket.closeLatch.await(10,TimeUnit.SECONDS));
        clientSocket.assertCloseCode(StatusCode.NORMAL);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.websocket.common.test.BlockheadServer.ServerConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.