hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r758645 [1/5] - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/ test/java/org/apache/http/impl/nio/reactor/ test/java/org/apache/http/mockup/ test/java/org/apache/http/n...
Date Thu, 26 Mar 2009 13:47:41 GMT
Author: olegk
Date: Thu Mar 26 13:47:19 2009
New Revision: 758645

URL: http://svn.apache.org/viewvc?rev=758645&view=rev
Log:
A complete rewrite of NIO test cases. The test cases should now be much less susceptible to
timing issues due to high load on the testing host, which should reduce intermittent test
cases failures due to timeouts. 

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java
  (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestJob.java
  (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestRequestExecutionHandler.java
  (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestRequestHandler.java
  (with props)
Removed:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/ByteSequence.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/ResponseSequence.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
Thu Mar 26 13:47:19 2009
@@ -68,7 +68,7 @@
  * and {@link ProducingNHttpEntity} interfaces.
  * 
  * When using this implementation, it is important to ensure that entities 
- * supplied for writing implement !ProducingNHttpEntity. Doing so will allow 
+ * supplied for writing implement {@link ProducingNHttpEntity}. Doing so will allow 
  * the entity to be written out asynchronously. If entities supplied for writing 
  * do not implement the {@link ProducingNHttpEntity} interface, a delegate is 
  * added that buffers the entire contents in memory. Additionally, the 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
Thu Mar 26 13:47:19 2009
@@ -31,10 +31,14 @@
 package org.apache.http;
 
 
+import java.io.IOException;
+import java.util.List;
+
 import junit.framework.TestCase;
 
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.reactor.ExceptionEvent;
 import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 import org.apache.http.mockup.TestHttpSSLClient;
 import org.apache.http.mockup.TestHttpSSLServer;
@@ -99,11 +103,38 @@
     }
 
     @Override
-    protected void tearDown() throws Exception {
-        this.server.shutdown();
-        this.client.shutdown();
+    protected void tearDown() {
+        try {
+            this.client.shutdown();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        List<ExceptionEvent> clogs = this.client.getAuditLog();
+        if (clogs != null) {
+            for (ExceptionEvent clog: clogs) {
+                Throwable cause = clog.getCause();
+                if (!(cause instanceof OoopsieRuntimeException)) {
+                    cause.printStackTrace();
+                }
+            }
+        }
+
+        try {
+            this.server.shutdown();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        List<ExceptionEvent> slogs = this.server.getAuditLog();
+        if (slogs != null) {
+            for (ExceptionEvent slog: slogs) {
+                Throwable cause = slog.getCause();
+                if (!(cause instanceof OoopsieRuntimeException)) {
+                    cause.printStackTrace();
+                }
+            }
+        }
     }
-    
+
     protected NHttpServiceHandler createHttpServiceHandler(
             final HttpRequestHandler requestHandler,
             final HttpExpectationVerifier expectationVerifier,

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java
Thu Mar 26 13:47:19 2009
@@ -30,10 +30,14 @@
 
 package org.apache.http;
 
+import java.io.IOException;
+import java.util.List;
+
 import junit.framework.TestCase;
 
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.reactor.ExceptionEvent;
 import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 import org.apache.http.mockup.TestHttpClient;
 import org.apache.http.mockup.TestHttpServer;
@@ -77,32 +81,59 @@
     protected void setUp() throws Exception {
         HttpParams serverParams = new BasicHttpParams();
         serverParams
-            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
             .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
             .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
             .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
             .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1");
-        
+
         this.server = new TestHttpServer(serverParams);
-        
+
         HttpParams clientParams = new BasicHttpParams();
         clientParams
-            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
-            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000)
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
+            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000)
             .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
             .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
             .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
             .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1");
-        
+
         this.client = new TestHttpClient(clientParams);
     }
 
     @Override
-    protected void tearDown() throws Exception {
-        this.server.shutdown();
-        this.client.shutdown();
+    protected void tearDown() {
+        try {
+            this.client.shutdown();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        List<ExceptionEvent> clogs = this.client.getAuditLog();
+        if (clogs != null) {
+            for (ExceptionEvent clog: clogs) {
+                Throwable cause = clog.getCause();
+                if (!(cause instanceof OoopsieRuntimeException)) {
+                    cause.printStackTrace();
+                }
+            }
+        }
+
+        try {
+            this.server.shutdown();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        List<ExceptionEvent> slogs = this.server.getAuditLog();
+        if (slogs != null) {
+            for (ExceptionEvent slog: slogs) {
+                Throwable cause = slog.getCause();
+                if (!(cause instanceof OoopsieRuntimeException)) {
+                    cause.printStackTrace();
+                }
+            }
+        }
     }
-    
+
     protected NHttpServiceHandler createHttpServiceHandler(
             final HttpRequestHandler requestHandler,
             final HttpExpectationVerifier expectationVerifier,

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java?rev=758645&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java
Thu Mar 26 13:47:19 2009
@@ -0,0 +1,42 @@
+/*
+ * $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;
+
+public class OoopsieRuntimeException extends RuntimeException {
+
+    private static final long serialVersionUID = 662807254163212266L;
+
+    public OoopsieRuntimeException() {
+        super("Ooopsie!!!");
+    }
+    
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
Thu Mar 26 13:47:19 2009
@@ -41,6 +41,7 @@
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
+import org.apache.http.OoopsieRuntimeException;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.mockup.RequestCount;
 import org.apache.http.mockup.SimpleEventListener;
@@ -190,7 +191,7 @@
                     final HttpRequest request, 
                     final HttpResponse response, 
                     final HttpContext context) throws HttpException, IOException {
-                throw new IllegalStateException("Oppsie!!!");
+                throw new OoopsieRuntimeException();
             }
             
         };
@@ -245,7 +246,7 @@
         assertNotNull(ex);
         assertTrue(ex instanceof IOReactorException);
         assertNotNull(ex.getCause());
-        assertTrue(ex.getCause() instanceof IllegalStateException);
+        assertTrue(ex.getCause() instanceof OoopsieRuntimeException);
         
         List<ExceptionEvent> auditlog = this.server.getAuditLog();
         assertNotNull(auditlog);
@@ -268,7 +269,7 @@
                     final HttpRequest request, 
                     final HttpResponse response, 
                     final HttpContext context) throws HttpException, IOException {
-                throw new IllegalStateException("Oppsie!!!");
+                throw new OoopsieRuntimeException();
             }
             
         };
@@ -341,7 +342,7 @@
         assertNotNull(ex);
         assertTrue(ex instanceof IOReactorException);
         assertNotNull(ex.getCause());
-        assertTrue(ex.getCause() instanceof IllegalStateException);
+        assertTrue(ex.getCause() instanceof OoopsieRuntimeException);
 
         List<ExceptionEvent> auditlog = this.server.getAuditLog();
         assertNotNull(auditlog);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
Thu Mar 26 13:47:19 2009
@@ -46,6 +46,7 @@
 import org.apache.http.impl.nio.reactor.ExceptionEvent;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.params.HttpParams;
 
@@ -92,6 +93,10 @@
         this.requestCount = requestCount;
     }
 
+    public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
+        this.ioReactor.setExceptionHandler(exceptionHandler);
+    }
+
     private void execute(final NHttpClientHandler clientHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new SSLClientIOEventDispatch(
                 clientHandler, 
@@ -110,6 +115,12 @@
         this.thread.start();
     }
     
+    public void join(long timeout) throws InterruptedException {
+        if (this.thread != null) {
+            this.thread.join(timeout);
+        }
+    }
+    
     public Exception getException() {
         if (this.thread != null) {
             return this.thread.getException();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java?rev=758645&r1=758644&r2=758645&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
Thu Mar 26 13:47:19 2009
@@ -46,6 +46,7 @@
 import org.apache.http.impl.nio.reactor.ExceptionEvent;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.params.HttpParams;
@@ -98,6 +99,10 @@
         this.requestCount = requestCount;
     }
 
+    public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
+        this.ioReactor.setExceptionHandler(exceptionHandler);
+    }
+
     private void execute(final NHttpServiceHandler serviceHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
                 serviceHandler, 
@@ -117,6 +122,12 @@
         this.thread.start();
     }
     
+    public void join(long timeout) throws InterruptedException {
+        if (this.thread != null) {
+            this.thread.join(timeout);
+        }
+    }
+    
     public Exception getException() {
         if (this.thread != null) {
             return this.thread.getException();



Mime
View raw message