Package org.eclipse.jetty.spdy.api

Examples of org.eclipse.jetty.spdy.api.Session


    {
        final CountDownLatch slowServerLatch = new CountDownLatch(1);
        final CountDownLatch fastServerLatch = new CountDownLatch(1);
        final String fastPath = "/fast";
        final String slowPath = "/slow";
        Session session = startClient(version, startHTTPServer(version, new AbstractHandler()
        {
            @Override
            public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
                    throws IOException, ServletException
            {
                try
                {
                    request.setHandled(true);
                    switch (target)
                    {
                        case slowPath:
                            Assert.assertTrue(fastServerLatch.await(10, TimeUnit.SECONDS));
                            slowServerLatch.countDown();
                            break;
                        case fastPath:
                            fastServerLatch.countDown();
                            break;
                        default:
                            Assert.fail();
                            break;
                    }
                }
                catch (InterruptedException x)
                {
                    throw new ServletException(x);
                }
            }
        }, 30000), null);

        // Perform slow request. This will wait on server side until the fast request wakes it up
        Fields headers = createHeaders(slowPath);
        final CountDownLatch slowClientLatch = new CountDownLatch(1);
        session.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
        {
            @Override
            public void onReply(Stream stream, ReplyInfo replyInfo)
            {
                Fields replyHeaders = replyInfo.getHeaders();
                Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
                slowClientLatch.countDown();
            }
        });

        // Perform the fast request. This will wake up the slow request
        headers = createHeaders(fastPath);
        final CountDownLatch fastClientLatch = new CountDownLatch(1);
        session.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
        {
            @Override
            public void onReply(Stream stream, ReplyInfo replyInfo)
            {
                Fields replyHeaders = replyInfo.getHeaders();
View Full Code Here


    @Test
    public void testSendDataBeforeReplyIsIllegal() throws Exception
    {
        final CountDownLatch resetLatch = new CountDownLatch(1);
        final CountDownLatch latch = new CountDownLatch(1);
        Session session = startClient(startServer(new ServerSessionFrameListener.Adapter()
        {
            @Override
            public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
            {
                try
                {
                    stream.data(new StringDataInfo("failure", true), new Callback.Adapter());
                    return null;
                }
                catch (IllegalStateException x)
                {
                    latch.countDown();
                    return null;
                }
            }
        }), new SessionFrameListener.Adapter()
        {
            @Override
            public void onRst(Session session, RstInfo rstInfo)
            {
                Assert.assertSame(StreamStatus.PROTOCOL_ERROR, rstInfo.getStreamStatus());
                resetLatch.countDown();
            }
        });
        session.syn(new SynInfo(new Fields(), true), null);
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
    }
View Full Code Here

    public void testReceiveDataBeforeReplyIsIllegal() throws Exception
    {
        ServerSocketChannel server = ServerSocketChannel.open();
        server.bind(new InetSocketAddress("localhost", 0));

        Session session = startClient(new InetSocketAddress("localhost", server.socket().getLocalPort()), null);
        session.syn(new SynInfo(new Fields(), true), null);

        SocketChannel channel = server.accept();
        ByteBuffer readBuffer = ByteBuffer.allocate(1024);
        channel.read(readBuffer);
        readBuffer.flip();
        int streamId = readBuffer.getInt(8);

        Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
        byte[] bytes = new byte[1];
        ByteBuffer writeBuffer = generator.data(streamId, bytes.length, new BytesDataInfo(bytes, true));
        channel.write(writeBuffer);
        assertThat("data is fully written", writeBuffer.hasRemaining(),is(false));

        readBuffer.clear();
        channel.read(readBuffer);
        readBuffer.flip();
        Assert.assertEquals(ControlFrameType.RST_STREAM.getCode(), readBuffer.getShort(2));
        Assert.assertEquals(streamId, readBuffer.getInt(8));

        session.goAway(new GoAwayInfo(5, TimeUnit.SECONDS));

        server.close();
    }
View Full Code Here

    }

    @Test(expected = IllegalStateException.class)
    public void testSendDataAfterCloseIsIllegal() throws Exception
    {
        Session session = startClient(startServer(null), null);
        Stream stream = session.syn(new SynInfo(5, TimeUnit.SECONDS, new Fields(), true, (byte)0), null);
        stream.data(new StringDataInfo("test", true));
    }
View Full Code Here

    }

    @Test(expected = IllegalStateException.class)
    public void testSendHeadersAfterCloseIsIllegal() throws Exception
    {
        Session session = startClient(startServer(null), null);
        Stream stream = session.syn(new SynInfo(5, TimeUnit.SECONDS, new Fields(), true, (byte)0), null);
        stream.headers(new HeadersInfo(new Fields(), true));
    }
