You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/09/03 20:06:39 UTC

svn commit: r1164902 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/impl/nio/pool/ test/java/org/apache/http/ test/java/org/apache/http/impl/nio/reactor/ test/java/org/apache/http/nio/protocol/ test/java/org/apache/http...

Author: olegk
Date: Sat Sep  3 18:06:38 2011
New Revision: 1164902

URL: http://svn.apache.org/viewvc?rev=1164902&view=rev
Log:
Simplified setup of NIO test cases

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.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/TestBaseIOReactorSSL.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/nio/protocol/TestAsyncNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java Sat Sep  3 18:06:38 2011
@@ -73,14 +73,16 @@ public class BasicNIOConnFactory impleme
         if (plainFactory == null) {
             throw new IllegalArgumentException("Plain HTTP client connection factory may not be null");
         }
-        if (sslFactory == null) {
-            throw new IllegalArgumentException("SSL HTTP client connection factory may not be null");
-        }
         this.plainFactory = plainFactory;
         this.sslFactory = sslFactory;
     }
 
     public BasicNIOConnFactory(
+            final NHttpConnectionFactory<? extends NHttpClientConnection> plainFactory) {
+        this(plainFactory, null);
+    }
+
+    public BasicNIOConnFactory(
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpResponseFactory responseFactory,
@@ -107,6 +109,9 @@ public class BasicNIOConnFactory impleme
     public NHttpClientConnection create(final HttpHost route, final IOSession session) throws IOException {
         NHttpClientConnection conn;
         if (route.getSchemeName().equalsIgnoreCase("https")) {
+            if (this.sslFactory == null) {
+                throw new IOException("SSL not supported");
+            }
             conn = this.sslFactory.createConnection(session);
         } else {
             conn = this.plainFactory.createConnection(session);

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=1164902&r1=1164901&r2=1164902&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 Sat Sep  3 18:06:38 2011
@@ -27,6 +27,8 @@
 
 package org.apache.http;
 
+import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
+import org.apache.http.impl.nio.pool.BasicNIOConnPool;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerIOTarget;
@@ -47,6 +49,7 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseServer;
 import org.apache.http.testserver.HttpClientNio;
 import org.apache.http.testserver.HttpServerNio;
+import org.junit.After;
 
 /**
  * Base class for all HttpCore NIO tests
@@ -60,6 +63,7 @@ public abstract class HttpCoreNIOTestBas
     protected HttpClientNio client;
     protected HttpProcessor serverHttpProc;
     protected HttpProcessor clientHttpProc;
+    protected BasicNIOConnPool connpool;
 
     protected abstract NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
             HttpParams params) throws Exception;
@@ -105,15 +109,34 @@ public abstract class HttpCoreNIOTestBas
                 new RequestExpectContinue()});
     }
 
+    public void initConnPool() throws Exception {
+        this.connpool = new BasicNIOConnPool(
+                this.client.getIoReactor(),
+                new BasicNIOConnFactory(createClientConnectionFactory(this.clientParams)),
+                this.clientParams);
+    }
+
+    @After
+    public void shutDownConnPool() throws Exception {
+        if (this.connpool != null) {
+            this.connpool.shutdown(2000);
+            this.connpool = null;
+        }
+    }
+
+    @After
     public void shutDownClient() throws Exception {
         if (this.client != null) {
             this.client.shutdown();
+            this.client = null;
         }
     }
 
+    @After
     public void shutDownServer() throws Exception {
         if (this.server != null) {
             this.server.shutdown();
+            this.server = null;
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java Sat Sep  3 18:06:38 2011
@@ -68,15 +68,13 @@ import org.junit.Test;
 public class TestBaseIOReactorSSL extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
+    public void setUp() throws Exception {
+        initServer();
     }
 
     @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownServer();
     }
 
     @Override

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=1164902&r1=1164901&r2=1164902&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 Sat Sep  3 18:06:38 2011
@@ -87,27 +87,15 @@ import org.junit.Test;
 public class TestDefaultIOReactors extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

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=1164902&r1=1164901&r2=1164902&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 Sat Sep  3 18:06:38 2011
@@ -85,27 +85,15 @@ import org.junit.Test;
 public class TestDefaultIOReactorsSSL extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java Sat Sep  3 18:06:38 2011
@@ -87,27 +87,15 @@ import org.junit.Test;
 public class TestAsyncNHttpHandlers extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java Sat Sep  3 18:06:38 2011
@@ -68,27 +68,15 @@ import org.junit.Test;
 public class TestBufferingNHttpHandlers extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java Sat Sep  3 18:06:38 2011
@@ -64,27 +64,17 @@ import org.junit.Test;
 public class TestHttpAsyncHandlers extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
+        initConnPool();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownConnPool();
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java Sat Sep  3 18:06:38 2011
@@ -67,27 +67,15 @@ import org.junit.Test;
 public class TestNIOSSLHttp extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java Sat Sep  3 18:06:38 2011
@@ -97,27 +97,15 @@ import org.junit.Test;
 public class TestThrottlingNHttpHandlers extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java Sat Sep  3 18:06:38 2011
@@ -85,27 +85,15 @@ import org.junit.Test;
 public class TestTruncatedChunks extends HttpCoreNIOTestBase {
 
     @Before
-    @Override
-    public void initServer() throws Exception {
-        super.initServer();
-    }
-
-    @Before
-    @Override
-    public void initClient() throws Exception {
-        super.initClient();
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
     }
 
     @After
-    @Override
-    public void shutDownClient() throws Exception {
-        super.shutDownClient();
-    }
-
-    @After
-    @Override
-    public void shutDownServer() throws Exception {
-        super.shutDownServer();
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java Sat Sep  3 18:06:38 2011
@@ -37,11 +37,11 @@ import org.apache.http.impl.nio.reactor.
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.SessionRequest;
-import org.apache.http.params.HttpParams;
 
 public class HttpClientNio {
 
@@ -61,11 +61,6 @@ public class HttpClientNio {
         this.ioReactor.setExceptionHandler(exceptionHandler);
     }
 
-    protected IOEventDispatch createIOEventDispatch(
-            final NHttpClientHandler clientHandler, final HttpParams params) {
-        return new DefaultClientIODispatch(clientHandler, params);
-    }
-
     private void execute(final NHttpClientHandler clientHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new DefaultClientIODispatch(clientHandler, this.connFactory);
         this.ioReactor.execute(ioEventDispatch);
@@ -80,6 +75,10 @@ public class HttpClientNio {
         this.thread.start();
     }
 
+    public ConnectingIOReactor getIoReactor() {
+        return this.ioReactor;
+    }
+
     public IOReactorStatus getStatus() {
         return this.ioReactor.getStatus();
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java?rev=1164902&r1=1164901&r2=1164902&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java Sat Sep  3 18:06:38 2011
@@ -41,6 +41,7 @@ import org.apache.http.nio.reactor.IOEve
 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.nio.reactor.ListeningIOReactor;
 
 /**
  * Trivial test server based on HttpCore NIO
@@ -84,6 +85,10 @@ public class HttpServerNio {
         this.thread.start();
     }
 
+    public ListeningIOReactor getIoReactor() {
+        return this.ioReactor;
+    }
+
     public IOReactorStatus getStatus() {
         return this.ioReactor.getStatus();
     }