You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mb...@apache.org on 2005/05/31 03:09:20 UTC
svn commit: r179178 -
/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient
Author: mbecke
Date: Mon May 30 18:09:19 2005
New Revision: 179178
URL: http://svn.apache.org/viewcvs?rev=179178&view=rev
Log:
Ported TestHttpConnectionManager to HttpClientTestBase
Modified:
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestLocalHost.java
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java?rev=179178&r1=179177&r2=179178&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java Mon May 30 18:09:19 2005
@@ -45,6 +45,8 @@
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.commons.httpclient.server.SimpleRequest;
+import org.apache.commons.httpclient.server.SimpleResponse;
/**
* Unit tests for {@link HttpConnectionManager}.
@@ -52,10 +54,10 @@
* @author Marc A. Saegesser
* @version $Id$
*/
-public class TestHttpConnectionManager extends TestLocalHostBase {
+public class TestHttpConnectionManager extends HttpClientTestBase {
// ------------------------------------------------------------ Constructor
- public TestHttpConnectionManager(String testName) {
+ public TestHttpConnectionManager(String testName) throws IOException {
super(testName);
}
@@ -83,12 +85,13 @@
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.getParams().setIntParameter(
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
- HttpClient client = createHttpClient(mgr);
+ client.setHttpConnectionManager(mgr);
+ this.server.setHttpService(new RejectConnectService());
// we're going to execute a connect method against the localhost, assuming
// that CONNECT is not supported. This should test the fakeResponse()
// code on HttpMethodBase.
- client.getHostConfiguration().setProxy(getHost(), getPort());
+ client.getHostConfiguration().setProxy(server.getLocalAddress(), server.getLocalPort());
// we must set the host to a secure destination or the CONNECT method
// will not be used
client.getHostConfiguration().setHost(
@@ -190,16 +193,18 @@
public void testDroppedThread() throws Exception {
+ this.server.setHttpService(new EchoService());
+
MultiThreadedHttpConnectionManager mthcm = new MultiThreadedHttpConnectionManager();
- HttpClient httpClient = createHttpClient(mthcm);
+ client.setHttpConnectionManager(mthcm);
WeakReference wr = new WeakReference(mthcm);
GetMethod method = new GetMethod("/");
- httpClient.executeMethod(method);
+ client.executeMethod(method);
method.releaseConnection();
mthcm = null;
- httpClient = null;
+ client = null;
method = null;
System.gc();
@@ -221,7 +226,7 @@
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(1);
- HttpClient client = createHttpClient(connectionManager);
+ client.setHttpConnectionManager(connectionManager);
GetMethod get = new GetMethod("/") {
protected boolean writeRequestBody(HttpState state, HttpConnection conn)
@@ -251,10 +256,12 @@
public void testReleaseConnection() {
+ this.server.setHttpService(new EchoService());
+
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(1);
- HttpClient client = createHttpClient(connectionManager);
+ client.setHttpConnectionManager(connectionManager);
// we shouldn't have to wait if a connection is available
client.getParams().setConnectionManagerTimeout(1);
@@ -300,10 +307,12 @@
*/
public void testResponseAutoRelease() throws Exception {
+ this.server.setHttpService(new EchoService());
+
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(1);
- HttpClient client = createHttpClient(connectionManager);
+ client.setHttpConnectionManager(connectionManager);
// we shouldn't have to wait if a connection is available
client.getParams().setConnectionManagerTimeout( 1 );
@@ -539,10 +548,12 @@
public void testMaxConnectionsPerServer() {
+ this.server.setHttpService(new EchoService());
+
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(1);
- HttpClient client = createHttpClient(connectionManager);
+ client.setHttpConnectionManager(connectionManager);
// we shouldn't have to wait if a connection is available
client.getParams().setConnectionManagerTimeout( 1 );
@@ -572,35 +583,33 @@
public void testDeleteClosedConnections() {
MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
-
- HostConfiguration hostConfig = new HostConfiguration();
-
- configureHostConfiguration(hostConfig);
- HttpConnection conn = manager.getConnection(hostConfig);
+ HttpConnection conn = manager.getConnection(client.getHostConfiguration());
assertEquals("connectionsInPool", manager.getConnectionsInPool(), 1);
- assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(hostConfig), 1);
+ assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(client.getHostConfiguration()), 1);
conn.close();
conn.releaseConnection();
assertEquals("connectionsInPool", manager.getConnectionsInPool(), 1);
- assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(hostConfig), 1);
+ assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(client.getHostConfiguration()), 1);
manager.deleteClosedConnections();
assertEquals("connectionsInPool", manager.getConnectionsInPool(), 0);
- assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(hostConfig), 0);
+ assertEquals("connectionsInPool(host)", manager.getConnectionsInPool(client.getHostConfiguration()), 0);
}
public void testReclaimUnusedConnection() {
+ this.server.setHttpService(new EchoService());
+
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setIntParameter(
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
- HttpClient client = createHttpClient(connectionManager);
+ client.setHttpConnectionManager(connectionManager);
// we shouldn't have to wait if a connection is available
client.getParams().setConnectionManagerTimeout( 30000 );
@@ -630,7 +639,9 @@
public void testGetFromMultipleThreads() {
- HttpClient client = createHttpClient(new MultiThreadedHttpConnectionManager());
+ this.server.setHttpService(new EchoService());
+
+ client.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
ExecuteMethodThread[] threads = new ExecuteMethodThread[10];
for (int i = 0; i < threads.length; i++) {
@@ -699,6 +710,19 @@
throws IOException, UnknownHostException {
throw new IllegalStateException("createSocket() should never have been called.");
}
+ }
+
+ static class RejectConnectService extends EchoService {
+ public boolean process(SimpleRequest request, SimpleResponse response)
+ throws IOException {
+ if (request.getRequestLine().getMethod().equalsIgnoreCase("CONNECT")) {
+ response.setStatusLine(request.getRequestLine().getHttpVersion(), HttpStatus.SC_METHOD_NOT_ALLOWED);
+ response.setHeader(new Header("Connection", "close"));
+ return true;
+ } else {
+ return super.process(request, response);
+ }
+ }
}
static class GetConnectionThread extends Thread {
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestLocalHost.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestLocalHost.java?rev=179178&r1=179177&r2=179178&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestLocalHost.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestLocalHost.java Mon May 30 18:09:19 2005
@@ -52,7 +52,6 @@
suite.addTest(TestMethodsLocalHost.suite());
suite.addTest(TestGetMethodLocal.suite());
suite.addTest(TestTraceMethodLocal.suite());
- suite.addTest(TestHttpConnectionManager.suite());
suite.addTest(TestWebapp.suite());
return suite;
}
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java?rev=179178&r1=179177&r2=179178&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java Mon May 30 18:09:19 2005
@@ -84,6 +84,7 @@
suite.addTest(TestRedirects.suite());
// Connection management
suite.addTest(TestHttpConnection.suite());
+ suite.addTest(TestHttpConnectionManager.suite());
suite.addTest(TestConnectionPersistence.suite());
suite.addTest(TestIdleConnectionTimeout.suite());
suite.addTest(TestMethodAbort.suite());
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org