hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r632854 - in /httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http: mockup/ nio/protocol/
Date Sun, 02 Mar 2008 21:51:01 GMT
Author: olegk
Date: Sun Mar  2 13:51:00 2008
New Revision: 632854

URL: http://svn.apache.org/viewvc?rev=632854&view=rev
Log:
Improved handling of I/O and runtime exceptions in NIO test cases

Modified:
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/RequestCount.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/RequestCount.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/RequestCount.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/RequestCount.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/RequestCount.java
Sun Mar  2 13:51:00 2008
@@ -31,10 +31,13 @@
 
 package org.apache.http.mockup;
 
+import java.io.IOException;
+
 public class RequestCount {
 
     private volatile boolean aborted;
     private volatile int value;
+    private volatile Exception ex;
     
     public RequestCount(int initialValue) {
         this.value = initialValue;
@@ -61,11 +64,19 @@
         }
     }
 
+    public void failure(final Exception ex) {
+        synchronized (this) {
+            this.aborted = true;
+            this.ex = ex;
+            notifyAll();
+        }
+    }
+
     public boolean isAborted() {
         return this.aborted;
     }
     
-    public void await(int count, long timeout) throws InterruptedException {
+    public void await(int count, long timeout) throws InterruptedException, IOException {
         synchronized (this) {
             long deadline = System.currentTimeMillis() + timeout;
             long remaining = timeout;
@@ -79,9 +90,18 @@
                 }
             }
         }
+        if (this.ex != null) {
+            if (this.ex instanceof IOException) {
+                throw (IOException) this.ex;
+            } else if (this.ex instanceof RuntimeException) {
+                throw (RuntimeException) this.ex;
+            } else {
+                throw new RuntimeException("Unexpected exception", ex);
+            }
+        }
     }
     
