hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r575700 - in /jakarta/httpcomponents/httpcore/trunk: module-nio/src/main/java/org/apache/http/impl/nio/reactor/ module-niossl/src/test/java/org/apache/http/ module-niossl/src/test/java/org/apache/http/impl/nio/mockup/ module-niossl/src/test...
Date Fri, 14 Sep 2007 14:36:37 GMT
Author: olegk
Date: Fri Sep 14 07:36:36 2007
New Revision: 575700

URL: http://svn.apache.org/viewvc?rev=575700&view=rev
Log:
 HTTPCORE-109: Ported test case improvements from NIO to NIOSSL module

Added:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleEventListener.java
      - copied, changed from r573981, jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
Removed:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=575700&r1=575699&r2=575700&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Fri Sep 14 07:36:36 2007
@@ -140,7 +140,7 @@
                 throw new IOReactorException("Unexpected selector failure", ex);
             }
             
-            if (this.status == SHUT_DOWN) {
+            if (this.status > ACTIVE) {
                 break;
             }
             processEvents(readyCount);
@@ -157,7 +157,7 @@
                         throw (InterruptedIOException) ex;
                     } else if (ex instanceof RuntimeException) {
                         throw (RuntimeException) ex;
-                    } else {
+                    } else if (ex != null) {
                         throw new IOReactorException(ex.getMessage(), ex);
                     }
                 }

Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java?rev=575700&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
Fri Sep 14 07:36:36 2007
@@ -0,0 +1,123 @@
+package org.apache.http;
+
+
+import junit.framework.TestCase;
+
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.mockup.SimpleHttpRequestHandlerResolver;
+import org.apache.http.impl.nio.mockup.TestHttpSSLClient;
+import org.apache.http.impl.nio.mockup.TestHttpSSLServer;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.protocol.BufferingHttpClientHandler;
+import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
+import org.apache.http.nio.protocol.EventListener;
+import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.protocol.HttpExpectationVerifier;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.protocol.ResponseConnControl;
+import org.apache.http.protocol.ResponseContent;
+import org.apache.http.protocol.ResponseDate;
+import org.apache.http.protocol.ResponseServer;
+
+/**
+ * Base class for all HttpCore NIO tests
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class HttpCoreNIOSSLTestBase extends TestCase {
+
+    public HttpCoreNIOSSLTestBase(String testName) {
+        super(testName);
+    }
+
+    protected TestHttpSSLServer server;
+    protected TestHttpSSLClient client;
+    
+    protected void setUp() throws Exception {
+        HttpParams serverParams = new BasicHttpParams();
+        serverParams
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000)
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SERVER/1.1");
+        
+        this.server = new TestHttpSSLServer(serverParams);
+        
+        HttpParams clientParams = new BasicHttpParams();
+        clientParams
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000)
+            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 2000)
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setParameter(HttpProtocolParams.USER_AGENT, "TEST-CLIENT/1.1");
+        
+        this.client = new TestHttpSSLClient(clientParams);
+    }
+
+    protected void tearDown() throws Exception {
+        this.server.shutdown();
+        this.client.shutdown();
+    }
+    
+    protected NHttpServiceHandler createHttpServiceHandler(
+            final HttpRequestHandler requestHandler,
+            final HttpExpectationVerifier expectationVerifier,
+            final EventListener eventListener) {
+        
+        BasicHttpProcessor httpproc = new BasicHttpProcessor();
+        httpproc.addInterceptor(new ResponseDate());
+        httpproc.addInterceptor(new ResponseServer());
+        httpproc.addInterceptor(new ResponseContent());
+        httpproc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                httpproc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setExpectationVerifier(expectationVerifier);
+        serviceHandler.setEventListener(eventListener);
+        
+        return serviceHandler;
+    }
+    
+    protected NHttpClientHandler createHttpClientHandler(
+            final HttpRequestExecutionHandler requestExecutionHandler,
+            final EventListener eventListener) {
+        
+        BasicHttpProcessor httpproc = new BasicHttpProcessor();
+        httpproc.addInterceptor(new RequestContent());
+        httpproc.addInterceptor(new RequestTargetHost());
+        httpproc.addInterceptor(new RequestConnControl());
+        httpproc.addInterceptor(new RequestUserAgent());
+        httpproc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                httpproc,
+                requestExecutionHandler,
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
+
+        clientHandler.setEventListener(eventListener);
+        
+        return clientHandler;
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java?rev=575700&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
Fri Sep 14 07:36:36 2007
@@ -0,0 +1,88 @@
+/*
+ * $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.nio.mockup;
+
+public class RequestCount {
+
+    private volatile boolean aborted;
+    private volatile int value;
+    
+    public RequestCount(int initialValue) {
+        this.value = initialValue;
+        this.aborted = false;
+    }
+    
+    public int getValue() {
+        return this.value;
+    }
+    
+    public void decrement() {
+        synchronized (this) {
+            if (!this.aborted) {
+                this.value--;
+            }
+            notifyAll();
+        }
+    }
+
+    public void abort() {
+        synchronized (this) {
+            this.aborted = true;
+            notifyAll();
+        }
+    }
+
+    public boolean isAborted() {
+        return this.aborted;
+    }
+    
+    public void await(int count, long timeout) throws InterruptedException {
+        synchronized (this) {
+            long deadline = System.currentTimeMillis() + timeout;
+            long remaining = timeout;
+            while (!this.aborted && this.value > count) {
+                wait(remaining);
+                if (timeout > 0) {
+                    remaining = deadline - System.currentTimeMillis();
+                    if (remaining <= 0) {
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    
+    public void await(long timeout) throws InterruptedException {
+        await(0, timeout);
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/RequestCount.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleEventListener.java
(from r573981, jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleEventListener.java?p2=jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleEventListener.java&p1=jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java&r1=573981&r2=575700&rev=575700&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleEventListener.java
Fri Sep 14 07:36:36 2007
@@ -37,33 +37,12 @@
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.protocol.EventListener;
 
-public class CountingEventListener implements EventListener {
+public class SimpleEventListener implements EventListener {
 
-    private volatile int connCount = 0;
-    
-    public CountingEventListener() {
+    public SimpleEventListener() {
         super();
     }
     
-    public int getConnCount() {
-        return this.connCount;
-    }
-    
-    private void incrementConnCount() {
-        synchronized (this) {
-            this.connCount++;
-            this.notifyAll();
-        }
-    }
-    
-    public void await(int connCount, long timeout) throws InterruptedException {
-        synchronized (this) {
-            while (this.connCount < connCount) {
-                this.wait(timeout);
-            }
-        }
-    }
-    
     public void connectionOpen(final NHttpConnection conn) {
     }
 
@@ -71,7 +50,6 @@
     }
 
     public void connectionClosed(final NHttpConnection conn) {
-        incrementConnCount();
     }
 
     public void fatalIOException(final IOException ex, final NHttpConnection conn) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java?rev=575700&r1=575699&r2=575700&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
Fri Sep 14 07:36:36 2007
@@ -38,6 +38,10 @@
 import java.util.List;
 import java.util.Random;
 
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpCoreNIOSSLTestBase;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
@@ -46,45 +50,20 @@
 import org.apache.http.HttpVersion;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.mockup.CountingEventListener;
-import org.apache.http.impl.nio.mockup.SimpleHttpRequestHandlerResolver;
-import org.apache.http.impl.nio.mockup.TestHttpSSLClient;
-import org.apache.http.impl.nio.mockup.TestHttpSSLServer;
-import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.impl.nio.mockup.SimpleEventListener;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.mockup.RequestCount;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.NHttpServiceHandler;
-import org.apache.http.nio.protocol.BufferingHttpClientHandler;
-import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
-import org.apache.http.nio.protocol.EventListener;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpProcessor;
-import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.ExecutionContext;
-import org.apache.http.protocol.HttpExpectationVerifier;
+import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.RequestConnControl;
-import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestExpectContinue;
-import org.apache.http.protocol.RequestTargetHost;
-import org.apache.http.protocol.RequestUserAgent;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
 import org.apache.http.util.EntityUtils;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 /**
  * HttpCore NIO SSL tests.
  *
@@ -92,7 +71,7 @@
  * 
  * @version $Id$
  */
