hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r535483 - in /jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn: TestAllConnImpl.java TestTSCCMNoServer.java TestTSCCMWithServer.java
Date Sat, 05 May 2007 09:27:04 GMT
Author: rolandw
Date: Sat May  5 02:27:03 2007
New Revision: 535483

URL: http://svn.apache.org/viewvc?view=rev&rev=535483
Log:
towards the first server-based test for TSCCM

Added:
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java?view=diff&rev=535483&r1=535482&r2=535483
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java
Sat May  5 02:27:03 2007
@@ -45,6 +45,7 @@
 
         suite.addTest(TestLocalServer.suite());
         suite.addTest(TestTSCCMNoServer.suite());
+        suite.addTest(TestTSCCMWithServer.suite());
 
         return suite;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java?view=diff&rev=535483&r1=535482&r2=535483
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
Sat May  5 02:27:03 2007
@@ -374,7 +374,7 @@
         HostConfiguration hcfg = route.toHostConfig(); //@@@ deprecated
 
         ManagedClientConnection conn = mgr.getConnection(route);
-        
+
         assertEquals("connectionsInPool",
                      mgr.getConnectionsInPool(), 1);
         assertEquals("connectionsInPool(host)",
@@ -399,5 +399,6 @@
     // testShutdownAll, depends on parameterization and extra threads
     // testShutdown, depends on parameterization and extra threads
     // testHostReusePreference, depends on parameterization and extra threads
+    // testWaitingThreadInterrupted - depends on extra thread
 
 } // class TestTSCCMNoServer

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java?view=auto&rev=535483
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
Sat May  5 02:27:03 2007
@@ -0,0 +1,169 @@
+/*
+ * $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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.util.EntityUtils;
+import org.apache.http.conn.Scheme;
+import org.apache.http.conn.SchemeRegistry;
+import org.apache.http.conn.SocketFactory;
+import org.apache.http.conn.PlainSocketFactory;
+import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.HostConfiguration; //@@@ deprecated
+import org.apache.http.conn.ManagedClientConnection;
+import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.params.HttpConnectionManagerParams;
+import org.apache.http.localserver.ServerTestBase;
+
+
+/**
+ * Tests for <code>ThreadSafeClientConnManager</code> that do require
+ * a server to communicate with.
+ */
+public class TestTSCCMWithServer extends ServerTestBase {
+
+    public TestTSCCMWithServer(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestTSCCMWithServer.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestTSCCMWithServer.class);
+    }
+
+
+    /**
+     * Helper to instantiate a <code>ThreadSafeClientConnManager</code>.
+     *
+     * @param params    the parameters, or
+     *                  <code>null</code> to use defaults
+     * @param schreg    the scheme registry, or
+     *                  <code>null</code> to use defaults
+     *
+     * @return  a connection manager to test
+     */
+    public ThreadSafeClientConnManager createTSCCM(HttpParams params,
+                                                   SchemeRegistry schreg) {
+        if (params == null)
+            params = defaultParams;
+        if (schreg == null)
+            schreg = supportedSchemes;
+
+        return new ThreadSafeClientConnManager(params, schreg);
+    }
+
+
+    /**
+     * Instantiates default parameters for a connection manager.
+     *
+     * @return  the default parameters
+     */
+    public HttpParams createManagerParams() {
+
+        HttpParams params = new BasicHttpParams();
+        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+        HttpProtocolParams.setUseExpectContinue(params, false);
+
+        return params;
+    }
+
+
+    /**
+     * Tests releasing and re-using a connection after a response is read.
+     */
+    // public void testReleaseConnection() throws Exception {
+    public void testSkeleton() throws Exception {
+        //@@@ this testcase is not yet complete
+
+        HttpParams mgrpar = createManagerParams();
+        HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(mgrpar, 1);
+        HttpConnectionManagerParams.setMaxTotalConnections(mgrpar, 3);
+
+        ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
+
+        final HttpRoute route = new HttpRoute(getServerHttp(), null, false);
+        final String    uri   = "/random/8"; // read 8 bytes
+
+        HttpRequest request =
+            new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
+
+        ManagedClientConnection conn = mgr.getConnection(route);
+        conn.open(route, httpContext, defaultParams);
+
+        HttpResponse response =
+            httpExecutor.execute(request, conn, httpContext);
+
+        assertEquals("wrong status in response",
+                     HttpStatus.SC_OK,
+                     response.getStatusLine().getStatusCode());
+        byte[] data = EntityUtils.toByteArray(response.getEntity());
+        // ignore data, but it must be read
+
+        mgr.releaseConnection(conn);
+
+        //@@@ to be checked:
+        // - connection is NOT re-used if not marked before release
+        // - connection is re-used if marked before release
+        // - re-using the connections works
+    }
+
+
+    // List of server-based tests in 3.x TestHttpConnectionManager
+    // The execution framework (HttpClient) used by some of them
+    // can probably be replaced by hand-coded request execution
+    //
+    // testConnectMethodFailureRelease
+    // testDroppedThread
+    // testWriteRequestReleaseConnection, depends on execution framework
+    // testReleaseConnection, depends on execution framework
+    // testResponseAutoRelease
+    // testMaxConnectionsPerServer - what's the server used/needed for?
+    // testReclaimUnusedConnection, depends on execution framework
+    // testGetFromMultipleThreads, depends on execution framework
+
+} // class TestTSCCMWithServer

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message