hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1405507 [3/3] - in /httpcomponents/httpclient/trunk: ./ fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/conn/ httpclient/src/main/java/org/apache/http/conn/ httpclient/src/main/java/o...
Date Sun, 04 Nov 2012 07:37:52 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java Sun Nov  4 07:37:50 2012
@@ -53,7 +53,7 @@ import org.apache.http.entity.InputStrea
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicResponseHandler;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
@@ -181,7 +181,7 @@ public class TestContentCodings extends 
          */
         int clients = 100;
 
-        PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
         cm.setMaxTotal(clients);
 
         this.httpclient = new HttpClientBuilder().setConnectionManager(cm).build();

Copied: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java (from r1398094, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java?p2=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java&p1=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java&r1=1398094&r2=1405507&rev=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java Sun Nov  4 07:37:50 2012
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.http.impl.conn;
+package org.apache.http.impl.client.integration;
 
 import java.net.InetSocketAddress;
 import java.util.concurrent.TimeUnit;
@@ -36,8 +36,9 @@ import org.apache.http.client.ClientProt
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.util.EntityUtils;
@@ -55,7 +56,7 @@ public class TestIdleConnectionEviction 
 
     @Test
     public void testIdleConnectionEviction() throws Exception {
-        PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
         cm.setDefaultMaxPerRoute(10);
         cm.setMaxTotal(50);
 
@@ -131,10 +132,10 @@ public class TestIdleConnectionEviction 
 
     public static class IdleConnectionMonitor extends Thread {
 
-        private final ClientConnectionManager cm;
+        private final HttpClientConnectionManager cm;
         private volatile boolean shutdown;
 
-        public IdleConnectionMonitor(final ClientConnectionManager cm) {
+        public IdleConnectionMonitor(final HttpClientConnectionManager cm) {
             super();
             this.cm = cm;
             setDaemon(true);

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java Sun Nov  4 07:37:50 2012
@@ -27,6 +27,7 @@ package org.apache.http.impl.client.inte
 
 import java.io.IOException;
 
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -35,10 +36,9 @@ import org.apache.http.HttpStatus;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.ManagedClientConnection;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
@@ -91,14 +91,14 @@ public class TestStatefulConnManagement 
         HttpParams params = new BasicHttpParams();
         HttpConnectionParams.setConnectionTimeout(params, 10);
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(workerCount);
         mgr.setDefaultMaxPerRoute(workerCount);
 
         UserTokenHandler userTokenHandler = new UserTokenHandler() {
 
             public Object getUserToken(final HttpContext context) {
-                Integer id = (Integer) context.getAttribute("user");
+                String id = (String) context.getAttribute("user");
                 return id;
             }
 
@@ -113,9 +113,10 @@ public class TestStatefulConnManagement 
         HttpWorker[] workers = new HttpWorker[workerCount];
         for (int i = 0; i < contexts.length; i++) {
             HttpContext context = new BasicHttpContext();
-            context.setAttribute("user", Integer.valueOf(i));
             contexts[i] = context;
-            workers[i] = new HttpWorker(context, requestCount, target, this.httpclient);
+            workers[i] = new HttpWorker(
+                    "user" + i,
+                    context, requestCount, target, this.httpclient);
         }
 
         for (int i = 0; i < workers.length; i++) {
@@ -134,12 +135,12 @@ public class TestStatefulConnManagement 
 
         for (int i = 0; i < contexts.length; i++) {
             HttpContext context = contexts[i];
-            Integer id = (Integer) context.getAttribute("user");
+            String uid = (String) context.getAttribute("user");
 
             for (int r = 0; r < requestCount; r++) {
-                Integer state = (Integer) context.getAttribute("r" + r);
+                String state = (String) context.getAttribute("r" + r);
                 Assert.assertNotNull(state);
-                Assert.assertEquals(id, state);
+                Assert.assertEquals(uid, state);
             }
         }
 
@@ -147,6 +148,7 @@ public class TestStatefulConnManagement 
 
     static class HttpWorker extends Thread {
 
+        private final String uid;
         private final HttpContext context;
         private final int requestCount;
         private final HttpHost target;
@@ -156,11 +158,13 @@ public class TestStatefulConnManagement 
         private volatile int count;
 
         public HttpWorker(
+                final String uid,
                 final HttpContext context,
                 int requestCount,
                 final HttpHost target,
                 final HttpClient httpclient) {
             super();
+            this.uid = uid;
             this.context = context;
             this.requestCount = requestCount;
             this.target = target;
@@ -179,6 +183,7 @@ public class TestStatefulConnManagement 
         @Override
         public void run() {
             try {
+                this.context.setAttribute("user", this.uid);
                 for (int r = 0; r < this.requestCount; r++) {
                     HttpGet httpget = new HttpGet("/");
                     HttpResponse response = this.httpclient.execute(
@@ -187,11 +192,15 @@ public class TestStatefulConnManagement 
                             this.context);
                     this.count++;
 
-                    ManagedClientConnection conn = (ManagedClientConnection) this.context.getAttribute(
+                    HttpClientConnection conn = (HttpClientConnection) this.context.getAttribute(
                             ExecutionContext.HTTP_CONNECTION);
-
-                    this.context.setAttribute("r" + r, conn.getState());
-
+                    HttpContext connContext = (HttpContext) conn;
+                    String connuid = (String) connContext.getAttribute("user");
+                    if (connuid == null) {
+                        connContext.setAttribute("user", this.uid);
+                        connuid = this.uid;
+                    }
+                    this.context.setAttribute("r" + r, connuid);
                     EntityUtils.consume(response.getEntity());
                 }
 
@@ -214,7 +223,7 @@ public class TestStatefulConnManagement 
         this.localServer.register("*", new SimpleService());
 
         // We build a client with 2 max active // connections, and 2 max per route.
-        PoolingClientConnectionManager connMngr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager connMngr = new PoolingHttpClientConnectionManager();
         connMngr.setMaxTotal(maxConn);
         connMngr.setDefaultMaxPerRoute(maxConn);
 

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,308 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.net.Socket;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.conn.ConnectionRequest;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.HttpConnectionFactory;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.params.HttpParams;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestBasicHttpClientConnectionManager {
+
+    private DefaultClientConnection conn;
+    private HttpConnectionFactory<DefaultClientConnection> connFactory;
+    private Socket socket;
+    private SchemeSocketFactory plainSocketFactory;
+    private SchemeRegistry schemeRegistry;
+    private DnsResolver dnsResolver;
+    private BasicHttpClientConnectionManager mgr;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setup() throws Exception {
+        conn = Mockito.mock(DefaultClientConnection.class);
+        connFactory = Mockito.mock(HttpConnectionFactory.class);
+        Mockito.when(connFactory.create()).thenReturn(conn);
+        socket = Mockito.mock(Socket.class);
+        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+
+        Scheme http = new Scheme("http", 80, plainSocketFactory);
+        schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(http);
+
+        dnsResolver = Mockito.mock(DnsResolver.class);
+
+        mgr = new BasicHttpClientConnectionManager(schemeRegistry, dnsResolver, connFactory);
+    }
+
+    @Test
+    public void testLeaseReleaseNonReusable() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+        Assert.assertFalse(conn1.isOpen());
+
+        mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
+
+        Assert.assertNull(mgr.getRoute());
+        Assert.assertNull(mgr.getState());
+
+        ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
+        HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn2);
+        Assert.assertFalse(conn2.isOpen());
+
+        Mockito.verify(connFactory, Mockito.times(2)).create();
+    }
+
+    @Test
+    public void testLeaseReleaseReusable() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
+
+        mgr.releaseConnection(conn1, null, 10000, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route, mgr.getRoute());
+        Assert.assertEquals(null, mgr.getState());
+
+        ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
+        HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn2);
+        Assert.assertTrue(conn2.isOpen());
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+    }
+
+    @Test
+    public void testLeaseReleaseReusableWithState() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, "some state");
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
+
+        mgr.releaseConnection(conn1, "some other state", 10000, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route, mgr.getRoute());
+        Assert.assertEquals("some other state", mgr.getState());
+
+        ConnectionRequest connRequest2 = mgr.requestConnection(route, "some other state");
+        HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn2);
+        Assert.assertTrue(conn2.isOpen());
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+    }
+
+    @Test
+    public void testLeaseDifferentRoute() throws Exception {
+        HttpHost target1 = new HttpHost("somehost");
+        HttpRoute route1 = new HttpRoute(target1);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route1, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
+
+        mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route1, mgr.getRoute());
+        Assert.assertEquals(null, mgr.getState());
+
+        HttpHost target2 = new HttpHost("otherhost");
+        HttpRoute route2 = new HttpRoute(target2);
+        ConnectionRequest connRequest2 = mgr.requestConnection(route2, null);
+        HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn2);
+        Assert.assertFalse(conn2.isOpen());
+
+        Mockito.verify(conn).close();
+        Mockito.verify(connFactory, Mockito.times(2)).create();
+    }
+
+    @Test
+    public void testLeaseExpired() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
+
+        mgr.releaseConnection(conn1, null, 10, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route, mgr.getRoute());
+        Assert.assertEquals(null, mgr.getState());
+
+        Thread.sleep(50);
+
+        ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
+        HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn2);
+        Assert.assertFalse(conn2.isOpen());
+
+        Mockito.verify(conn).close();
+        Mockito.verify(connFactory, Mockito.times(2)).create();
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testLeaseInvalidArg() throws Exception {
+        mgr.requestConnection(null, null);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testReleaseInvalidArg() throws Exception {
+        mgr.releaseConnection(null, null, 0, TimeUnit.MILLISECONDS);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testReleaseAnotherConnection() throws Exception {
+        HttpClientConnection wrongCon = Mockito.mock(HttpClientConnection.class);
+        mgr.releaseConnection(wrongCon, null, 0, TimeUnit.MILLISECONDS);
+    }
+
+    @Test
+    public void testShutdown() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
+
+        mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
+
+        mgr.shutdown();
+
+        Mockito.verify(conn, Mockito.times(1)).shutdown();
+
+        try {
+            ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
+            connRequest2.get(0, TimeUnit.MILLISECONDS);
+            Assert.fail("IllegalStateException expected");
+        } catch (IllegalStateException ex) {
+        }
+    }
+
+    @Test
+    public void testCloseExpired() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
+
+        mgr.releaseConnection(conn1, null, 10, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route, mgr.getRoute());
+        Assert.assertEquals(null, mgr.getState());
+
+        Thread.sleep(50);
+
+        mgr.closeExpiredConnections();
+
+        Mockito.verify(conn).close();
+    }
+
+    @Test
+    public void testCloseIdle() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+
+        Mockito.verify(connFactory, Mockito.times(1)).create();
+
+        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
+
+        mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
+
+        Assert.assertEquals(route, mgr.getRoute());
+        Assert.assertEquals(null, mgr.getState());
+
+        Thread.sleep(100);
+
+        mgr.closeIdleConnections(50, TimeUnit.MILLISECONDS);
+
+        Mockito.verify(conn).close();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void testAlreadyLeased() throws Exception {
+        HttpHost target = new HttpHost("somehost");
+        HttpRoute route = new HttpRoute(target);
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertNotNull(conn1);
+        mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
+
+        mgr.getConnection(route, null);
+        mgr.getConnection(route, null);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java Sun Nov  4 07:37:50 2012
@@ -37,6 +37,7 @@ import org.apache.http.conn.DnsResolver;
 import org.junit.Assert;
 import org.junit.Test;
 
+@Deprecated
 public class TestDefaultClientConnectOperator {
 
     @Test

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,194 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.net.Socket;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.ConnectionRequest;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.params.HttpParams;
+import org.apache.http.pool.ConnPool;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestHttpClientConnectionManagerBase {
+
+    private DefaultClientConnection conn;
+    private Socket socket;
+    private SchemeSocketFactory plainSocketFactory;
+    private SchemeRegistry schemeRegistry;
+    private DnsResolver dnsResolver;
+    private Future<CPoolEntry> future;
+    private ConnPool<HttpRoute, CPoolEntry> pool;
+    private HttpClientConnectionManagerBase mgr;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setup() throws Exception {
+        conn = Mockito.mock(DefaultClientConnection.class);
+        socket = Mockito.mock(Socket.class);
+        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+        dnsResolver = Mockito.mock(DnsResolver.class);
+
+        Scheme http = new Scheme("http", 80, plainSocketFactory);
+        schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(http);
+
+        pool = Mockito.mock(ConnPool.class);
+        future = Mockito.mock(Future.class);
+        mgr = new HttpClientConnectionManagerBase(pool, schemeRegistry, dnsResolver) {
+
+            public void closeIdleConnections(long idletime, TimeUnit tunit) {
+            }
+
+            public void closeExpiredConnections() {
+            }
+
+            public void shutdown() {
+            }
+
+        };
+    }
+
+    @Test
+    public void testLeaseRelease() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+
+        CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
+                -1, TimeUnit.MILLISECONDS);
+
+        Mockito.when(future.isCancelled()).thenReturn(false);
+        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
+        Mockito.when(pool.lease(route, null, null)).thenReturn(future);
+
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
+        Assert.assertNotNull(conn1);
+        Assert.assertFalse(conn1.isOpen());
+        Assert.assertNotSame(conn, conn1);
+
+        mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
+
+        Mockito.verify(pool).release(entry, false);
+    }
+
+    @Test(expected=InterruptedException.class)
+    public void testLeaseFutureCancelled() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+
+        CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
+                -1, TimeUnit.MILLISECONDS);
+
+        Mockito.when(future.isCancelled()).thenReturn(true);
+        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
+        Mockito.when(pool.lease(route, null, null)).thenReturn(future);
+
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        connRequest1.get(1, TimeUnit.SECONDS);
+    }
+
+    @Test(expected=ConnectionPoolTimeoutException.class)
+    public void testLeaseFutureTimeout() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(future.isCancelled()).thenReturn(true);
+        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenThrow(new TimeoutException());
+        Mockito.when(pool.lease(route, null, null)).thenReturn(future);
+
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        connRequest1.get(1, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testReleaseReusable() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+
+        CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
+                -1, TimeUnit.MILLISECONDS));
+
+        Mockito.when(future.isCancelled()).thenReturn(false);
+        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
+        Mockito.when(pool.lease(route, null, null)).thenReturn(future);
+        Mockito.when(conn.isOpen()).thenReturn(true);
+
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
+        Assert.assertNotNull(conn1);
+        Assert.assertTrue(conn1.isOpen());
+
+        mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);
+
+        Mockito.verify(pool).release(entry, true);
+        Mockito.verify(entry).setState("some state");
+        Mockito.verify(entry).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testReleaseNonReusable() throws Exception {
+        HttpHost target = new HttpHost("localhost");
+        HttpRoute route = new HttpRoute(target);
+
+        CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
+                -1, TimeUnit.MILLISECONDS));
+
+        Mockito.when(future.isCancelled()).thenReturn(false);
+        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
+        Mockito.when(pool.lease(route, null, null)).thenReturn(future);
+        Mockito.when(conn.isOpen()).thenReturn(false);
+
+        ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
+        HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
+        Assert.assertNotNull(conn1);
+        Assert.assertFalse(conn1.isOpen());
+
+        mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);
+
+        Mockito.verify(pool).release(entry, false);
+        Mockito.verify(entry, Mockito.never()).setState(Mockito.anyObject());
+        Mockito.verify(entry, Mockito.never()).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,179 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import org.apache.http.HttpHost;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.HttpInetSocketAddress;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestHttpClientConnectionOperator {
+
+    private DefaultClientConnection conn;
+    private Socket socket;
+    private SchemeSocketFactory plainSocketFactory;
+    private SchemeLayeredSocketFactory sslSocketFactory;
+    private SchemeRegistry schemeRegistry;
+    private DnsResolver dnsResolver;
+    private HttpClientConnectionOperator connectionOperator;
+
+    @Before
+    public void setup() throws Exception {
+        conn = Mockito.mock(DefaultClientConnection.class);
+        socket = Mockito.mock(Socket.class);
+        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
+        sslSocketFactory = Mockito.mock(SchemeLayeredSocketFactory.class);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+        Mockito.when(sslSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+        dnsResolver = Mockito.mock(DnsResolver.class);
+
+        Scheme http = new Scheme("http", 80, plainSocketFactory);
+        Scheme https = new Scheme("https", 443, sslSocketFactory);
+        schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(http);
+        schemeRegistry.register(https);
+
+        connectionOperator = new HttpClientConnectionOperator(schemeRegistry, dnsResolver);
+    }
+
+    @Test
+    public void testConnect() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpParams params = new BasicHttpParams();
+        HttpHost host = new HttpHost("somehost");
+        InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
+        InetAddress ip1 = InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
+        InetAddress ip2 = InetAddress.getByAddress(new byte[] {127, 0, 0, 2});
+
+        Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.<Socket>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<HttpParams>any())).thenReturn(socket);
+
+        connectionOperator.connect(conn, host, local, context, params);
+
+        Mockito.verify(plainSocketFactory).connectSocket(socket,
+                new InetSocketAddress(ip1, 80),
+                new InetSocketAddress(local, 0), params);
+        Mockito.verify(conn).opening(socket, host);
+        Mockito.verify(conn).openCompleted(false, params);
+    }
+
+    @Test(expected=ConnectTimeoutException.class)
+    public void testConnectFailure() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpParams params = new BasicHttpParams();
+        HttpHost host = new HttpHost("somehost");
+        InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
+        InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1});
+        InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2});
+
+        Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.<Socket>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<HttpParams>any())).thenThrow(new ConnectTimeoutException());
+
+        connectionOperator.connect(conn, host, local, context, params);
+    }
+
+    @Test
+    public void testConnectFailover() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpParams params = new BasicHttpParams();
+        HttpHost host = new HttpHost("somehost");
+        InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
+        InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1});
+        InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2});
+
+        Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.<Socket>any(),
+                Mockito.eq(new HttpInetSocketAddress(host, ip1, 80)),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<HttpParams>any())).thenThrow(new ConnectTimeoutException());
+        Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.<Socket>any(),
+                Mockito.eq(new HttpInetSocketAddress(host, ip2, 80)),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<HttpParams>any())).thenReturn(socket);
+
+        connectionOperator.connect(conn, host, local, context, params);
+
+        Mockito.verify(plainSocketFactory).connectSocket(socket,
+                new HttpInetSocketAddress(host, ip2, 80),
+                new InetSocketAddress(local, 0), params);
+        Mockito.verify(conn, Mockito.times(2)).opening(socket, host);
+        Mockito.verify(conn).openCompleted(false, params);
+    }
+
+    @Test
+    public void testUpgrade() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpParams params = new BasicHttpParams();
+        HttpHost host = new HttpHost("somehost", -1, "https");
+
+        Mockito.when(sslSocketFactory.createLayeredSocket(
+                Mockito.<Socket>any(),
+                Mockito.eq("somehost"),
+                Mockito.eq(443),
+                Mockito.<HttpParams>any())).thenReturn(socket);
+
+        connectionOperator.upgrade(conn, host, context, params);
+
+        Mockito.verify(conn).update(socket, host, false, params);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testUpgradeNonLayeringScheme() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpParams params = new BasicHttpParams();
+        HttpHost host = new HttpHost("somehost", -1, "http");
+
+        connectionOperator.upgrade(conn, host, context, params);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java (from r1398094, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManagerNoServer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java?p2=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java&p1=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManagerNoServer.java&r1=1398094&r2=1405507&rev=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManagerNoServer.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java Sun Nov  4 07:37:50 2012
@@ -29,76 +29,55 @@ package org.apache.http.impl.conn;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpVersion;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.ClientConnectionRequest;
+import org.apache.http.conn.ConnectionRequest;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
-import org.apache.http.conn.ManagedClientConnection;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.impl.conn.tsccm.GetConnThread;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 /**
- * Tests for <code>PoolingClientConnectionManager</code> that do not require a server to
- * communicate with.
+ * {@link PoolingHttpClientConnectionManager} tests.
  */
-public class TestPoolingConnManagerNoServer {
+public class TestPoolingHttpClientConnectionManager {
 
-    private static ManagedClientConnection getConnection(
-            final ClientConnectionManager mgr,
+    private static HttpClientConnection getConnection(
+            final HttpClientConnectionManager mgr,
             final HttpRoute route,
             long timeout,
             TimeUnit unit) throws ConnectionPoolTimeoutException, InterruptedException {
-        ClientConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.getConnection(timeout, unit);
+        ConnectionRequest connRequest = mgr.requestConnection(route, null);
+        return connRequest.get(timeout, unit);
     }
 
-    private static ManagedClientConnection getConnection(
-            final ClientConnectionManager mgr,
+    private static HttpClientConnection getConnection(
+            final HttpClientConnectionManager mgr,
             final HttpRoute route) throws ConnectionPoolTimeoutException, InterruptedException {
-        ClientConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.getConnection(0, null);
-    }
-
-    /**
-     * Instantiates default parameters.
-     *
-     * @return  the default parameters
-     */
-    public HttpParams createDefaultParams() {
-
-        HttpParams params = new BasicHttpParams();
-        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
-        HttpProtocolParams.setUseExpectContinue(params, false);
-
-        return params;
+        ConnectionRequest connRequest = mgr.requestConnection(route, null);
+        return connRequest.get(0, null);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testIllegalConstructor() {
-        new PoolingClientConnectionManager(null);
+        new PoolingHttpClientConnectionManager(null);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testGetConnection()
             throws InterruptedException, ConnectionPoolTimeoutException {
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
 
         HttpHost target = new HttpHost("www.test.invalid", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
-        ManagedClientConnection conn = getConnection(mgr, route);
+        HttpClientConnection conn = getConnection(mgr, route);
         Assert.assertNotNull(conn);
-        Assert.assertNull(conn.getRoute());
         Assert.assertFalse(conn.isOpen());
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
 
         try {
             getConnection(mgr, null);
@@ -113,7 +92,7 @@ public class TestPoolingConnManagerNoSer
     public void testMaxConnTotal()
             throws InterruptedException, ConnectionPoolTimeoutException {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(2);
         mgr.setDefaultMaxPerRoute(1);
 
@@ -122,9 +101,9 @@ public class TestPoolingConnManagerNoSer
         HttpHost target2 = new HttpHost("www.test2.invalid", 80, "http");
         HttpRoute route2 = new HttpRoute(target2, null, false);
 
-        ManagedClientConnection conn1 = getConnection(mgr, route1);
+        HttpClientConnection conn1 = getConnection(mgr, route1);
         Assert.assertNotNull(conn1);
-        ManagedClientConnection conn2 = getConnection(mgr, route2);
+        HttpClientConnection conn2 = getConnection(mgr, route2);
         Assert.assertNotNull(conn2);
 
         try {
@@ -136,7 +115,7 @@ public class TestPoolingConnManagerNoSer
         }
 
         // release one of the connections
-        mgr.releaseConnection(conn2, -1, null);
+        mgr.releaseConnection(conn2, null, -1, null);
         conn2 = null;
 
         // there should be a connection available now
@@ -159,20 +138,20 @@ public class TestPoolingConnManagerNoSer
         HttpHost target3 = new HttpHost("www.test3.invalid", 80, "http");
         HttpRoute route3 = new HttpRoute(target3, null, false);
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(100);
         mgr.setDefaultMaxPerRoute(1);
         mgr.setMaxPerRoute(route2, 2);
         mgr.setMaxPerRoute(route3, 3);
 
         // route 3, limit 3
-        ManagedClientConnection conn1 =
+        HttpClientConnection conn1 =
             getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
-        ManagedClientConnection conn2 =
+        HttpClientConnection conn2 =
             getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn2);
-        ManagedClientConnection conn3 =
+        HttpClientConnection conn3 =
             getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn3);
         try {
@@ -203,18 +182,16 @@ public class TestPoolingConnManagerNoSer
         } catch (ConnectionPoolTimeoutException e) {
             // expected
         }
-
-
         // check releaseConnection with invalid arguments
         try {
-            mgr.releaseConnection(null, -1, null);
+            mgr.releaseConnection(null, null, -1, null);
             Assert.fail("null connection adapter not detected");
         } catch (IllegalArgumentException iax) {
             // expected
         }
         try {
-            ManagedClientConnection conn = Mockito.mock(ManagedClientConnection.class);
-            mgr.releaseConnection(conn, -1, null);
+            HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
+            mgr.releaseConnection(conn, null, -1, null);
             Assert.fail("foreign connection adapter not detected");
         } catch (IllegalArgumentException iax) {
             // expected
@@ -226,7 +203,7 @@ public class TestPoolingConnManagerNoSer
     @Test
     public void testReleaseConnection() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(3);
         mgr.setDefaultMaxPerRoute(1);
 
@@ -238,11 +215,11 @@ public class TestPoolingConnManagerNoSer
         HttpRoute route3 = new HttpRoute(target3, null, false);
 
         // the first three allocations should pass
-        ManagedClientConnection conn1 =
+        HttpClientConnection conn1 =
             getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
-        ManagedClientConnection conn2 =
+        HttpClientConnection conn2 =
             getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
-        ManagedClientConnection conn3 =
+        HttpClientConnection conn3 =
             getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
         Assert.assertNotNull(conn2);
@@ -270,7 +247,7 @@ public class TestPoolingConnManagerNoSer
         }
 
         // now release one and check that exactly that one can be obtained then
-        mgr.releaseConnection(conn2, -1, null);
+        mgr.releaseConnection(conn2, null, -1, null);
         conn2 = null;
         try {
             getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
@@ -292,26 +269,17 @@ public class TestPoolingConnManagerNoSer
     }
 
     @Test
-    public void testDeleteClosedConnections()
-            throws InterruptedException, ConnectionPoolTimeoutException {
-
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+    public void testDeleteClosedConnections() throws Exception {
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
 
         HttpHost target = new HttpHost("www.test.invalid", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
-        ManagedClientConnection conn = getConnection(mgr, route);
+        HttpClientConnection conn = getConnection(mgr, route);
 
         Assert.assertEquals(1, mgr.getTotalStats().getLeased());
         Assert.assertEquals(1, mgr.getStats(route).getLeased());
-        conn.markReusable();
-        mgr.releaseConnection(conn, -1, null);
-
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, mgr.getStats(route).getAvailable());
-
-        // this implicitly deletes them
-        mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS);
+        mgr.releaseConnection(conn, null, -1, null);
 
         Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
         Assert.assertEquals(0, mgr.getStats(route).getAvailable());
@@ -323,7 +291,7 @@ public class TestPoolingConnManagerNoSer
     public void testShutdown() throws Exception {
         // 3.x: TestHttpConnectionManager.testShutdown
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
         mgr.setDefaultMaxPerRoute(1);
 
@@ -333,7 +301,7 @@ public class TestPoolingConnManagerNoSer
         // get the only connection, then start an extra thread
         // on shutdown, the extra thread should get an exception
 
-        ManagedClientConnection conn =
+        HttpClientConnection conn =
             getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
         GetConnThread gct = new GetConnThread(mgr, route, 0L); // no timeout
         gct.start();
@@ -345,7 +313,7 @@ public class TestPoolingConnManagerNoSer
         // First release the connection. If the manager keeps working
         // despite the shutdown, this will deblock the extra thread.
         // The release itself should turn into a no-op, without exception.
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
 
 
         gct.join(10000);
@@ -369,14 +337,14 @@ public class TestPoolingConnManagerNoSer
     public void testInterruptThread() throws Exception {
         // 3.x: TestHttpConnectionManager.testWaitingThreadInterrupted
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = new HttpHost("www.test.invalid", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
         // get the only connection, then start an extra thread
-        ManagedClientConnection conn =
+        HttpClientConnection conn =
             getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
         GetConnThread gct = new GetConnThread(mgr, route, 0L); // no timeout
         gct.start();
@@ -402,7 +370,7 @@ public class TestPoolingConnManagerNoSer
             // expected
         }
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         // this time: no exception
         conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull("should have gotten a connection", conn);
@@ -414,7 +382,7 @@ public class TestPoolingConnManagerNoSer
     public void testReusePreference() throws Exception {
         // 3.x: TestHttpConnectionManager.testHostReusePreference
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
@@ -423,7 +391,7 @@ public class TestPoolingConnManagerNoSer
         HttpRoute route2 = new HttpRoute(target2, null, false);
 
         // get the only connection, then start two extra threads
-        ManagedClientConnection conn =
+        HttpClientConnection conn =
             getConnection(mgr, route1, 1L, TimeUnit.MILLISECONDS);
         GetConnThread gct1 = new GetConnThread(mgr, route1, 1000L);
         GetConnThread gct2 = new GetConnThread(mgr, route2, 1000L);
@@ -438,7 +406,7 @@ public class TestPoolingConnManagerNoSer
 
         // releasing the connection for route1 should deblock thread1
         // the other thread gets a timeout
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
 
         gct1.join(10000);
         gct2.join(10000);
@@ -453,20 +421,20 @@ public class TestPoolingConnManagerNoSer
 
     @Test
     public void testAbortAfterRequestStarts() throws Exception {
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = new HttpHost("www.test.invalid", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
         // get the only connection, then start an extra thread
-        ManagedClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
-        ClientConnectionRequest request = mgr.requestConnection(route, null);
+        HttpClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
+        ConnectionRequest request = mgr.requestConnection(route, null);
         GetConnThread gct = new GetConnThread(request, route, 0L); // no timeout
         gct.start();
         Thread.sleep(100); // give extra thread time to block
 
-        request.abortRequest();
+        request.cancel();
 
         gct.join(10000);
         Assert.assertNotNull("thread should have gotten an exception",
@@ -483,7 +451,7 @@ public class TestPoolingConnManagerNoSer
             // expected
         }
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         // this time: no exception
         conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull("should have gotten a connection", conn);
@@ -493,16 +461,16 @@ public class TestPoolingConnManagerNoSer
 
     @Test
     public void testAbortBeforeRequestStarts() throws Exception {
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = new HttpHost("www.test.invalid", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
         // get the only connection, then start an extra thread
-        ManagedClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
-        ClientConnectionRequest request = mgr.requestConnection(route, null);
-        request.abortRequest();
+        HttpClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
+        ConnectionRequest request = mgr.requestConnection(route, null);
+        request.cancel();
 
         GetConnThread gct = new GetConnThread(request, route, 0L); // no timeout
         gct.start();
@@ -523,7 +491,7 @@ public class TestPoolingConnManagerNoSer
             // expected
         }
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         // this time: no exception
         conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
         Assert.assertNotNull("should have gotten a connection", conn);
@@ -531,4 +499,45 @@ public class TestPoolingConnManagerNoSer
         mgr.shutdown();
     }
 
+    public class GetConnThread extends Thread {
+
+        private final ConnectionRequest connRequest;
+        private final long timeout;
+
+        private volatile HttpClientConnection connection;
+        private volatile Exception exception;
+
+        public GetConnThread(
+                final HttpClientConnectionManager mgr,
+                final HttpRoute route, long timeout) {
+            this(mgr.requestConnection(route, null), route, timeout);
+        }
+
+        public GetConnThread(
+                final ConnectionRequest connRequest,
+                final HttpRoute route, long timeout) {
+            super();
+            this.connRequest = connRequest;
+            this.timeout = timeout;
+        }
+
+        @Override
+        public void run() {
+            try {
+                connection = connRequest.get(timeout, TimeUnit.MILLISECONDS);
+            } catch (Exception ex) {
+                exception = ex;
+            }
+        }
+
+        public Throwable getException() {
+            return exception;
+        }
+
+        public HttpClientConnection getConnection() {
+            return connection;
+        }
+
+    }
+
 }

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message