-public class TestNIOSSLHttp extends TestCase {
+public class TestNIOSSLHttp extends HttpCoreNIOSSLTestBase {
 
     // ------------------------------------------------------------ Constructor
     public TestNIOSSLHttp(String testName) {
@@ -111,82 +90,6 @@
         return new TestSuite(TestNIOSSLHttp.class);
     }
 
-    private TestHttpSSLServer server;
-    private TestHttpSSLClient client;
-    
-    protected void setUp() throws Exception {
-        HttpParams serverParams = new BasicHttpParams();
-        serverParams
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 30000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
-            .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SERVER/1.1");
-        
-        this.server = new TestHttpSSLServer(serverParams);
-        
-        HttpParams clientParams = new BasicHttpParams();
-        clientParams
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 30000)
-            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 2000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
-            .setParameter(HttpProtocolParams.USER_AGENT, "TEST-CLIENT/1.1");
-        
-        this.client = new TestHttpSSLClient(clientParams);
-    }
-
-    protected void tearDown() throws Exception {
-        this.server.shutdown();
-        this.client.shutdown();
-    }
-
-    private NHttpServiceHandler createHttpServiceHandler(
-            final HttpRequestHandler requestHandler,
-            final HttpExpectationVerifier expectationVerifier,
-            final EventListener eventListener) {
-        BasicHttpProcessor httpproc = new BasicHttpProcessor();
-        httpproc.addInterceptor(new ResponseDate());
-        httpproc.addInterceptor(new ResponseServer());
-        httpproc.addInterceptor(new ResponseContent());
-        httpproc.addInterceptor(new ResponseConnControl());
-
-        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
-                httpproc,
-                new DefaultHttpResponseFactory(),
-                new DefaultConnectionReuseStrategy(),
-                this.server.getParams());
-
-        serviceHandler.setHandlerResolver(
-                new SimpleHttpRequestHandlerResolver(requestHandler));
-        serviceHandler.setExpectationVerifier(expectationVerifier);
-        serviceHandler.setEventListener(eventListener);
-        
-        return serviceHandler;
-    }
-    
-    private NHttpClientHandler createHttpClientHandler(
-            final HttpRequestExecutionHandler requestExecutionHandler,
-            final EventListener eventListener) {
-        BasicHttpProcessor httpproc = new BasicHttpProcessor();
-        httpproc.addInterceptor(new RequestContent());
-        httpproc.addInterceptor(new RequestTargetHost());
-        httpproc.addInterceptor(new RequestConnControl());
-        httpproc.addInterceptor(new RequestUserAgent());
-        httpproc.addInterceptor(new RequestExpectContinue());
-        
-        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
-                httpproc,
-                requestExecutionHandler,
-                new DefaultConnectionReuseStrategy(),
-                this.client.getParams());
-
-        clientHandler.setEventListener(eventListener);
-
-        return clientHandler;
-    }
-    
     /**
      * This test case executes a series of simple (non-pipelined) GET requests 
      * over multiple connections. 
@@ -196,6 +99,7 @@
         
         final int connNo = 3;
         final int reqNo = 20;
+        final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
         Random rnd = new Random();
         
@@ -269,33 +173,26 @@
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
                     list.add(data);
+                    requestCount.decrement();
                 } catch (IOException ex) {
-                    fail(ex.getMessage());
+                    requestCount.abort();
                 }
 
                 if (i < reqNo) {
                     conn.requestInput();
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                    }
                 }
             }
             
         };
         
-        CountingEventListener serverEventListener = new CountingEventListener();
-        CountingEventListener clientEventListener = new CountingEventListener();
-        
         NHttpServiceHandler serviceHandler = createHttpServiceHandler(
                 requestHandler, 
                 null,
-                serverEventListener);
+                new SimpleEventListener());
 
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler, 
-                clientEventListener);
+                new SimpleEventListener());
 
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
@@ -308,8 +205,8 @@
                     responseData[i]);
         }
      
-        clientEventListener.await(connNo, 10000);
-        assertEquals(connNo, clientEventListener.getConnCount());
+        requestCount.await(10000);
+        assertEquals(0, requestCount.getValue());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -340,6 +237,7 @@
         
         final int connNo = 3;
         final int reqNo = 20;
+        final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
         Random rnd = new Random();
         
@@ -417,33 +315,26 @@
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
                     list.add(data);
+                    requestCount.decrement();
                 } catch (IOException ex) {
-                    fail(ex.getMessage());
+                    requestCount.abort();
                 }
 
                 if (i < reqNo) {
                     conn.requestInput();
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                    }
                 }
             }
             
         };
         
-        CountingEventListener serverEventListener = new CountingEventListener();
-        CountingEventListener clientEventListener = new CountingEventListener();
-        
         NHttpServiceHandler serviceHandler = createHttpServiceHandler(
                 requestHandler, 
                 null,
-                serverEventListener);
+                new SimpleEventListener());
 
         NHttpClientHandler clientHandler = createHttpClientHandler(
                 requestExecutionHandler, 
-                clientEventListener);
+                new SimpleEventListener());
 
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
@@ -456,8 +347,8 @@
                     responseData[i]);
         }
      
-        clientEventListener.await(connNo, 10000);
-        assertEquals(connNo, clientEventListener.getConnCount());
+        requestCount.await(10000);
+        assertEquals(0, requestCount.getValue());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -488,6 +379,7 @@
         
         final int connNo = 3;
         final int reqNo = 20;
+        final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
         Random rnd = new Random();
         
@@ -565,24 +457,20 @@
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
                     list.add(data);
+                    requestCount.decrement();
                 } catch (IOException ex) {
-                    fail(ex.getMessage());
+                    requestCount.abort();
                 }
 
                 if (i < reqNo) {
                     conn.requestInput();
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                    }
                 }
             }
             
         };
         
-        CountingEventListener serverEventListener = new CountingEventListener();
-        CountingEventListener clientEventListener = new CountingEventListener();
+        SimpleEventListener serverEventListener = new SimpleEventListener();
+        SimpleEventListener clientEventListener = new SimpleEventListener();
         
         NHttpServiceHandler serviceHandler = createHttpServiceHandler(
                 requestHandler, 
@@ -604,8 +492,8 @@
                     responseData[i]);
         }
      
-        clientEventListener.await(connNo, 10000);
-        assertEquals(connNo, clientEventListener.getConnCount());
+        requestCount.await(10000);
+        assertEquals(0, requestCount.getValue());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -636,6 +524,7 @@
         
         final int connNo = 3;
         final int reqNo = 20;
+        final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
         Random rnd = new Random();
         
@@ -718,24 +607,20 @@
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
                     list.add(data);
+                    requestCount.decrement();
                 } catch (IOException ex) {
-                    fail(ex.getMessage());
+                    requestCount.abort();
                 }
 
                 if (i < reqNo) {
                     conn.requestInput();
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                    }
                 }
             }
             
         };
         
-        CountingEventListener serverEventListener = new CountingEventListener();
-        CountingEventListener clientEventListener = new CountingEventListener();
+        SimpleEventListener serverEventListener = new SimpleEventListener();
+        SimpleEventListener clientEventListener = new SimpleEventListener();
         
         NHttpServiceHandler serviceHandler = createHttpServiceHandler(
                 requestHandler, 
@@ -757,8 +642,8 @@
                     responseData[i]);
         }
      
-        clientEventListener.await(connNo, 10000);
-        assertEquals(connNo, clientEventListener.getConnCount());
+        requestCount.await(10000);
+        assertEquals(0, requestCount.getValue());
         
         this.client.shutdown();
         this.server.shutdown();



Mime
View raw message