Fixed minimal async client integration tests

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1630968 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
index 7671604..e44ea16 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
@@ -40,6 +40,7 @@
 import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
 import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
 import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpProcessorBuilder;
@@ -144,16 +145,18 @@
         final HttpProcessor httpprocessor = b.build();
 
         ThreadFactory threadFactory = null;
+        NHttpClientEventHandler eventHandler = null;
         if (!this.connManagerShared) {
             threadFactory = this.threadFactory;
             if (threadFactory == null) {
                 threadFactory = Executors.defaultThreadFactory();
             }
+            eventHandler = new LoggingAsyncRequestExecutor();
         }
         return new MinimalHttpAsyncClient(
             connManager,
             threadFactory,
-            new LoggingAsyncRequestExecutor(),
+            eventHandler,
             httpprocessor,
             reuseStrategy,
             keepAliveStrategy);
diff --git a/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java b/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
new file mode 100644
index 0000000..0d4aa0a
--- /dev/null
+++ b/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
@@ -0,0 +1,112 @@
+/*
+ * ====================================================================
+ * 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.localserver;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.ExceptionLogger;
+import org.apache.http.HttpHost;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.impl.nio.bootstrap.HttpServer;
+import org.apache.http.impl.nio.bootstrap.ServerBootstrap;
+import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
+import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.conn.NoopIOSessionStrategy;
+import org.apache.http.nio.conn.SchemeIOSessionStrategy;
+import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
+import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class AbstractAsyncTest {
+
+    public enum ProtocolScheme { http, https };
+
+    protected final ProtocolScheme scheme;
+
+    protected ServerBootstrap serverBootstrap;
+    protected HttpServer server;
+    protected PoolingNHttpClientConnectionManager connMgr;
+
+    public AbstractAsyncTest(final ProtocolScheme scheme) {
+        this.scheme = scheme;
+    }
+
+    public AbstractAsyncTest() {
+        this(ProtocolScheme.http);
+    }
+
+    public String getSchemeName() {
+        return this.scheme.name();
+    }
+
+    public HttpHost startServer() throws Exception {
+        this.server = this.serverBootstrap.create();
+        this.server.start();
+
+        final ListenerEndpoint endpoint = this.server.getEndpoint();
+        endpoint.waitFor();
+
+        final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
+        return new HttpHost("localhost", address.getPort(), this.scheme.name());
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        this.serverBootstrap = ServerBootstrap.bootstrap();
+        final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
+                .setSoTimeout(15000)
+                .build();
+        this.serverBootstrap.setServerInfo("TEST/1.1");
+        this.serverBootstrap.setIOReactorConfig(ioReactorConfig);
+        this.serverBootstrap.setExceptionLogger(ExceptionLogger.STD_ERR);
+        if (this.scheme.equals(ProtocolScheme.https)) {
+            this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
+        }
+
+        final RegistryBuilder<SchemeIOSessionStrategy> builder = RegistryBuilder.create();
+        builder.register("http", NoopIOSessionStrategy.INSTANCE);
+        if (this.scheme.equals(ProtocolScheme.https)) {
+            builder.register("https", new SSLIOSessionStrategy(SSLTestContexts.createClientSSLContext()));
+        }
+        final Registry<SchemeIOSessionStrategy> registry =  builder.build();
+        final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
+        this.connMgr = new PoolingNHttpClientConnectionManager(ioReactor, registry);
+    }
+
+    @After
+    public void shutDown() throws Exception {
+        if (this.server != null) {
+            this.server.shutdown(10, TimeUnit.SECONDS);
+        }
+    }
+
+}
diff --git a/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java b/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
index 93293f6..dd05d98 100644
--- a/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
+++ b/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
@@ -27,98 +27,47 @@
 
 package org.apache.http.localserver;
 
-import java.net.InetSocketAddress;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.http.ExceptionLogger;
 import org.apache.http.HttpHost;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.impl.nio.bootstrap.HttpServer;
-import org.apache.http.impl.nio.bootstrap.ServerBootstrap;
 import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
 import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
-import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
-import org.apache.http.impl.nio.reactor.IOReactorConfig;
-import org.apache.http.nio.conn.NoopIOSessionStrategy;
-import org.apache.http.nio.conn.SchemeIOSessionStrategy;
-import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
-import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.junit.After;
 import org.junit.Before;
 
-public abstract class HttpAsyncTestBase {
+public abstract class HttpAsyncTestBase extends AbstractAsyncTest{
 
-    public enum ProtocolScheme { http, https };
-
-    protected final ProtocolScheme scheme;
-
-    protected ServerBootstrap serverBootstrap;
-    protected HttpServer server;
     protected HttpAsyncClientBuilder clientBuilder;
-    protected PoolingNHttpClientConnectionManager connMgr;
     protected CloseableHttpAsyncClient httpclient;
 
-    public HttpAsyncTestBase(final ProtocolScheme scheme) {
-        this.scheme = scheme;
-    }
-
     public HttpAsyncTestBase() {
-        this(ProtocolScheme.http);
+        super();
     }
 
-    public String getSchemeName() {
-        return this.scheme.name();
+    public HttpAsyncTestBase(final ProtocolScheme scheme) {
+        super(scheme);
     }
 
     public HttpHost start() throws Exception {
-        this.server = this.serverBootstrap.create();
-        this.server.start();
+        final HttpHost serverEndpoint = startServer();
 
         this.httpclient = this.clientBuilder.build();
         this.httpclient.start();
 
-        final ListenerEndpoint endpoint = this.server.getEndpoint();
-        endpoint.waitFor();
-
-        final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
-        return new HttpHost("localhost", address.getPort(), this.scheme.name());
+        return serverEndpoint;
     }
 
-    @Before
+    @Before @Override
     public void setUp() throws Exception {
-        this.serverBootstrap = ServerBootstrap.bootstrap();
-        final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
-                .setSoTimeout(15000)
-                .build();
-        this.serverBootstrap.setServerInfo("TEST/1.1");
-        this.serverBootstrap.setIOReactorConfig(ioReactorConfig);
-        this.serverBootstrap.setExceptionLogger(ExceptionLogger.STD_ERR);
-        if (this.scheme.equals(ProtocolScheme.https)) {
-            this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
-        }
-
+        super.setUp();
         this.clientBuilder = HttpAsyncClientBuilder.create();
-        final RegistryBuilder<SchemeIOSessionStrategy> builder = RegistryBuilder.create();
-        builder.register("http", NoopIOSessionStrategy.INSTANCE);
-        if (this.scheme.equals(ProtocolScheme.https)) {
-            builder.register("https", new SSLIOSessionStrategy(SSLTestContexts.createClientSSLContext()));
-        }
-        final Registry<SchemeIOSessionStrategy> registry =  builder.build();
-        final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
-        this.connMgr = new PoolingNHttpClientConnectionManager(ioReactor, registry);
         this.clientBuilder.setConnectionManager(this.connMgr);
     }
 
-    @After
+    @After  @Override
     public void shutDown() throws Exception {
         if (this.httpclient != null) {
             this.httpclient.close();
         }
-        if (this.server != null) {
-            this.server.shutdown(10, TimeUnit.SECONDS);
-        }
+        super.shutDown();
     }
 
 }
diff --git a/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java b/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
index 475dcc4..3993d10 100644
--- a/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
+++ b/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
@@ -33,17 +33,20 @@
 import java.util.Random;
 import java.util.concurrent.Future;
 
-import org.apache.http.localserver.HttpAsyncTestBase;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.apache.http.localserver.AbstractAsyncTest;
 import org.apache.http.localserver.EchoHandler;
 import org.apache.http.localserver.RandomHandler;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
 import org.apache.http.util.EntityUtils;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -51,7 +54,7 @@
 import org.junit.runners.Parameterized;
 
 @RunWith(Parameterized.class)
-public class TestHttpAsyncMinimal extends HttpAsyncTestBase {
+public class TestHttpAsyncMinimal extends AbstractAsyncTest {
 
     @Parameterized.Parameters(name = "{0}")
     public static Collection<Object[]> protocols() {
@@ -61,6 +64,8 @@
         });
     }
 
+    protected CloseableHttpAsyncClient httpclient;
+
     public TestHttpAsyncMinimal(final ProtocolScheme scheme) {
         super(scheme);
     }
@@ -70,6 +75,24 @@
         super.setUp();
         this.serverBootstrap.registerHandler("/echo/*", new BasicAsyncRequestHandler(new EchoHandler()));
         this.serverBootstrap.registerHandler("/random/*", new BasicAsyncRequestHandler(new RandomHandler()));
+
+        this.httpclient = HttpAsyncClients.createMinimal(this.connMgr);
+    }
+
+    @After @Override
+    public void shutDown() throws Exception {
+        if (this.httpclient != null) {
+            this.httpclient.close();
+        }
+        super.shutDown();
+    }
+
+    public HttpHost start() throws Exception {
+        final HttpHost serverEndpoint = startServer();
+
+        this.httpclient.start();
+
+        return serverEndpoint;
     }
 
     @Test