-    public void await(long timeout) throws InterruptedException {
+    public void await(long timeout) throws InterruptedException, IOException {
         await(0, timeout);
     }
     

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
Sun Mar  2 13:51:00 2008
@@ -49,6 +49,8 @@
     
     private volatile IOReactorThread thread;
 
+    private volatile RequestCount requestCount;
+    
     public TestHttpClient(final HttpParams params) throws IOException {
         super();
         this.ioReactor = new DefaultConnectingIOReactor(2, params);
@@ -59,6 +61,10 @@
         return this.params;
     }
     
+    public void setRequestCount(final RequestCount requestCount) {
+        this.requestCount = requestCount;
+    }
+
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -121,10 +127,11 @@
         public void run() {
             try {
                 execute(this.clientHandler);
-            } catch (IOException ex) {
-                this.ex = ex;
-            } catch (RuntimeException ex) {
+            } catch (Exception ex) {
                 this.ex = ex;
+                if (requestCount != null) {
+                    requestCount.failure(ex);
+                }
             }
         }
         

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
Sun Mar  2 13:51:00 2008
@@ -55,6 +55,7 @@
     
     private volatile IOReactorThread thread;
 
+    private volatile RequestCount requestCount;
     
     public TestHttpSSLClient(final HttpParams params) throws Exception {
         super();
@@ -77,6 +78,10 @@
         return this.params;
     }
     
+    public void setRequestCount(final RequestCount requestCount) {
+        this.requestCount = requestCount;
+    }
+
     private void execute(final NHttpClientHandler clientHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new SSLClientIOEventDispatch(
                 clientHandler, 
@@ -95,6 +100,14 @@
         this.thread.start();
     }
     
+    public Exception getException() {
+        if (this.thread != null) {
+            return this.thread.getException();
+        } else {
+            return null;
+        }
+    }
+    
     public void shutdown() throws IOException {
         this.ioReactor.shutdown();
         try {
@@ -109,6 +122,8 @@
 
         private final NHttpClientHandler clientHandler;
         
+        private volatile Exception ex;
+        
         public IOReactorThread(final NHttpClientHandler clientHandler) {
             super();
             this.clientHandler = clientHandler;
@@ -118,9 +133,16 @@
         public void run() {
             try {
                 execute(this.clientHandler);
-            } catch (IOException ex) {
-                ex.printStackTrace();
+            } catch (Exception ex) {
+                this.ex = ex;
+                if (requestCount != null) {
+                    requestCount.failure(ex);
+                }
             }
+        }
+        
+        public Exception getException() {
+            return this.ex;
         }
 
     }    

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
Sun Mar  2 13:51:00 2008
@@ -62,6 +62,8 @@
     private volatile IOReactorThread thread;
     private ListenerEndpoint endpoint;
     
+    private volatile RequestCount requestCount;
+    
     public TestHttpSSLServer(final HttpParams params) throws Exception {
         super();
         this.params = params;
@@ -83,6 +85,10 @@
         return this.params;
     }
     
+    public void setRequestCount(final RequestCount requestCount) {
+        this.requestCount = requestCount;
+    }
+
     private void execute(final NHttpServiceHandler serviceHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
                 serviceHandler, 
@@ -102,6 +108,14 @@
         this.thread.start();
     }
     
+    public Exception getException() {
+        if (this.thread != null) {
+            return this.thread.getException();
+        } else {
+            return null;
+        }
+    }
+    
     public void shutdown() throws IOException {
         this.ioReactor.shutdown();
         try {
@@ -116,6 +130,8 @@
 
         private final NHttpServiceHandler serviceHandler;
         
+        private volatile Exception ex;
+        
         public IOReactorThread(final NHttpServiceHandler serviceHandler) {
             super();
             this.serviceHandler = serviceHandler;
@@ -125,9 +141,16 @@
         public void run() {
             try {
                 execute(this.serviceHandler);
-            } catch (IOException ex) {
-                ex.printStackTrace();
+            } catch (Exception ex) {
+                this.ex = ex;
+                if (requestCount != null) {
+                    requestCount.failure(ex);
+                }
             }
+        }
+        
+        public Exception getException() {
+            return this.ex;
         }
 
     }    

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
Sun Mar  2 13:51:00 2008
@@ -56,6 +56,8 @@
     private volatile IOReactorThread thread;
     private ListenerEndpoint endpoint;
     
+    private volatile RequestCount requestCount;
+    
     public TestHttpServer(final HttpParams params) throws IOException {
         super();
         this.ioReactor = new DefaultListeningIOReactor(2, params);
@@ -66,6 +68,10 @@
         return this.params;
     }
     
+    public void setRequestCount(final RequestCount requestCount) {
+        this.requestCount = requestCount;
+    }
+
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -133,10 +139,11 @@
         public void run() {
             try {
                 execute(this.serviceHandler);
-            } catch (IOException ex) {
-                this.ex = ex;
-            } catch (RuntimeException ex) {
+            } catch (Exception ex) {
                 this.ex = ex;
+                if (requestCount != null) {
+                    requestCount.failure(ex);
+                }
             }
         }
         

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
Sun Mar  2 13:51:00 2008
@@ -324,6 +324,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -469,6 +472,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -616,6 +622,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -769,6 +778,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1083,6 +1095,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1215,6 +1230,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1383,6 +1401,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1509,6 +1530,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1624,6 +1648,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -1709,6 +1736,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
Sun Mar  2 13:51:00 2008
@@ -120,6 +120,7 @@
     protected void setUp() throws Exception {
         HttpParams serverParams = new BasicHttpParams();
         serverParams
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
             .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
             .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
             .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
@@ -129,6 +130,8 @@
 
         HttpParams clientParams = new BasicHttpParams();
         clientParams
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
+            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000)
             .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
             .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
             .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
@@ -278,6 +281,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -412,6 +418,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -545,6 +554,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -686,6 +698,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -822,6 +837,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -972,6 +990,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
@@ -983,7 +1004,7 @@
                 new InetSocketAddress("localhost", serverAddress.getPort()),
                 responses);
 
-        requestCount.await(1000000);
+        requestCount.await(10000);
 
         this.client.shutdown();
         this.server.shutdown();
@@ -1091,6 +1112,9 @@
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java?rev=632854&r1=632853&r2=632854&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
Sun Mar  2 13:51:00 2008
@@ -185,9 +185,12 @@
                 requestExecutionHandler, 
                 new SimpleEventListener());
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
-        
+
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
@@ -320,9 +323,12 @@
                 requestExecutionHandler, 
                 new SimpleEventListener());
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
-        
+
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
@@ -458,9 +464,12 @@
                 requestExecutionHandler, 
                 clientEventListener);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
-        
+
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
@@ -601,9 +610,12 @@
                 requestExecutionHandler, 
                 clientEventListener);
 
+        this.server.setRequestCount(requestCount);
+        this.client.setRequestCount(requestCount);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
-        
+
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();



Mime
View raw message