You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by John Karp <jo...@gmail.com> on 2011/06/21 20:51:00 UTC

Unit testing connection pool release

Hi,

I'm trying to ensure that my own code is handling HttpEntities and
their streams properly, so that the underlying connections get
returned to the pool.

Is there a recommended way to write unit tests for this? It seems I'll
have to check connManager.pool.leasedConnections.size() == 0 after
each operation, but since they're protected members I have to subclass
both the connection manager and connection pool classes to get the
value out. Is there better approach?

Also, is there away to glean from a leased connection pool entry what
URL it was used to fetch? (The entire URL, not just the 'route') That
would be helpful with troubleshooting any issues that weren't caught
by the unit testing.

Thanks,
John

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Unit testing connection pool release

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2011-06-21 at 13:51 -0500, John Karp wrote:
> Hi,
> 
> I'm trying to ensure that my own code is handling HttpEntities and
> their streams properly, so that the underlying connections get
> returned to the pool.
> 
> Is there a recommended way to write unit tests for this? It seems I'll
> have to check connManager.pool.leasedConnections.size() == 0 after
> each operation, but since they're protected members I have to subclass
> both the connection manager and connection pool classes to get the
> value out. Is there better approach?
> 

There is currently no convenient way of interrogating the state of the
connection pool in HttpClient. Feel free to raise a request in JIRA for
this feature.  

> Also, is there away to glean from a leased connection pool entry what
> URL it was used to fetch? (The entire URL, not just the 'route') That
> would be helpful with troubleshooting any issues that weren't caught
> by the unit testing.
> 

The only way one can get access to the underlying HTTP connection is by
looking it up in the HTTP context. The actual HTTP request instance can
be obtained from the same context.

Hope this helps

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org