View Full Code Here

    public void testServerClosesStreamTwice() throws Exception
    {
        ServerSocketChannel server = ServerSocketChannel.open();
        server.bind(new InetSocketAddress("localhost", 0));

        Session session = startClient(new InetSocketAddress("localhost", server.socket().getLocalPort()), null);
        final CountDownLatch dataLatch = new CountDownLatch(2);
        session.syn(new SynInfo(new Fields(), false), new StreamFrameListener.Adapter()
        {
            @Override
            public void onData(Stream stream, DataInfo dataInfo)
            {
                dataLatch.countDown();
            }
        });

        SocketChannel channel = server.accept();
        ByteBuffer readBuffer = ByteBuffer.allocate(1024);
        channel.read(readBuffer);
        readBuffer.flip();
        int streamId = readBuffer.getInt(8);

        Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());

        ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Fields()));
        channel.write(writeBuffer);
        assertThat("SynReply is fully written", writeBuffer.hasRemaining(), is(false));

        byte[] bytes = new byte[1];
        writeBuffer = generator.data(streamId, bytes.length, new BytesDataInfo(bytes, true));
        channel.write(writeBuffer);
        assertThat("data is fully written", writeBuffer.hasRemaining(), is(false));

        // Write again to simulate the faulty condition
        writeBuffer.flip();
        channel.write(writeBuffer);
        assertThat("data is fully written", writeBuffer.hasRemaining(), is(false));

        Assert.assertFalse(dataLatch.await(1, TimeUnit.SECONDS));

        session.goAway(new GoAwayInfo(5, TimeUnit.SECONDS));

        server.close();
    }
View Full Code Here

                    }
                };
            }
        };

        Session session = startClient(startServer(serverSessionFrameListener), null);

        final CountDownLatch latch = new CountDownLatch(1);
        session.syn(new SynInfo(new Fields(), false), new StreamFrameListener.Adapter()
        {
            @Override
            public void onReply(Stream stream, ReplyInfo replyInfo)
            {
                Fields headers = new Fields();
View Full Code Here

            {
                ref.set(pingInfo);
                latch.countDown();
            }
        };
        Session session = startClient(startServer(null), clientSessionFrameListener);
        PingResultInfo pingResultInfo = session.ping(new PingInfo(5, TimeUnit.SECONDS));
        Assert.assertEquals(1, pingResultInfo.getPingId() % 2);

        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
        PingResultInfo pongInfo = ref.get();
        Assert.assertNotNull(pongInfo);
View Full Code Here

    }

    @Test
    public void testSessionClosedIsRemovedFromClientFactory() throws Exception
    {
        Session session = startClient(startServer(null), null);

        session.goAway(new GoAwayInfo(5, TimeUnit.SECONDS));

        for (int i=0;i<10;i++)
        {
            // Sleep a while to allow the factory to remove the session
            // since it is done asynchronously by the selector thread
View Full Code Here

    }

    @Test
    public void testSessionClosedIsRemovedFromServerConnector() throws Exception
    {
        Session session = startClient(startServer(null), null);

        session.goAway(new GoAwayInfo(5, TimeUnit.SECONDS));

        // Sleep a while to allow the connector to remove the session
        // since it is done asynchronously by the selector thread
        TimeUnit.SECONDS.sleep(1);
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.spdy.api.Session

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.