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 2008/04/17 19:50:16 UTC
svn commit: r649204 - in /httpcomponents/httpclient/trunk: ./
module-client/src/main/java/org/apache/http/conn/
module-client/src/main/java/org/apache/http/impl/conn/
module-client/src/main/java/org/apache/http/impl/conn/tsccm/
module-client/src/test/j...
Author: olegk
Date: Thu Apr 17 10:50:13 2008
New Revision: 649204
URL: http://svn.apache.org/viewvc?rev=649204&view=rev
Log:
HTTPCLIENT-652: Added optional state attribute to managed client connections; this enables connection managers to correctly handle stateful connections
Added:
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java (with props)
Modified:
httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestAllTSCCM.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java
Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Apr 17 10:50:13 2008
@@ -1,6 +1,10 @@
Changes since 4.0 Alpha 3
-------------------
+* [HTTPCLIENT-652] Added optional state attribute to managed client connections.
+ This enables connection managers to correctly handle stateful connections.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCLIENT-673] Revised max connections per route configuration
Contributed by Oleg Kalnichevski <olegk at apache.org>
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java Thu Apr 17 10:50:13 2008
@@ -229,11 +229,21 @@
boolean isMarkedReusable()
;
+ /**
+ * Assigns a state object to this connection. Connection managers may make
+ * use of the connection state when allocating persistent connections.
+ *
+ * @param state The state object
+ */
void setState(Object state)
;
- boolean isStateful()
+ /**
+ * Returns the state object associated with this connection.
+ *
+ * @return The state object
+ */
+ Object getState()
;
-
} // interface ManagedClientConnection
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java Thu Apr 17 10:50:13 2008
@@ -68,6 +68,9 @@
*/
public abstract class AbstractPoolEntry {
+ /** The connection operator. */
+ protected final ClientConnectionOperator connOperator;
+
/** The underlying connection being pooled or used. */
protected volatile OperatedClientConnection connection;
@@ -91,23 +94,36 @@
* @param route the planned route for the connection,
* or <code>null</code>
*/
- protected AbstractPoolEntry(OperatedClientConnection occ,
+ protected AbstractPoolEntry(ClientConnectionOperator connOperator,
HttpRoute route) {
- this.connection = occ;
+ super();
+ if (connOperator == null) {
+ throw new IllegalArgumentException("Connection operator may not be null");
+ }
+ this.connOperator = connOperator;
+ this.connection = connOperator.createConnection();
this.route = route;
this.tracker = null;
}
-
/**
- * Obtains the connection {@link ClientConnectionOperator operator}.
- *
- * @return the operator for opening connections and layering protocols
+ * Returns the state object associated with this pool entry.
+ *
+ * @return The state object
*/
- protected abstract ClientConnectionOperator getOperator()
- ;
-
-
+ public Object getState() {
+ return state;
+ }
+
+ /**
+ * Assigns a state object to this pool entry.
+ *
+ * @param state The state object
+ */
+ public void setState(final Object state) {
+ this.state = state;
+ }
+
/**
* Opens the underlying connection.
*
@@ -142,14 +158,10 @@
//@@@ verify route against planned route?
- //if (LOG.isDebugEnabled()) {
- // LOG.debug("Open connection for " + route);
- //}
-
this.tracker = new RouteTracker(route);
final HttpHost proxy = route.getProxyHost();
- getOperator().openConnection
+ connOperator.openConnection
(this.connection,
(proxy != null) ? proxy : route.getTargetHost(),
route.getLocalAddress(),
@@ -278,11 +290,7 @@
final HttpHost target = tracker.getTargetHost();
- //if (LOG.isDebugEnabled()) {
- // LOG.debug("Layer protocol on connection to " + target);
- //}
-
- getOperator().updateSecureConnection(this.connection, target,
+ connOperator.updateSecureConnection(this.connection, target,
context, params);
this.tracker.layerProtocol(this.connection.isSecure());
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java Thu Apr 17 10:50:13 2008
@@ -170,15 +170,18 @@
}
}
+
// non-javadoc, see interface ManagedClientConnection
- public boolean isStateful() {
+ public Object getState() {
assertAttached();
- return poolEntry.state != null;
+ return poolEntry.getState();
}
+
// non-javadoc, see interface ManagedClientConnection
public void setState(final Object state) {
- poolEntry.state = state;
+ assertAttached();
+ poolEntry.setState(state);
}
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java Thu Apr 17 10:50:13 2008
@@ -40,7 +40,6 @@
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ManagedClientConnection;
-import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.params.HttpParams;
@@ -118,7 +117,7 @@
}
this.schemeRegistry = schreg;
this.connOperator = createConnectionOperator(schreg);
- this.uniquePoolEntry = new PoolEntry(connOperator.createConnection());
+ this.uniquePoolEntry = new PoolEntry();
this.managedConn = null;
this.lastReleaseTime = -1L;
this.alwaysShutDown = false; //@@@ from params? as argument?
@@ -227,8 +226,7 @@
} catch (IOException iox) {
LOG.debug("Problem shutting down connection.", iox);
// create a new connection, just to be sure
- uniquePoolEntry =
- new PoolEntry(connOperator.createConnection());
+ uniquePoolEntry = new PoolEntry();
}
}
}
@@ -364,17 +362,9 @@
*
* @param occ the underlying connection for this entry
*/
- protected PoolEntry(OperatedClientConnection occ) {
- super(occ, null);
+ protected PoolEntry() {
+ super(SingleClientConnManager.this.connOperator, null);
}
-
-
- // non-javadoc, see base AbstractPoolEntry
- @Override
- protected ClientConnectionOperator getOperator() {
- return SingleClientConnManager.this.connOperator;
- }
-
/**
* Closes the connection in this pool entry.
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java Thu Apr 17 10:50:13 2008
@@ -168,14 +168,14 @@
long timeout,
TimeUnit tunit)
throws ConnectionPoolTimeoutException, InterruptedException {
- return newPoolEntryRequest().getPoolEntry(route, state, timeout, tunit);
+ return requestPoolEntry(route, state).getPoolEntry(timeout, tunit);
}
/**
* Returns a new {@link PoolEntryRequest}, from which a {@link BasicPoolEntry}
* can be obtained, or the request can be aborted.
*/
- public abstract PoolEntryRequest newPoolEntryRequest();
+ public abstract PoolEntryRequest requestPoolEntry(HttpRoute route, Object state);
/**
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java Thu Apr 17 10:50:13 2008
@@ -45,11 +45,6 @@
*/
public class BasicPoolEntry extends AbstractPoolEntry {
- /** The connection operator. */
- //@@@ move to base class, drop getOperator()?
- private ClientConnectionOperator connOperator;
-
-
/**
* A weak reference to <code>this</code> used to detect GC of entries.
* Pool entries can only be GCed when they are allocated by an application
@@ -57,7 +52,6 @@
*/
private BasicPoolEntryRef reference;
-
/**
* Creates a new pool entry.
*
@@ -69,24 +63,12 @@
public BasicPoolEntry(ClientConnectionOperator op,
HttpRoute route,
ReferenceQueue<Object> queue) {
- //@@@ create connection in base? or delay creation until needed?
- super(op.createConnection(), route);
+ super(op, route);
if (route == null) {
- throw new IllegalArgumentException
- ("Planned route must not be null.");
+ throw new IllegalArgumentException("HTTP route may not be null");
}
-
- this.connOperator = op;
this.reference = new BasicPoolEntryRef(this, queue);
}
-
-
- // non-javadoc, see base AbstractPoolEntry
- @Override
- protected ClientConnectionOperator getOperator() {
- return this.connOperator;
- }
-
protected final OperatedClientConnection getConnection() {
return super.connection;
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java Thu Apr 17 10:50:13 2008
@@ -217,7 +217,9 @@
}
@Override
- public PoolEntryRequest newPoolEntryRequest() {
+ public PoolEntryRequest requestPoolEntry(
+ final HttpRoute route,
+ final Object state) {
final Aborter aborter = new Aborter();
@@ -233,8 +235,6 @@
}
public BasicPoolEntry getPoolEntry(
- HttpRoute route,
- Object state,
long timeout,
TimeUnit tunit)
throws InterruptedException, ConnectionPoolTimeoutException {
@@ -298,15 +298,21 @@
entry = getFreeEntry(rospl, state);
if (entry != null) {
- // we're fine
- //@@@ yeah this is ugly, but historical... will be revised
- } else if ((rospl.getEntryCount() < rospl.getMaxEntries()) &&
- (numConnections < maxTotalConnections)) {
+ break;
+ }
+
+ boolean hasCapacity = rospl.getCapacity() > 0;
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Available capacity: " + rospl.getCapacity()
+ + " [" + route + "][" + state + "]");
+ }
+
+ if (hasCapacity && numConnections < maxTotalConnections) {
entry = createEntry(rospl, operator);
- } else if ((rospl.getEntryCount() < rospl.getMaxEntries()) &&
- (freeConnections.size() > 0)) {
+ } else if (hasCapacity && !freeConnections.isEmpty()) {
deleteLeastUsedEntry();
entry = createEntry(rospl, operator);
@@ -314,7 +320,8 @@
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("Need to wait for connection. " + route);
+ LOG.debug("Need to wait for connection" +
+ " [" + route + "][" + state + "]");
}
if (waitingThread == null) {
@@ -368,7 +375,8 @@
HttpRoute route = entry.getPlannedRoute();
if (LOG.isDebugEnabled()) {
- LOG.debug("Freeing connection. " + route);
+ LOG.debug("Freeing connection" +
+ " [" + route + "][" + entry.getState() + "]");
}
poolLock.lock();
@@ -390,7 +398,7 @@
if (numConnections == 0) {
// for some reason this pool didn't already exist
- LOG.error("Master connection pool not found. " + route);
+ LOG.error("Master connection pool not found: " + route);
numConnections = 1;
}
@@ -424,7 +432,9 @@
if (entry != null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Getting free connection. " + rospl.getRoute());
+ LOG.debug("Getting free connection"
+ + " [" + rospl.getRoute() + "][" + state + "]");
+
}
freeConnections.remove(entry);
idleConnHandler.remove(entry.getConnection());// no longer idle
@@ -433,7 +443,8 @@
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("No free connections. " + rospl.getRoute());
+ LOG.debug("No free connections"
+ + " [" + rospl.getRoute() + "][" + state + "]");
}
}
@@ -459,7 +470,7 @@
ClientConnectionOperator op) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Creating new connection. " + rospl.getRoute());
+ LOG.debug("Creating new connection [" + rospl.getRoute() + "]");
}
// the entry will create the connection when needed
@@ -498,7 +509,8 @@
HttpRoute route = entry.getPlannedRoute();
if (LOG.isDebugEnabled()) {
- LOG.debug("Deleting connection. " + route);
+ LOG.debug("Deleting connection"
+ + " [" + route + "][" + entry.getState() + "]");
}
poolLock.lock();
@@ -590,15 +602,15 @@
if ((rospl != null) && rospl.hasThread()) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Notifying thread waiting on pool. "
- + rospl.getRoute());
+ LOG.debug("Notifying thread waiting on pool" +
+ " [" + rospl.getRoute() + "]");
}
waitingThread = rospl.dequeueThread();
waitingThreads.remove(waitingThread);
} else if (!waitingThreads.isEmpty()) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Notifying thread waiting on any pool.");
+ LOG.debug("Notifying thread waiting on any pool");
}
waitingThread = waitingThreads.remove();
waitingThread.getPool().removeThread(waitingThread);
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java Thu Apr 17 10:50:13 2008
@@ -46,7 +46,6 @@
* If {@link #abortRequest()} is called before this completes,
* an {@link InterruptedException} is thrown.
*
- * @param route the route for which to get the connection
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout
@@ -59,8 +58,6 @@
* if the calling thread was interrupted
*/
BasicPoolEntry getPoolEntry(
- HttpRoute route,
- Object state,
long timeout,
TimeUnit unit) throws InterruptedException, ConnectionPoolTimeoutException;
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java Thu Apr 17 10:50:13 2008
@@ -30,10 +30,16 @@
package org.apache.http.impl.conn.tsccm;
+import java.io.IOException;
+import java.util.ListIterator;
import java.util.Queue;
import java.util.LinkedList;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.util.LangUtils;
/**
@@ -43,6 +49,8 @@
*/
public class RouteSpecificPool {
+ private final Log LOG = LogFactory.getLog(RouteSpecificPool.class);
+
/** The route this pool is for. */
protected final HttpRoute route;
@@ -112,6 +120,16 @@
/**
+ * Return remaining capacity of this pool
+ *
+ * @return capacity
+ */
+ public int getCapacity() {
+ return maxEntries - numEntries;
+ }
+
+
+ /**
* Obtains the number of entries.
* This includes not only the free entries, but also those that
* have been created and are currently issued to an application.
@@ -129,14 +147,28 @@
* @return an available pool entry, or <code>null</code> if there is none
*/
public BasicPoolEntry allocEntry(final Object state) {
-
- BasicPoolEntry entry = null;
-
if (!freeEntries.isEmpty()) {
- entry = freeEntries.removeLast();
+ ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size());
+ while (it.hasPrevious()) {
+ BasicPoolEntry entry = it.previous();
+ if (LangUtils.equals(state, entry.getState())) {
+ it.remove();
+ return entry;
+ }
+ }
}
-
- return entry;
+ if (!freeEntries.isEmpty()) {
+ BasicPoolEntry entry = freeEntries.remove();
+ entry.setState(null);
+ OperatedClientConnection conn = entry.getConnection();
+ try {
+ conn.close();
+ } catch (IOException ex) {
+ LOG.debug("I/O error closing connection", ex);
+ }
+ return entry;
+ }
+ return null;
}
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java Thu Apr 17 10:50:13 2008
@@ -150,9 +150,12 @@
}
- public ClientConnectionRequest requestConnection(final HttpRoute route, final Object state) {
+ public ClientConnectionRequest requestConnection(
+ final HttpRoute route,
+ final Object state) {
- final PoolEntryRequest poolRequest = connectionPool.newPoolEntryRequest();
+ final PoolEntryRequest poolRequest = connectionPool.requestPoolEntry(
+ route, state);
return new ClientConnectionRequest() {
@@ -172,9 +175,7 @@
+ route + ", timeout = " + timeout);
}
- final BasicPoolEntry entry = poolRequest.getPoolEntry(
- route, state, timeout, tunit);
-
+ BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
}
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java Thu Apr 17 10:50:13 2008
@@ -75,7 +75,7 @@
throw new UnsupportedOperationException("just a mockup");
}
- public boolean isStateful() {
+ public Object getState() {
throw new UnsupportedOperationException("just a mockup");
}
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestAllTSCCM.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestAllTSCCM.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestAllTSCCM.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestAllTSCCM.java Thu Apr 17 10:50:13 2008
@@ -46,7 +46,7 @@
suite.addTest(TestDumbHelpers.suite());
suite.addTest(TestWaitingThread.suite());
suite.addTest(TestSpuriousWakeup.suite());
-
+ suite.addTest(TestConnPoolByRoute.suite());
return suite;
}
Added: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java?rev=649204&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java (added)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java Thu Apr 17 10:50:13 2008
@@ -0,0 +1,180 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ * ====================================================================
+ * 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.tsccm;
+
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpHost;
+import org.apache.http.conn.ClientConnectionOperator;
+import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.params.ConnPerRouteBean;
+import org.apache.http.conn.params.HttpConnectionManagerParams;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.conn.DefaultClientConnectionOperator;
+import org.apache.http.localserver.ServerTestBase;
+import org.apache.http.params.BasicHttpParams;
+
+public class TestConnPoolByRoute extends ServerTestBase {
+
+ public TestConnPoolByRoute(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestConnPoolByRoute.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestConnPoolByRoute.class);
+ }
+
+ public void testStatelessConnections() throws Exception {
+ final HttpHost target = getServerHttp();
+ final HttpRoute route = new HttpRoute(target, null, false);
+
+ ClientConnectionOperator operator = new DefaultClientConnectionOperator(
+ supportedSchemes);
+
+ BasicHttpParams params = new BasicHttpParams();
+ ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
+ HttpConnectionManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
+
+ ConnPoolByRoute connPool = new ConnPoolByRoute(operator, params);
+ try {
+ // Allocate max possible entries
+ PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e1 = r1.getPoolEntry(10, TimeUnit.SECONDS);
+ assertNotNull(e1);
+
+ PoolEntryRequest r2 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e2 = r2.getPoolEntry(10, TimeUnit.SECONDS);
+ assertNotNull(e2);
+
+ PoolEntryRequest r3 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e3 = r3.getPoolEntry(10, TimeUnit.SECONDS);
+ assertNotNull(e3);
+
+ // Attempt to allocate one more. Expected to fail
+ PoolEntryRequest r4 = connPool.requestPoolEntry(route, null);
+ try {
+ r4.getPoolEntry(250, TimeUnit.MICROSECONDS);
+ fail("ConnectionPoolTimeoutException should have been thrown");
+ } catch (ConnectionPoolTimeoutException expected) {
+ }
+
+ // Free one
+ connPool.freeEntry(e3);
+
+ // This time the request should succeed
+ PoolEntryRequest r5 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e5 = r5.getPoolEntry(10, TimeUnit.SECONDS);
+ assertNotNull(e5);
+
+ } finally {
+ connPool.shutdown();
+ }
+ }
+
+ public void testStatefullConnections() throws Exception {
+ final HttpHost target = getServerHttp();
+ final HttpRoute route = new HttpRoute(target, null, false);
+
+ ClientConnectionOperator operator = new DefaultClientConnectionOperator(
+ supportedSchemes);
+
+ BasicHttpParams params = new BasicHttpParams();
+ ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
+ HttpConnectionManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
+
+ ConnPoolByRoute connPool = new ConnPoolByRoute(operator, params);
+ try {
+ // Allocate max possible entries
+ PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e1 = r1.getPoolEntry(10, TimeUnit.SECONDS);
+
+ PoolEntryRequest r2 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e2 = r2.getPoolEntry(10, TimeUnit.SECONDS);
+
+ PoolEntryRequest r3 = connPool.requestPoolEntry(route, null);
+ BasicPoolEntry e3 = r3.getPoolEntry(10, TimeUnit.SECONDS);
+
+ // Set states
+ e1.setState(Integer.valueOf(1));
+ e2.setState(Integer.valueOf(2));
+ e3.setState(Integer.valueOf(3));
+
+ // Release entries
+ connPool.freeEntry(e1);
+ connPool.freeEntry(e2);
+ connPool.freeEntry(e3);
+
+ // Request statefull entries
+ PoolEntryRequest r4 = connPool.requestPoolEntry(route, Integer.valueOf(2));
+ BasicPoolEntry e4 = r4.getPoolEntry(10, TimeUnit.SECONDS);
+
+ PoolEntryRequest r5 = connPool.requestPoolEntry(route, Integer.valueOf(3));
+ BasicPoolEntry e5 = r5.getPoolEntry(10, TimeUnit.SECONDS);
+
+ PoolEntryRequest r6 = connPool.requestPoolEntry(route, Integer.valueOf(1));
+ BasicPoolEntry e6 = r6.getPoolEntry(10, TimeUnit.SECONDS);
+
+ assertNotNull(e4.getState());
+ assertNotNull(e5.getState());
+ assertNotNull(e6.getState());
+
+ // Check whether we got the same objects
+ assertTrue(e4 == e2);
+ assertTrue(e5 == e3);
+ assertTrue(e6 == e1);
+
+ // Release entries again
+ connPool.freeEntry(e4);
+ connPool.freeEntry(e5);
+ connPool.freeEntry(e6);
+
+ // Request an entry with a state not avaialable in the pool
+ PoolEntryRequest r7 = connPool.requestPoolEntry(route, Integer.valueOf(4));
+ BasicPoolEntry e7 = r7.getPoolEntry(10, TimeUnit.SECONDS);
+
+ // Make sure we got a closed connection and a stateless entry back
+ assertFalse(e7.getConnection().isOpen());
+ assertNull(e7.getState());
+
+ } finally {
+ connPool.shutdown();
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java?rev=649204&r1=649203&r2=649204&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java Thu Apr 17 10:50:13 2008
@@ -114,7 +114,6 @@
}
bpe = new BasicPoolEntry(ccop, route, null);
- assertEquals ("wrong operator", ccop, bpe.getOperator());
assertEquals ("wrong route", route, bpe.getPlannedRoute());
assertNotNull("missing ref", bpe.getWeakRef());