hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r758682 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http: ./ impl/nio/reactor/ mockup/
Date Thu, 26 Mar 2009 15:27:41 GMT
Author: olegk
Date: Thu Mar 26 15:27:21 2009
New Revision: 758682

URL: http://svn.apache.org/viewvc?rev=758682&view=rev
Log:
More NIO test case cleanups

Removed:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/RequestCount.java
Modified:
    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/impl/nio/reactor/TestDefaultIOReactorsSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.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/mockup/TestHttpServer.java

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=758682&r1=758681&r2=758682&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 15:27:21 2009
@@ -36,34 +36,13 @@
 
 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;
-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.CoreConnectionPNames;
-import org.apache.http.params.HttpParams;
 import org.apache.http.params.CoreProtocolPNames;
-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;
+import org.apache.http.params.HttpParams;
 
 /**
  * Base class for all HttpCore NIO tests
@@ -135,51 +114,4 @@
         }
     }
 
-    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;
-    }
-    
 }

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=758682&r1=758681&r2=758682&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 15:27:21 2009
@@ -35,34 +35,13 @@
 
 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;
-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.CoreConnectionPNames;
-import org.apache.http.params.HttpParams;
 import org.apache.http.params.CoreProtocolPNames;
-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;
+import org.apache.http.params.HttpParams;
 
 /**
  * Base class for all HttpCore NIO tests
@@ -134,51 +113,4 @@
         }
     }
 
-    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;
-    }
-    
 }

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=758682&r1=758681&r2=758682&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 15:27:21 2009
@@ -33,6 +33,8 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -42,20 +44,34 @@
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.OoopsieRuntimeException;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.message.BasicHttpRequest;
-import org.apache.http.mockup.RequestCount;
 import org.apache.http.mockup.SimpleEventListener;
-import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 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.nio.reactor.IOReactorException;
 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.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpProcessor;
 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;
 
 /**
  * Tests for basic I/O functionality.
@@ -88,9 +104,9 @@
         // they get cleanly closed upon shutdown
         
         final int connNo = 10;
-        final RequestCount requestConns = new RequestCount(connNo); 
-        final RequestCount closedServerConns = new RequestCount(connNo); 
-        final RequestCount closedClientConns = new RequestCount(connNo); 
+        final CountDownLatch requestConns = new CountDownLatch(connNo); 
+        final CountDownLatch closedServerConns = new CountDownLatch(connNo); 
+        final CountDownLatch closedClientConns = new CountDownLatch(connNo); 
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
@@ -122,7 +138,7 @@
             }
             
             public void handleResponse(final HttpResponse response, final HttpContext context)
{
-                requestConns.decrement();                    
+                requestConns.countDown();                    
             }
             
         };
@@ -131,35 +147,58 @@
 
             @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedServerConns.decrement();
+                closedServerConns.countDown();
                 super.connectionClosed(conn);
             }
             
         };
         
-        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
-                requestHandler, 
-                null,
+        BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
+        serverHttpProc.addInterceptor(new ResponseDate());
+        serverHttpProc.addInterceptor(new ResponseServer());
+        serverHttpProc.addInterceptor(new ResponseContent());
+        serverHttpProc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                serverHttpProc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setEventListener(
                 serverEventListener);
-        
+
         EventListener clientEventListener = new SimpleEventListener() {
 
             @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedClientConns.decrement();
+                closedClientConns.countDown();
                 super.connectionClosed(conn);
             }
             
         };
         
-        NHttpClientHandler clientHandler = createHttpClientHandler(
+        BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
+        clientHttpProc.addInterceptor(new RequestContent());
+        clientHttpProc.addInterceptor(new RequestTargetHost());
+        clientHttpProc.addInterceptor(new RequestConnControl());
+        clientHttpProc.addInterceptor(new RequestUserAgent());
+        clientHttpProc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                clientHttpProc,
                 requestExecutionHandler,
-                clientEventListener);
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
 
+        clientHandler.setEventListener(
+                clientEventListener);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
         
-        
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
@@ -170,17 +209,17 @@
                     null);
         }
      
-        requestConns.await(10000);
-        assertEquals(0, requestConns.getValue());
+        requestConns.await(10000, TimeUnit.MILLISECONDS);
+        assertEquals(0, requestConns.getCount());
      
         this.client.shutdown();
         this.server.shutdown();
         
-        closedClientConns.await(10000);
-        assertEquals(0, closedClientConns.getValue());
+        closedClientConns.await();
+        assertEquals(0, closedClientConns.getCount());
      
-        closedServerConns.await(10000);
-        assertEquals(0, closedServerConns.getValue());
+        closedServerConns.await();
+        assertEquals(0, closedServerConns.getCount());
     }
     
     public void testRuntimeException() throws Exception {
@@ -220,15 +259,39 @@
             
         };
      
-        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
-                requestHandler, 
-                null,
+        BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
+        serverHttpProc.addInterceptor(new ResponseDate());
+        serverHttpProc.addInterceptor(new ResponseServer());
+        serverHttpProc.addInterceptor(new ResponseContent());
+        serverHttpProc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                serverHttpProc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setEventListener(
                 new SimpleEventListener());
-        
-        NHttpClientHandler clientHandler = createHttpClientHandler(
+
+        BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
+        clientHttpProc.addInterceptor(new RequestContent());
+        clientHttpProc.addInterceptor(new RequestTargetHost());
+        clientHttpProc.addInterceptor(new RequestConnControl());
+        clientHttpProc.addInterceptor(new RequestUserAgent());
+        clientHttpProc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                clientHttpProc,
                 requestExecutionHandler,
-                new SimpleEventListener());
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
 
+        clientHandler.setEventListener(
+                new SimpleEventListener());
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
         
@@ -261,8 +324,8 @@
 
     public void testUnhandledRuntimeException() throws Exception {
 
-        final RequestCount requestConns = new RequestCount(1); 
-        
+        final CountDownLatch requestConns = new CountDownLatch(1); 
+
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
             public void handle(
@@ -305,23 +368,43 @@
             }
 
             public boolean handle(final RuntimeException ex) {
-                requestConns.decrement();                    
+                requestConns.countDown();                    
                 return false;
             }
           
         };
         
-        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
-                requestHandler, 
-                null,
+        BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
+        serverHttpProc.addInterceptor(new ResponseDate());
+        serverHttpProc.addInterceptor(new ResponseServer());
+        serverHttpProc.addInterceptor(new ResponseContent());
+        serverHttpProc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                serverHttpProc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setEventListener(
                 new SimpleEventListener());
-        
-        NHttpClientHandler clientHandler = createHttpClientHandler(
+
+        BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
+        clientHttpProc.addInterceptor(new RequestContent());
+        clientHttpProc.addInterceptor(new RequestTargetHost());
+        clientHttpProc.addInterceptor(new RequestConnControl());
+        clientHttpProc.addInterceptor(new RequestUserAgent());
+        clientHttpProc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                clientHttpProc,
                 requestExecutionHandler,
-                new SimpleEventListener());
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
 
         this.server.setExceptionHandler(exceptionHandler);
-        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
         
@@ -333,8 +416,8 @@
                 new InetSocketAddress("localhost", serverAddress.getPort()), 
                 null);
      
-        requestConns.await(10000);
-        assertEquals(0, requestConns.getValue());
+        requestConns.await();
+        assertEquals(0, requestConns.getCount());
         
         this.server.join(20000);
         
@@ -357,7 +440,7 @@
 
     public void testHandledRuntimeException() throws Exception {
 
-        final RequestCount requestConns = new RequestCount(1); 
+        final CountDownLatch requestConns = new CountDownLatch(1); 
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
@@ -365,7 +448,7 @@
                     final HttpRequest request, 
                     final HttpResponse response, 
                     final HttpContext context) throws HttpException, IOException {
-                throw new IllegalStateException("Oppsie!!!");
+                throw new OoopsieRuntimeException();
             }
             
         };
@@ -401,20 +484,41 @@
             }
 
             public boolean handle(final RuntimeException ex) {
-                requestConns.decrement();                    
+                requestConns.countDown();                    
                 return true;
             }
           
         };
         
-        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
-                requestHandler, 
-                null,
+        BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
+        serverHttpProc.addInterceptor(new ResponseDate());
+        serverHttpProc.addInterceptor(new ResponseServer());
+        serverHttpProc.addInterceptor(new ResponseContent());
+        serverHttpProc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                serverHttpProc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setEventListener(
                 new SimpleEventListener());
-        
-        NHttpClientHandler clientHandler = createHttpClientHandler(
+
+        BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
+        clientHttpProc.addInterceptor(new RequestContent());
+        clientHttpProc.addInterceptor(new RequestTargetHost());
+        clientHttpProc.addInterceptor(new RequestConnControl());
+        clientHttpProc.addInterceptor(new RequestUserAgent());
+        clientHttpProc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                clientHttpProc,
                 requestExecutionHandler,
-                new SimpleEventListener());
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
 
         this.server.setExceptionHandler(exceptionHandler);
         
@@ -429,8 +533,8 @@
                 new InetSocketAddress("localhost", serverAddress.getPort()), 
                 null);
      
-        requestConns.await(10000);
-        assertEquals(0, requestConns.getValue());
+        requestConns.await();
+        assertEquals(0, requestConns.getCount());
         
         this.server.join(1000);
         

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java?rev=758682&r1=758681&r2=758682&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
Thu Mar 26 15:27:21 2009
@@ -32,6 +32,8 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -40,19 +42,29 @@
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.message.BasicHttpRequest;
-import org.apache.http.mockup.RequestCount;
 import org.apache.http.mockup.SimpleEventListener;
-import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 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.nio.reactor.ListenerEndpoint;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpProcessor;
 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;
 
 /**
  * Basic functionality tests for SSL I/O reactors.
@@ -77,27 +89,15 @@
         return new TestSuite(TestDefaultIOReactorsSSL.class);
     }
 
-    public void testRestartListeningIOReactor() throws Exception {
-        HttpParams params = new BasicHttpParams();
-        
-        DefaultListeningIOReactor ioReactor = new DefaultListeningIOReactor(1, params);
-        ioReactor.listen(new InetSocketAddress(9999));
-        ioReactor.shutdown();
-        
-        ioReactor = new DefaultListeningIOReactor(1, params);
-        ioReactor.listen(new InetSocketAddress(9999));
-        ioReactor.shutdown();         
-    }
-    
     public void testGracefulShutdown() throws Exception {
 
         // Open some connection and make sure 
         // they get cleanly closed upon shutdown
         
         final int connNo = 10;
-        final RequestCount requestConns = new RequestCount(connNo); 
-        final RequestCount closedServerConns = new RequestCount(connNo); 
-        final RequestCount closedClientConns = new RequestCount(connNo); 
+        final CountDownLatch requestConns = new CountDownLatch(connNo); 
+        final CountDownLatch closedServerConns = new CountDownLatch(connNo); 
+        final CountDownLatch closedClientConns = new CountDownLatch(connNo); 
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
@@ -129,7 +129,7 @@
             }
             
             public void handleResponse(final HttpResponse response, final HttpContext context)
{
-                requestConns.decrement();                    
+                requestConns.countDown();                    
             }
             
         };
@@ -138,31 +138,55 @@
 
             @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedServerConns.decrement();
+                closedServerConns.countDown();
                 super.connectionClosed(conn);
             }
             
         };
         
-        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
-                requestHandler, 
-                null,
+        BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
+        serverHttpProc.addInterceptor(new ResponseDate());
+        serverHttpProc.addInterceptor(new ResponseServer());
+        serverHttpProc.addInterceptor(new ResponseContent());
+        serverHttpProc.addInterceptor(new ResponseConnControl());
+
+        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                serverHttpProc,
+                new DefaultHttpResponseFactory(),
+                new DefaultConnectionReuseStrategy(),
+                this.server.getParams());
+
+        serviceHandler.setHandlerResolver(
+                new SimpleHttpRequestHandlerResolver(requestHandler));
+        serviceHandler.setEventListener(
                 serverEventListener);
-        
+
         EventListener clientEventListener = new SimpleEventListener() {
 
             @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedClientConns.decrement();
+                closedClientConns.countDown();
                 super.connectionClosed(conn);
             }
             
         };
         
-        NHttpClientHandler clientHandler = createHttpClientHandler(
+        BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
+        clientHttpProc.addInterceptor(new RequestContent());
+        clientHttpProc.addInterceptor(new RequestTargetHost());
+        clientHttpProc.addInterceptor(new RequestConnControl());
+        clientHttpProc.addInterceptor(new RequestUserAgent());
+        clientHttpProc.addInterceptor(new RequestExpectContinue());
+
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                clientHttpProc,
                 requestExecutionHandler,
-                clientEventListener);
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
 
+        clientHandler.setEventListener(
+                clientEventListener);
+        
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
         
@@ -176,17 +200,17 @@
                     null);
         }
      
-        requestConns.await(10000);
-        assertEquals(0, requestConns.getValue());
+        requestConns.await(10000, TimeUnit.MILLISECONDS);
+        assertEquals(0, requestConns.getCount());
      
         this.client.shutdown();
         this.server.shutdown();
         
-        closedClientConns.await(10000);
-        assertEquals(0, closedClientConns.getValue());
+        closedClientConns.await();
+        assertEquals(0, closedClientConns.getCount());
      
-        closedServerConns.await(10000);
-        assertEquals(0, closedServerConns.getValue());
+        closedServerConns.await();
+        assertEquals(0, closedServerConns.getCount());
     }
-    
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java?rev=758682&r1=758681&r2=758682&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
Thu Mar 26 15:27:21 2009
@@ -51,8 +51,6 @@
     
     private volatile IOReactorThread thread;
 
-    private volatile RequestCount requestCount;
-    
     public TestHttpClient(final HttpParams params) throws IOException {
         super();
         this.ioReactor = new DefaultConnectingIOReactor(2, params);
@@ -63,10 +61,6 @@
         return this.params;
     }
     
-    public void setRequestCount(final RequestCount requestCount) {
-        this.requestCount = requestCount;
-    }
-
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -135,9 +129,6 @@
                 execute(this.clientHandler);
             } catch (Exception ex) {
                 this.ex = ex;
-                if (requestCount != null) {
-                    requestCount.failure(ex);
-                }
             }
         }
         

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=758682&r1=758681&r2=758682&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 15:27:21 2009
@@ -58,8 +58,6 @@
     
     private volatile IOReactorThread thread;
 
-    private volatile RequestCount requestCount;
-    
     public TestHttpSSLClient(final HttpParams params) throws Exception {
         super();
         this.params = params;
@@ -89,10 +87,6 @@
         return this.ioReactor.getAuditLog();
     }
     
-    public void setRequestCount(final RequestCount requestCount) {
-        this.requestCount = requestCount;
-    }
-
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -156,9 +150,6 @@
                 execute(this.clientHandler);
             } catch (Exception ex) {
                 this.ex = ex;
-                if (requestCount != null) {
-                    requestCount.failure(ex);
-                }
             }
         }
         

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=758682&r1=758681&r2=758682&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 15:27:21 2009
@@ -64,8 +64,6 @@
     private volatile IOReactorThread thread;
     private ListenerEndpoint endpoint;
     
-    private volatile RequestCount requestCount;
-    
     public TestHttpSSLServer(final HttpParams params) throws Exception {
         super();
         this.params = params;
@@ -95,10 +93,6 @@
         return this.ioReactor.getAuditLog();
     }
     
-    public void setRequestCount(final RequestCount requestCount) {
-        this.requestCount = requestCount;
-    }
-
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -163,9 +157,6 @@
                 execute(this.serviceHandler);
             } catch (Exception ex) {
                 this.ex = ex;
-                if (requestCount != null) {
-                    requestCount.failure(ex);
-                }
             }
         }
         

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java?rev=758682&r1=758681&r2=758682&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
Thu Mar 26 15:27:21 2009
@@ -57,8 +57,6 @@
     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);
@@ -69,10 +67,6 @@
         return this.params;
     }
     
-    public void setRequestCount(final RequestCount requestCount) {
-        this.requestCount = requestCount;
-    }
-
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
@@ -146,9 +140,6 @@
                 execute(this.serviceHandler);
             } catch (Exception ex) {
                 this.ex = ex;
-                if (requestCount != null) {
-                    requestCount.failure(ex);
-                }
             }
         }
         



Mime
View raw message