Package org.apache.http

Examples of org.apache.http.HttpConnection


       
        Iterator<HttpConnection> connectionIter =
            connectionToTimes.keySet().iterator();
       
        while (connectionIter.hasNext()) {
            HttpConnection conn = connectionIter.next();
            TimeValues times = connectionToTimes.get(conn);
            Long connectionTime = times.timeAdded;
            if (connectionTime.longValue() <= idleTimeout) {
                if (log.isDebugEnabled()) {
                    log.debug("Closing connection, connection time: "  + connectionTime);
                }
                connectionIter.remove();
                try {
                    conn.close();
                } catch (IOException ex) {
                    log.debug("I/O error closing connection", ex);
                }
            }
        }
View Full Code Here


       
        Iterator<HttpConnection> connectionIter =
            connectionToTimes.keySet().iterator();
       
        while (connectionIter.hasNext()) {
            HttpConnection conn = connectionIter.next();
            TimeValues times = connectionToTimes.get(conn);
            if(times.timeExpires <= now) {
                if (log.isDebugEnabled()) {
                    log.debug("Closing connection, expired @: "  + times.timeExpires);
                }
                connectionIter.remove();
                try {
                    conn.close();
                } catch (IOException ex) {
                    log.debug("I/O error closing connection", ex);
                }
            }
        }       
View Full Code Here

        }
    }

    @Test
    public void testLeaseRelease() throws Exception {
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn2.isOpen()).thenReturn(true);

        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
        Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn2);
View Full Code Here

    @Test
    public void testMaxLimits() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);

        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn2.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn2);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
        pool.setMaxPerRoute("somehost", 2);
        pool.setMaxPerRoute("otherhost", 1);
View Full Code Here

    @Test
    public void testConnectionRedistributionOnTotalMaxLimit() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn2.isOpen()).thenReturn(true);
        HttpConnection conn3 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn3.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1, conn2, conn3);

        HttpConnection conn4 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn4.isOpen()).thenReturn(true);
        HttpConnection conn5 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn5.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn4, conn5);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
        pool.setMaxPerRoute("somehost", 2);
        pool.setMaxPerRoute("otherhost", 2);
View Full Code Here

    @Test
    public void testStatefulConnectionRedistributionOnPerRouteMaxLimit() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn2.isOpen()).thenReturn(true);
        HttpConnection conn3 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn3.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1, conn2, conn3);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
        pool.setMaxPerRoute("somehost", 2);
        pool.setMaxTotal(2);
View Full Code Here

    @Test
    public void testCreateNewIfExpired() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);

        Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
View Full Code Here

    @Test
    public void testCloseExpired() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(Boolean.FALSE);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn2.isOpen()).thenReturn(Boolean.TRUE);

        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1, conn2);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);
View Full Code Here

    @Test
    public void testLeaseTimeout() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);

        LocalConnPool pool = new LocalConnPool(connFactory, 1, 1);

        Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
View Full Code Here

    @Test
    public void testLeaseCacnel() throws Exception {
        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(conn1.isOpen()).thenReturn(true);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);

        LocalConnPool pool = new LocalConnPool(connFactory, 1, 1);

        Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
View Full Code Here

TOP

Related Classes of org.apache.http.HttpConnection

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.