Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 38517 invoked from network); 6 May 2007 10:16:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 May 2007 10:16:05 -0000 Received: (qmail 99279 invoked by uid 500); 6 May 2007 10:16:11 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 99259 invoked by uid 500); 6 May 2007 10:16:11 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 99250 invoked by uid 99); 6 May 2007 10:16:11 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 May 2007 03:16:11 -0700 X-ASF-Spam-Status: No, hits=-99.3 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME,SUBJECT_NOVOWEL X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 May 2007 03:16:04 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DB5D41A9838; Sun, 6 May 2007 03:15:43 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r535592 - in /jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http: impl/conn/TestTSCCMWithServer.java localserver/ServerTestBase.java Date: Sun, 06 May 2007 10:15:43 -0000 To: httpcomponents-commits@jakarta.apache.org From: rolandw@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070506101543.DB5D41A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rolandw Date: Sun May 6 03:15:39 2007 New Revision: 535592 URL: http://svn.apache.org/viewvc?view=rev&rev=535592 Log: first server-based test case for TSCCM Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/localserver/ServerTestBase.java Modified: 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=diff&rev=535592&r1=535591&r2=535592 ============================================================================== --- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java (original) +++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMWithServer.java Sun May 6 03:15:39 2007 @@ -42,6 +42,7 @@ import org.apache.http.conn.ManagedClientConnection; import org.apache.http.conn.SchemeRegistry; import org.apache.http.conn.params.HttpConnectionManagerParams; +import org.apache.http.conn.ConnectionPoolTimeoutException; import org.apache.http.localserver.ServerTestBase; import org.apache.http.message.BasicHttpRequest; import org.apache.http.params.BasicHttpParams; @@ -110,19 +111,18 @@ /** * 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 + public void testReleaseConnection() throws Exception { + //public void testSkeleton() throws Exception { HttpParams mgrpar = createManagerParams(); - HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(mgrpar, 1); - HttpConnectionManagerParams.setMaxTotalConnections(mgrpar, 3); + HttpConnectionManagerParams.setMaxTotalConnections(mgrpar, 1); ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null); - HttpHost target = getServerHttp(); + final HttpHost target = getServerHttp(); final HttpRoute route = new HttpRoute(target, null, false); - final String uri = "/random/8"; // read 8 bytes + final int rsplen = 8; + final String uri = "/random/" + rsplen; HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1); @@ -130,13 +130,14 @@ ManagedClientConnection conn = mgr.getConnection(route); conn.open(route, httpContext, defaultParams); + // a new context is created for each testcase, no need to reset httpContext.setAttribute( - HttpExecutionContext.HTTP_CONNECTION, conn); + HttpExecutionContext.HTTP_CONNECTION, conn); httpContext.setAttribute( - HttpExecutionContext.HTTP_TARGET_HOST, target); + HttpExecutionContext.HTTP_TARGET_HOST, target); httpContext.setAttribute( - HttpExecutionContext.HTTP_REQUEST, request); - + HttpExecutionContext.HTTP_REQUEST, request); + httpExecutor.preProcess (request, httpProcessor, httpContext); HttpResponse response = @@ -144,18 +145,65 @@ httpExecutor.postProcess (response, httpProcessor, httpContext); - assertEquals("wrong status in response", + assertEquals("wrong status in first response", HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); byte[] data = EntityUtils.toByteArray(response.getEntity()); + assertEquals("wrong length of first response entity", + rsplen, data.length); + // ignore data, but it must be read + + // check that there is no auto-release by default + try { + // this should fail quickly, connection has not been released + mgr.getConnection(route, 10L); + fail("ConnectionPoolTimeoutException should have been thrown"); + } catch (ConnectionPoolTimeoutException e) { + // expected + } + + // release connection without marking for re-use + // expect the next connection obtained to be closed + mgr.releaseConnection(conn); + conn = mgr.getConnection(route); + assertFalse("connection should have been closed", conn.isOpen()); + + // repeat the communication, no need to prepare the request again + conn.open(route, httpContext, defaultParams); + httpContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn); + response = httpExecutor.execute(request, conn, httpContext); + httpExecutor.postProcess(response, httpProcessor, httpContext); + + assertEquals("wrong status in second response", + HttpStatus.SC_OK, + response.getStatusLine().getStatusCode()); + data = EntityUtils.toByteArray(response.getEntity()); + assertEquals("wrong length of second response entity", + rsplen, data.length); // ignore data, but it must be read + // release connection after marking it for re-use + // expect the next connection obtained to be open + conn.markReusable(); mgr.releaseConnection(conn); + conn = mgr.getConnection(route); + assertTrue("connection should have been open", conn.isOpen()); + + // repeat the communication, no need to prepare the request again + httpContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn); + response = httpExecutor.execute(request, conn, httpContext); + httpExecutor.postProcess(response, httpProcessor, httpContext); + + assertEquals("wrong status in third response", + HttpStatus.SC_OK, + response.getStatusLine().getStatusCode()); + data = EntityUtils.toByteArray(response.getEntity()); + assertEquals("wrong length of third response entity", + rsplen, data.length); + // ignore data, but it must be read - //@@@ 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 + mgr.releaseConnection(conn); + mgr.shutdown(); } @@ -166,7 +214,7 @@ // testConnectMethodFailureRelease // testDroppedThread // testWriteRequestReleaseConnection, depends on execution framework - // testReleaseConnection, depends on execution framework + // + testReleaseConnection, depends on execution framework // testResponseAutoRelease // testMaxConnectionsPerServer - what's the server used/needed for? // testReclaimUnusedConnection, depends on execution framework Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/localserver/ServerTestBase.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/localserver/ServerTestBase.java?view=diff&rev=535592&r1=535591&r2=535592 ============================================================================== --- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/localserver/ServerTestBase.java (original) +++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/localserver/ServerTestBase.java Sun May 6 03:15:39 2007 @@ -98,15 +98,19 @@ * This method will re-use the helper objects from a previous run * if they are still available. For example, the local test server * will be re-started rather than re-created. - * Tests that modify the helper objects should afterwards - * set the respective attributes to null to force - * re-creation for subsequent tests. Of course that shouldn't - * be done to the test server, or only after shutting that down. + * {@link #httpContext httpContext} will always be re-created. + * Tests that modify the other helper objects should afterwards + * set the respective attributes to null in a + * finally{} block to force re-creation for + * subsequent tests. + * Of course that shouldn't be done with the test server, + * or only after shutting that down. * * @throws Exception in case of a problem */ protected void setUp() throws Exception { + boolean newparams = false; if (defaultParams == null) { defaultParams = new BasicHttpParams(null); HttpProtocolParams.setVersion @@ -117,6 +121,7 @@ (defaultParams, "Jakarta-HttpComponents-Test/1.1"); HttpProtocolParams.setUseExpectContinue (defaultParams, false); + newparams = true; } if (supportedSchemes == null) { @@ -131,11 +136,10 @@ httpProcessor.addInterceptor(new RequestConnControl()); // optional } - if (httpContext == null) { - httpContext = new HttpExecutionContext(null); - } + // the context is created each time, it may get modified by test cases + httpContext = new HttpExecutionContext(null); - if (httpExecutor == null) { + if ((httpExecutor == null) || newparams) { httpExecutor = new HttpRequestExecutor(defaultParams); }