Package org.apache.http.nio.reactor

Examples of org.apache.http.nio.reactor.IOSession


    }

    @Test
    public void testSuccessfulConnect() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest.getSession()).thenReturn(session);
        BasicPoolEntryCallback callback = new BasicPoolEntryCallback();
        pool.addPending(sessionRequest, callback);
        Assert.assertEquals(1, pool.getAllocatedCount());
View Full Code Here


    }

    @Test
    public void testLeaseRelease() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        pool.addPending(sessionRequest1, new BasicPoolEntryCallback());
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        pool.addPending(sessionRequest2, new BasicPoolEntryCallback());
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        pool.addPending(sessionRequest3, new BasicPoolEntryCallback());

        Assert.assertEquals(3, pool.getAllocatedCount());
View Full Code Here

    }

    @Test
    public void testLeaseReleaseStateful() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        pool.addPending(sessionRequest1, new BasicPoolEntryCallback());
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        pool.addPending(sessionRequest2, new BasicPoolEntryCallback());
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        pool.addPending(sessionRequest3, new BasicPoolEntryCallback());

        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
View Full Code Here

    }

    @Test(expected=IllegalStateException.class)
    public void testReleaseInvalidEntry() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session = Mockito.mock(IOSession.class);
        LocalPoolEntry entry = new LocalPoolEntry("whatever", session, 0L, TimeUnit.MILLISECONDS);
        pool.freeEntry(entry, true);
    }
View Full Code Here

    }

    @Test
    public void testRemove() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        pool.addPending(sessionRequest1, new BasicPoolEntryCallback());
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        pool.addPending(sessionRequest2, new BasicPoolEntryCallback());
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        pool.addPending(sessionRequest3, new BasicPoolEntryCallback());

        Assert.assertEquals(3, pool.getAllocatedCount());
View Full Code Here

    }

    @Test
    public void testShutdown() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        pool.addPending(sessionRequest1, new BasicPoolEntryCallback());
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        pool.addPending(sessionRequest2, new BasicPoolEntryCallback());
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        pool.addPending(sessionRequest3, new BasicPoolEntryCallback());

        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
View Full Code Here

    protected void connectable(final SelectionKey key) {
    }

    protected void readable(final SelectionKey key) {
        SessionHandle handle = (SessionHandle) key.attachment();
        IOSession session = handle.getSession();
        handle.resetLastRead();

        this.eventDispatch.inputReady(session);
        if (session.hasBufferedInput()) {
            this.bufferingSessions.add(session);
        }
    }
View Full Code Here

        }
    }

    protected void writable(final SelectionKey key) {
        SessionHandle handle = (SessionHandle) key.attachment();
        IOSession session = handle.getSession();
        handle.resetLastWrite();
       
        this.eventDispatch.outputReady(session);
    }
View Full Code Here

                }
            }
        }
        if (!this.bufferingSessions.isEmpty()) {
            for (Iterator it = this.bufferingSessions.iterator(); it.hasNext(); ) {
                IOSession session = (IOSession) it.next();
                if (!session.hasBufferedInput()) {
                    it.remove();
                    continue;
                }
                try {
                    int ops = session.getEventMask();
                    if ((ops & EventMask.READ) > 0) {
                        this.eventDispatch.inputReady(session);
                        if (!session.hasBufferedInput()) {
                            it.remove();
                        }
                    }
                } catch (CancelledKeyException ex) {
                    it.remove();
View Full Code Here

    protected void timeoutCheck(final SelectionKey key, long now) {
        Object attachment = key.attachment();
        if (attachment instanceof SessionHandle) {
            SessionHandle handle = (SessionHandle) key.attachment();
            IOSession session = handle.getSession();
            int timeout = session.getSocketTimeout();
            if (timeout > 0) {
                if (handle.getLastReadTime() + timeout < now) {
                    this.eventDispatch.timeout(session);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.reactor.IOSession

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.