c629dbd830ef1ecebd6d18299cc6d630061ad8d4 Changes for HTTPCLIENT-1914 diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java index 9117c62..55022ee 100644 --- a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java +++ b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java @@ -688,10 +688,12 @@ @Override public void setMaxPerRoute(final T route, final int max) { Args.notNull(route, "Route"); - Args.positive(max, "Max value"); this.lock.lock(); try { - this.maxPerRoute.put(route, Integer.valueOf(max)); + if (max > -1) + this.maxPerRoute.put(route, Integer.valueOf(max)); + else + this.maxPerRoute.remove(route); } finally { this.lock.unlock(); } diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java index 65d1f44..9314df6 100644 --- a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java +++ b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java @@ -996,11 +996,6 @@ } catch (final IllegalArgumentException expected) { } try { - pool.setMaxPerRoute("somehost", -1); - Assert.fail("IllegalArgumentException should have been thrown"); - } catch (final IllegalArgumentException expected) { - } - try { pool.setDefaultMaxPerRoute(-1); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException expected) { @@ -1008,6 +1003,18 @@ } @Test + public void testSetMaxPerRoute() throws Exception { + final ConnectingIOReactor ioreactor = Mockito.mock(ConnectingIOReactor.class); + final LocalSessionPool pool = new LocalSessionPool(ioreactor, 2, 2); + pool.setMaxPerRoute("somehost", 1); + Assert.assertEquals(1, pool.getMaxPerRoute("somehost")); + pool.setMaxPerRoute("somehost", 0); + Assert.assertEquals(0, pool.getMaxPerRoute("somehost")); + pool.setMaxPerRoute("somehost", -1); + Assert.assertEquals(2, pool.getMaxPerRoute("somehost")); + } + + @Test public void testShutdown() throws Exception { final ConnectingIOReactor ioreactor = Mockito.mock(ConnectingIOReactor.class); final LocalSessionPool pool = new LocalSessionPool(ioreactor, 2, 2); diff --git a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java index 6e09832..7113c09 100644 --- a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java +++ b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java @@ -484,10 +484,12 @@ @Override public void setMaxPerRoute(final T route, final int max) { Args.notNull(route, "Route"); - Args.positive(max, "Max per route value"); this.lock.lock(); try { - this.maxPerRoute.put(route, Integer.valueOf(max)); + if (max > -1) + this.maxPerRoute.put(route, Integer.valueOf(max)); + else + this.maxPerRoute.remove(route); } finally { this.lock.unlock(); } diff --git a/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java b/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java index 75ebb26..b40806b 100644 --- a/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java +++ b/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java @@ -743,11 +743,6 @@ } catch (final IllegalArgumentException expected) { } try { - pool.setMaxPerRoute("somehost", -1); - Assert.fail("IllegalArgumentException should have been thrown"); - } catch (final IllegalArgumentException expected) { - } - try { pool.setDefaultMaxPerRoute(-1); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException expected) { @@ -755,6 +750,18 @@ } @Test + public void testSetMaxPerRoute() throws Exception { + final LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class); + final LocalConnPool pool = new LocalConnPool(connFactory, 2, 2); + pool.setMaxPerRoute("somehost", 1); + Assert.assertEquals(1, pool.getMaxPerRoute("somehost")); + pool.setMaxPerRoute("somehost", 0); + Assert.assertEquals(0, pool.getMaxPerRoute("somehost")); + pool.setMaxPerRoute("somehost", -1); + Assert.assertEquals(2, pool.getMaxPerRoute("somehost")); + } + + @Test public void testShutdown() throws Exception { final LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);