Package org.apache.http

Examples of org.apache.http.HttpConnection


    @Test
    public void testCloseIdle() 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);

        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 {
        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, 2);
        Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
        LocalPoolEntry entry1 = future1.get(1, TimeUnit.SECONDS);
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

    }

    @Test
    public void testLeaseReleaseStateful() 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

    }

    @Test(expected=IllegalStateException.class)
    public void testReleaseInvalidEntry() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry = new LocalPoolEntry(ROUTE, conn);
        pool.free(entry, true);
    }
View Full Code Here

    }

    @Test
    public void testRemove() 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

    @SuppressWarnings("unchecked")
    @Test
    public void testShutdown() 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);

        PoolEntryFuture<LocalPoolEntry> future1 = Mockito.mock(PoolEntryFuture.class);
        pool.queue(future1);
View Full Code Here

        }
      } else {
        port = url.getServerConfig().getPort();
      }
      if (context != null) {
        HttpConnection con = getHttpConnection(context);
        if (con instanceof HttpInetConnection) {
          port = ((HttpInetConnection)con).getLocalPort();
          InetAddress addr = ((HttpInetConnection)con).getLocalAddress();
          if (hostName == null && addr != null) {
            hostName = addr.getHostName();
View Full Code Here

                userPrincipal = getAuthPrincipal(proxyAuthState);
            }
        }

        if (userPrincipal == null) {
            final HttpConnection conn = clientContext.getConnection();
            if (conn.isOpen() && conn instanceof SocketClientConnection) {
                final SSLSession sslsession = ((SocketClientConnection) conn).getSSLSession();
                if (sslsession != null) {
                    userPrincipal = sslsession.getLocalPrincipal();
                }
            }
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.