You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/09/07 22:44:27 UTC
svn commit: r1166394 - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/
httpcore-nio/src/main/java/org/apache/http/nio/pool/
httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/
httpcore-nio/src/test/jav...
Author: olegk
Date: Wed Sep 7 20:44:26 2011
New Revision: 1166394
URL: http://svn.apache.org/viewvc?rev=1166394&view=rev
Log:
Added abstract methods #close and #isClosed to PoolEntry; pool implementations to check whether or not the underlying is closed prior when processing lease requests
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java Wed Sep 7 20:44:26 2011
@@ -26,7 +26,6 @@
*/
package org.apache.http.impl.nio.pool;
-import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Future;
@@ -98,15 +97,6 @@ public class BasicNIOConnPool extends Ab
}
@Override
- protected void closeEntry(final BasicNIOPoolEntry entry) {
- NHttpClientConnection conn = entry.getConnection();
- try {
- conn.shutdown();
- } catch (IOException ex) {
- }
- }
-
- @Override
public Future<BasicNIOPoolEntry> lease(
final HttpHost route,
final Object state,
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java Wed Sep 7 20:44:26 2011
@@ -26,6 +26,8 @@
*/
package org.apache.http.impl.nio.pool;
+import java.io.IOException;
+
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.nio.NHttpClientConnection;
@@ -43,4 +45,17 @@ public class BasicNIOPoolEntry extends P
super(id, route, conn);
}
+ @Override
+ public void close() {
+ try {
+ getConnection().close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return !getConnection().isOpen();
+ }
+
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java Wed Sep 7 20:44:26 2011
@@ -119,8 +119,6 @@ public abstract class AbstractNIOConnPoo
protected abstract E createEntry(T route, C conn);
- protected abstract void closeEntry(E entry);
-
public boolean isShutdown() {
return this.isShutDown;
}
@@ -136,10 +134,10 @@ public abstract class AbstractNIOConnPoo
sessionRequest.cancel();
}
for (E entry: this.available) {
- closeEntry(entry);
+ entry.close();
}
for (E entry: this.leased) {
- closeEntry(entry);
+ entry.close();
}
for (RouteSpecificPool<T, C, E> pool: this.routeToPool.values()) {
pool.shutdown();
@@ -165,11 +163,6 @@ public abstract class AbstractNIOConnPoo
return AbstractNIOConnPool.this.createEntry(route, conn);
}
- @Override
- protected void closeEntry(final E entry) {
- AbstractNIOConnPool.this.closeEntry(entry);
- }
-
};
this.routeToPool.put(route, pool);
}
@@ -226,7 +219,7 @@ public abstract class AbstractNIOConnPoo
if (reusable) {
this.available.add(entry);
} else {
- closeEntry(entry);
+ entry.close();
}
processPendingRequests();
}
@@ -259,8 +252,8 @@ public abstract class AbstractNIOConnPoo
if (entry == null) {
break;
}
- if (entry.isExpired(System.currentTimeMillis())) {
- closeEntry(entry);
+ if (entry.isClosed() || entry.isExpired(System.currentTimeMillis())) {
+ entry.close();
this.available.remove(entry);
pool.free(entry, false);
} else {
@@ -285,7 +278,7 @@ public abstract class AbstractNIOConnPoo
if (lastUsed == null) {
break;
}
- closeEntry(lastUsed);
+ lastUsed.close();
this.available.remove(lastUsed);
pool.remove(lastUsed);
}
@@ -301,7 +294,7 @@ public abstract class AbstractNIOConnPoo
if (totalAvailable > freeCapacity - 1) {
if (!this.available.isEmpty()) {
E lastUsed = this.available.removeFirst();
- closeEntry(lastUsed);
+ lastUsed.close();
RouteSpecificPool<T, C, E> otherpool = getPool(lastUsed.getRoute());
otherpool.remove(lastUsed);
}
@@ -537,7 +530,7 @@ public abstract class AbstractNIOConnPoo
while (it.hasNext()) {
E entry = it.next();
if (entry.getUpdated() <= deadline) {
- closeEntry(entry);
+ entry.close();
RouteSpecificPool<T, C, E> pool = getPool(entry.getRoute());
pool.remove(entry);
it.remove();
@@ -557,7 +550,7 @@ public abstract class AbstractNIOConnPoo
while (it.hasNext()) {
E entry = it.next();
if (entry.isExpired(now)) {
- closeEntry(entry);
+ entry.close();
RouteSpecificPool<T, C, E> pool = getPool(entry.getRoute());
pool.remove(entry);
it.remove();
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java Wed Sep 7 20:44:26 2011
@@ -57,8 +57,6 @@ abstract class RouteSpecificPool<T, C, E
protected abstract E createEntry(T route, C conn);
- protected abstract void closeEntry(E entry);
-
public int getLeasedCount() {
return this.leased.size();
}
@@ -178,11 +176,11 @@ abstract class RouteSpecificPool<T, C, E
}
this.pending.clear();
for (E entry: this.available) {
- closeEntry(entry);
+ entry.close();
}
this.available.clear();
for (E entry: this.leased) {
- closeEntry(entry);
+ entry.close();
}
this.leased.clear();
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java Wed Sep 7 20:44:26 2011
@@ -80,7 +80,6 @@ public class TestBasicNIOConnPool {
public void testCreateEntry() throws Exception {
NHttpClientConnection conn = connFactory.create(route, session);
BasicNIOPoolEntry entry = pool.createEntry(route, conn);
-
- pool.closeEntry(entry);
+ entry.close();
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java Wed Sep 7 20:44:26 2011
@@ -54,6 +54,16 @@ public class TestNIOConnPool {
super(null, route, conn);
}
+ @Override
+ public void close() {
+ getConnection().close();
+ }
+
+ @Override
+ public boolean isClosed() {
+ return getConnection().isClosed();
+ }
+
}
static class LocalConnFactory implements NIOConnFactory<String, IOSession> {
@@ -86,12 +96,6 @@ public class TestNIOConnPool {
return new LocalPoolEntry(route, session);
}
- @Override
- protected void closeEntry(final LocalPoolEntry entry) {
- IOSession session = entry.getConnection();
- session.close();
- }
-
}
@Test
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java Wed Sep 7 20:44:26 2011
@@ -47,6 +47,16 @@ public class TestRouteSpecificPool {
super(null, route, conn);
}
+ @Override
+ public void close() {
+ getConnection().close();
+ }
+
+ @Override
+ public boolean isClosed() {
+ return getConnection().isClosed();
+ }
+
}
static class LocalRoutePool extends RouteSpecificPool<String, IOSession, LocalPoolEntry> {
@@ -60,12 +70,6 @@ public class TestRouteSpecificPool {
return new LocalPoolEntry(route, session);
}
- @Override
- protected void closeEntry(final LocalPoolEntry entry) {
- IOSession session = entry.getConnection();
- session.close();
- }
-
};
@Test
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java Wed Sep 7 20:44:26 2011
@@ -26,11 +26,9 @@
*/
package org.apache.http.impl.pool;
-import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.http.HttpClientConnection;
-import org.apache.http.HttpConnection;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.params.HttpParams;
@@ -60,13 +58,4 @@ public class BasicConnPool extends Abstr
return new BasicPoolEntry(Long.toString(COUNTER.getAndIncrement()), host, conn);
}
- @Override
- protected void closeEntry(final BasicPoolEntry entry) {
- HttpConnection conn = entry.getConnection();
- try {
- conn.close();
- } catch (IOException ignore) {
- }
- }
-
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java Wed Sep 7 20:44:26 2011
@@ -26,6 +26,8 @@
*/
package org.apache.http.impl.pool;
+import java.io.IOException;
+
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
@@ -41,4 +43,17 @@ public class BasicPoolEntry extends Pool
super(id, route, conn);
}
+ @Override
+ public void close() {
+ try {
+ this.getConnection().close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return !this.getConnection().isOpen();
+ }
+
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java Wed Sep 7 20:44:26 2011
@@ -95,8 +95,6 @@ public abstract class AbstractConnPool<T
protected abstract E createEntry(T route, C conn);
- protected abstract void closeEntry(E entry);
-
public boolean isShutdown() {
return this.isShutDown;
}
@@ -109,10 +107,10 @@ public abstract class AbstractConnPool<T
this.lock.lock();
try {
for (E entry: this.available) {
- closeEntry(entry);
+ entry.close();
}
for (E entry: this.leased) {
- closeEntry(entry);
+ entry.close();
}
for (RouteSpecificPool<T, C, E> pool: this.routeToPool.values()) {
pool.shutdown();
@@ -135,11 +133,6 @@ public abstract class AbstractConnPool<T
return AbstractConnPool.this.createEntry(route, conn);
}
- @Override
- protected void closeEntry(final E entry) {
- AbstractConnPool.this.closeEntry(entry);
- }
-
};
this.routeToPool.put(route, pool);
}
@@ -195,8 +188,8 @@ public abstract class AbstractConnPool<T
if (entry == null) {
break;
}
- if (entry.isExpired(System.currentTimeMillis())) {
- closeEntry(entry);
+ if (entry.isClosed() || entry.isExpired(System.currentTimeMillis())) {
+ entry.close();
this.available.remove(entry);
pool.free(entry, false);
} else {
@@ -219,7 +212,7 @@ public abstract class AbstractConnPool<T
if (lastUsed == null) {
break;
}
- closeEntry(lastUsed);
+ lastUsed.close();
this.available.remove(lastUsed);
pool.remove(lastUsed);
}
@@ -233,7 +226,7 @@ public abstract class AbstractConnPool<T
if (totalAvailable > freeCapacity - 1) {
if (!this.available.isEmpty()) {
E lastUsed = this.available.removeFirst();
- closeEntry(lastUsed);
+ lastUsed.close();
RouteSpecificPool<T, C, E> otherpool = getPool(lastUsed.getRoute());
otherpool.remove(lastUsed);
}
@@ -291,7 +284,7 @@ public abstract class AbstractConnPool<T
if (reusable && !this.isShutDown) {
this.available.add(entry);
} else {
- closeEntry(entry);
+ entry.close();
}
notifyPending(pool);
}
@@ -423,7 +416,7 @@ public abstract class AbstractConnPool<T
while (it.hasNext()) {
E entry = it.next();
if (entry.getUpdated() <= deadline) {
- closeEntry(entry);
+ entry.close();
RouteSpecificPool<T, C, E> pool = getPool(entry.getRoute());
pool.remove(entry);
it.remove();
@@ -443,7 +436,7 @@ public abstract class AbstractConnPool<T
while (it.hasNext()) {
E entry = it.next();
if (entry.isExpired(now)) {
- closeEntry(entry);
+ entry.close();
RouteSpecificPool<T, C, E> pool = getPool(entry.getRoute());
pool.remove(entry);
it.remove();
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java Wed Sep 7 20:44:26 2011
@@ -39,7 +39,7 @@ import org.apache.http.annotation.Thread
* @since 4.2
*/
@ThreadSafe
-public class PoolEntry<T, C> {
+public abstract class PoolEntry<T, C> {
private final String id;
private final T route;
@@ -133,6 +133,10 @@ public class PoolEntry<T, C> {
return now >= this.expiry;
}
+ public abstract void close();
+
+ public abstract boolean isClosed();
+
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java Wed Sep 7 20:44:26 2011
@@ -51,8 +51,6 @@ abstract class RouteSpecificPool<T, C, E
protected abstract E createEntry(C conn);
- protected abstract void closeEntry(E entry);
-
public final T getRoute() {
return route;
}
@@ -163,11 +161,11 @@ abstract class RouteSpecificPool<T, C, E
}
this.pending.clear();
for (E entry: this.available) {
- closeEntry(entry);
+ entry.close();
}
this.available.clear();
for (E entry: this.leased) {
- closeEntry(entry);
+ entry.close();
}
this.leased.clear();
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java Wed Sep 7 20:44:26 2011
@@ -122,7 +122,7 @@ public class TestBasicConnPool {
assertEquals(conn, entry.getConnection());
assertEquals("localhost", entry.getRoute().getHostName());
- pool.closeEntry(entry);
+ entry.close();
}
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java Wed Sep 7 20:44:26 2011
@@ -51,6 +51,19 @@ public class TestConnPool {
super(null, route, conn);
}
+ @Override
+ public void close() {
+ try {
+ getConnection().close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return !getConnection().isOpen();
+ }
+
}
static class LocalConnPool extends AbstractConnPool<String, HttpConnection, LocalPoolEntry> {
@@ -66,15 +79,6 @@ public class TestConnPool {
return new LocalPoolEntry(route, conn);
}
- @Override
- protected void closeEntry(final LocalPoolEntry entry) {
- HttpConnection conn = entry.getConnection();
- try {
- conn.close();
- } catch (IOException ignore) {
- }
- }
-
}
@Test
@@ -112,7 +116,9 @@ public class TestConnPool {
@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);
@@ -214,9 +220,11 @@ public class TestConnPool {
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);
@@ -313,12 +321,17 @@ public class TestConnPool {
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);
@@ -417,8 +430,11 @@ public class TestConnPool {
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);
@@ -480,6 +496,7 @@ public class TestConnPool {
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);
@@ -555,6 +572,7 @@ public class TestConnPool {
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);
@@ -601,6 +619,7 @@ public class TestConnPool {
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);
@@ -636,7 +655,9 @@ public class TestConnPool {
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);
@@ -726,8 +747,10 @@ public class TestConnPool {
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);
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java Wed Sep 7 20:44:26 2011
@@ -26,6 +26,7 @@
*/
package org.apache.http.pool;
+import java.io.IOException;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
@@ -48,6 +49,19 @@ public class TestPoolEntry {
super(null, route, conn, timeToLive, tunit);
}
+ @Override
+ public void close() {
+ try {
+ getConnection().close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return !getConnection().isOpen();
+ }
+
}
@Test
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java?rev=1166394&r1=1166393&r2=1166394&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java Wed Sep 7 20:44:26 2011
@@ -44,6 +44,19 @@ public class TestRouteSpecificPool {
super(null, route, conn);
}
+ @Override
+ public void close() {
+ try {
+ getConnection().close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return !getConnection().isOpen();
+ }
+
}
static class LocalRoutePool extends RouteSpecificPool<String, HttpConnection, LocalPoolEntry> {
@@ -57,15 +70,6 @@ public class TestRouteSpecificPool {
return new LocalPoolEntry(getRoute(), conn);
}
- @Override
- protected void closeEntry(LocalPoolEntry entry) {
- HttpConnection conn = entry.getConnection();
- try {
- conn.close();
- } catch (IOException ignore) {
- }
- }
-
};
@Test