Package org.apache.http

Examples of org.apache.http.HttpConnection


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

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

        HttpConnection conn4 = Mockito.mock(HttpConnection.class);
        HttpConnection conn5 = Mockito.mock(HttpConnection.class);
        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 testCreateNewIfExpired() throws Exception {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        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 {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.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 {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        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 {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        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 testCloseIdle() throws Exception {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);

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

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

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

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

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);
        Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
        LocalPoolEntry entry1 = future1.get(1, TimeUnit.SECONDS);
View Full Code Here

            return new LocalPoolEntry(route, conn);
        }

        @Override
        protected void closeEntry(final LocalPoolEntry entry) {
            HttpConnection conn = entry.getConnection();
            try {
                conn.close();
            } catch (IOException ignore) {
            }
        }
View Full Code Here

    }

    @Test
    public void testAdd() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn = Mockito.mock(HttpConnection.class);
        PoolEntry<String, HttpConnection> entry = pool.add(conn);
        Assert.assertEquals(1, pool.getAllocatedCount());
        Assert.assertEquals(0, pool.getAvailableCount());
        Assert.assertEquals(1, pool.getLeasedCount());
        Assert.assertEquals(0, pool.getPendingCount());
View Full Code Here

    }

    @Test
    public void testLeaseRelease() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry1 = pool.add(conn1);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry2 = pool.add(conn2);
        HttpConnection conn3 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry3 = pool.add(conn3);

        Assert.assertNotNull(entry1);
        Assert.assertNotNull(entry2);
        Assert.assertNotNull(entry3);
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.