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/05/05 22:01:56 UTC

svn commit: r1099944 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http: impl/nio/client/ localserver/ nio/client/methods/

Author: olegk
Date: Thu May  5 20:01:55 2011
New Revision: 1099944

URL: http://svn.apache.org/viewvc?rev=1099944&view=rev
Log:
Improved base class for local HTTP server based test cases

Added:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java   (with props)
Removed:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/ServerTestBase.java
Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java?rev=1099944&r1=1099943&r2=1099944&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java Thu May  5 20:01:55 2011
@@ -34,56 +34,21 @@ import java.util.concurrent.ExecutionExc
 import java.util.concurrent.Future;
 
 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.conn.PoolingClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
-import org.apache.http.localserver.ServerTestBase;
+import org.apache.http.localserver.AsyncHttpTestBase;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncClient;
-import org.apache.http.nio.conn.scheme.Scheme;
-import org.apache.http.nio.conn.scheme.SchemeRegistry;
 import org.apache.http.nio.entity.NByteArrayEntity;
-import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.params.BasicHttpParams;
 import org.apache.http.util.EntityUtils;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-public class TestHttpAsync extends ServerTestBase {
-
-    private HttpHost target;
-    private PoolingClientConnectionManager sessionManager;
-    private HttpAsyncClient httpclient;
-
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        this.localServer.registerDefaultHandlers();
-        int port = this.localServer.getServiceAddress().getPort();
-        this.target = new HttpHost("localhost", port);
-
-        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, new BasicHttpParams());
-        SchemeRegistry schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(new Scheme("http", 80, null));
-        this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
-        this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        this.httpclient.shutdown();
-        super.tearDown();
-    }
+public class TestHttpAsync extends AsyncHttpTestBase {
 
     @Test
     public void testSingleGet() throws Exception {
-        this.httpclient.start();
         HttpGet httpget = new HttpGet("/random/2048");
         Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, null);
         HttpResponse response = future.get();
@@ -97,8 +62,6 @@ public class TestHttpAsync extends Serve
         Random rnd = new Random(System.currentTimeMillis());
         rnd.nextBytes(b1);
 
-        this.httpclient.start();
-
         HttpPost httppost = new HttpPost("/echo/stuff");
         httppost.setEntity(new NByteArrayEntity(b1));
 
@@ -122,7 +85,6 @@ public class TestHttpAsync extends Serve
 
         this.sessionManager.setDefaultMaxPerHost(reqCount);
         this.sessionManager.setTotalMax(100);
-        this.httpclient.start();
 
         Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
 
@@ -154,7 +116,6 @@ public class TestHttpAsync extends Serve
 
         this.sessionManager.setDefaultMaxPerHost(1);
         this.sessionManager.setTotalMax(100);
-        this.httpclient.start();
 
         Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
 
@@ -178,8 +139,6 @@ public class TestHttpAsync extends Serve
 
     @Test
     public void testRequestFailure() throws Exception {
-        this.httpclient.start();
-
         HttpGet httpget = new HttpGet("/random/2048");
         BasicHttpAsyncRequestProducer requestProducer = new BasicHttpAsyncRequestProducer(this.target, httpget) ;
         BasicHttpAsyncResponseConsumer responseConsumer = new BasicHttpAsyncResponseConsumer() {

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java?rev=1099944&r1=1099943&r2=1099944&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java Thu May  5 20:01:55 2011
@@ -48,31 +48,20 @@ 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.conn.PoolingClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.localserver.AsyncHttpTestBase;
 import org.apache.http.localserver.LocalTestServer;
-import org.apache.http.localserver.ServerTestBase;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncClient;
 import org.apache.http.nio.conn.scheme.Scheme;
 import org.apache.http.nio.conn.scheme.SchemeRegistry;
 import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.params.BasicHttpParams;
 import org.apache.http.util.EntityUtils;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-public class TestHttpsAsync extends ServerTestBase {
-
-    private SSLContext serverSSLContext;
-    private SSLContext clientSSLContext;
-    private HttpHost target;
-    private PoolingClientConnectionManager sessionManager;
-    private HttpAsyncClient httpclient;
+public class TestHttpsAsync extends AsyncHttpTestBase {
 
     private KeyManagerFactory createKeyManagerFactory() throws NoSuchAlgorithmException {
         String algo = KeyManagerFactory.getDefaultAlgorithm();
@@ -92,10 +81,8 @@ public class TestHttpsAsync extends Serv
         }
     }
 
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-
+    @Override
+    protected LocalTestServer createServer() throws Exception {
         ClassLoader cl = getClass().getClassLoader();
         URL url = cl.getResource("test.keystore");
         KeyStore keystore  = KeyStore.getInstance("jks");
@@ -110,35 +97,45 @@ public class TestHttpsAsync extends Serv
         kmfactory.init(keystore, pwd);
         KeyManager[] km = kmfactory.getKeyManagers();
 
-        this.serverSSLContext = SSLContext.getInstance("TLS");
-        this.serverSSLContext.init(km, tm, null);
+        SSLContext serverSSLContext = SSLContext.getInstance("TLS");
+        serverSSLContext.init(km, tm, null);
 
-        this.clientSSLContext = SSLContext.getInstance("TLS");
-        this.clientSSLContext.init(null, tm, null);
+        LocalTestServer localServer = new LocalTestServer(serverSSLContext);
+        localServer.registerDefaultHandlers();
+        return localServer;
+    }
 
-        this.localServer = new LocalTestServer(this.serverSSLContext);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
-        int port = this.localServer.getServiceAddress().getPort();
-        this.target = new HttpHost("localhost", port, "https");
+    @Override
+    protected PoolingClientConnectionManager createConnectionManager(
+            final ConnectingIOReactor ioreactor) throws Exception {
+        ClassLoader cl = getClass().getClassLoader();
+        URL url = cl.getResource("test.keystore");
+        KeyStore keystore  = KeyStore.getInstance("jks");
+        char[] pwd = "nopassword".toCharArray();
+        keystore.load(url.openStream(), pwd);
+
+        TrustManagerFactory tmf = createTrustManagerFactory();
+        tmf.init(keystore);
+        TrustManager[] tm = tmf.getTrustManagers();
+
+        SSLContext clientSSLContext = SSLContext.getInstance("TLS");
+        clientSSLContext.init(null, tm, null);
 
-        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, new BasicHttpParams());
         SchemeRegistry schemeRegistry = new SchemeRegistry();
         schemeRegistry.register(new Scheme("http", 80, null));
-        schemeRegistry.register(new Scheme("https", 443, new SSLLayeringStrategy(this.clientSSLContext)));
-        this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
-        this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
+        schemeRegistry.register(new Scheme("https", 443, new SSLLayeringStrategy(clientSSLContext)));
+        return new PoolingClientConnectionManager(ioreactor, schemeRegistry);
     }
 
-    @After
-    public void tearDown() throws Exception {
-        this.httpclient.shutdown();
-        super.tearDown();
+    @Override
+    public void startServer() throws Exception {
+        super.startServer();
+        int port = this.localServer.getServiceAddress().getPort();
+        this.target = new HttpHost("localhost", port, "https");
     }
 
     @Test
     public void testSingleGet() throws Exception {
-        this.httpclient.start();
         HttpGet httpget = new HttpGet("/random/2048");
         Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, null);
         HttpResponse response = future.get();
@@ -152,8 +149,6 @@ public class TestHttpsAsync extends Serv
         Random rnd = new Random(System.currentTimeMillis());
         rnd.nextBytes(b1);
 
-        this.httpclient.start();
-
         HttpPost httppost = new HttpPost("/echo/stuff");
         httppost.setEntity(new NByteArrayEntity(b1));
 
@@ -177,7 +172,6 @@ public class TestHttpsAsync extends Serv
 
         this.sessionManager.setDefaultMaxPerHost(reqCount);
         this.sessionManager.setTotalMax(100);
-        this.httpclient.start();
 
         Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
 
@@ -209,7 +203,6 @@ public class TestHttpsAsync extends Serv
 
         this.sessionManager.setDefaultMaxPerHost(1);
         this.sessionManager.setTotalMax(100);
-        this.httpclient.start();
 
         Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
 
@@ -233,8 +226,6 @@ public class TestHttpsAsync extends Serv
 
     @Test
     public void testRequestFailure() throws Exception {
-        this.httpclient.start();
-
         HttpGet httpget = new HttpGet("/random/2048");
         BasicHttpAsyncRequestProducer requestProducer = new BasicHttpAsyncRequestProducer(this.target, httpget) ;
         BasicHttpAsyncResponseConsumer responseConsumer = new BasicHttpAsyncResponseConsumer() {

Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java?rev=1099944&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java (added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java Thu May  5 20:01:55 2011
@@ -0,0 +1,119 @@
+/*
+ * ====================================================================
+ * 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.util.List;
+
+import org.apache.http.HttpHost;
+import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
+import org.apache.http.impl.nio.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.impl.nio.reactor.ExceptionEvent;
+import org.apache.http.nio.conn.ClientConnectionManager;
+import org.apache.http.nio.conn.scheme.Scheme;
+import org.apache.http.nio.conn.scheme.SchemeRegistry;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOReactorStatus;
+import org.apache.http.params.BasicHttpParams;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class AsyncHttpTestBase {
+
+    protected LocalTestServer localServer;
+    protected HttpHost target;
+    protected DefaultConnectingIOReactor ioreactor;
+    protected PoolingClientConnectionManager sessionManager;
+    protected DefaultHttpAsyncClient httpclient;
+
+    protected LocalTestServer createServer() throws Exception {
+        LocalTestServer localServer = new LocalTestServer(null, null);
+        localServer.registerDefaultHandlers();
+        return localServer;
+    }
+
+    protected DefaultConnectingIOReactor createIOReactor() throws Exception {
+        return new DefaultConnectingIOReactor(2, new BasicHttpParams());
+    }
+
+    protected PoolingClientConnectionManager createConnectionManager(
+            final ConnectingIOReactor ioreactor) throws Exception {
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(new Scheme("http", 80, null));
+        return new PoolingClientConnectionManager(ioreactor, schemeRegistry);
+    }
+
+    protected DefaultHttpAsyncClient createClient(
+            final ClientConnectionManager sessionManager) throws Exception {
+        return new DefaultHttpAsyncClient(sessionManager);
+    }
+
+    @Before
+    public void startServer() throws Exception {
+        this.localServer = createServer();
+        this.localServer.start();
+        int port = this.localServer.getServiceAddress().getPort();
+        this.target = new HttpHost("localhost", port);
+    }
+
+    @Before
+    public void startClient() throws Exception {
+        this.ioreactor = createIOReactor();
+        this.sessionManager = createConnectionManager(this.ioreactor);
+        this.httpclient = createClient(this.sessionManager);
+        this.httpclient.start();
+    }
+
+    @After
+    public void stopServer() throws Exception {
+        if (this.localServer != null) {
+            this.localServer.stop();
+            this.localServer = null;
+        }
+    }
+
+    @After
+    public void stopClient() throws Exception {
+        if (this.httpclient != null) {
+            this.httpclient.shutdown();
+            if (this.ioreactor.getStatus() != IOReactorStatus.SHUT_DOWN) {
+                System.err.println("I/O reactor failed to shut down cleanly");
+            } else {
+                List<ExceptionEvent> exs = this.ioreactor.getAuditLog();
+                if (exs != null && !exs.isEmpty()) {
+                    System.err.println("I/O reactor terminated abnormally");
+                    for (ExceptionEvent ex: exs) {
+                        System.err.println("-------------------------");
+                        ex.getCause().printStackTrace();
+                    }
+                }
+            }
+            this.httpclient = null;
+        }
+    }
+
+}

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AsyncHttpTestBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java?rev=1099944&r1=1099943&r2=1099944&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java Thu May  5 20:01:55 2011
@@ -34,50 +34,15 @@ import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
-import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
-import org.apache.http.impl.nio.conn.PoolingClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
-import org.apache.http.localserver.ServerTestBase;
+import org.apache.http.localserver.AsyncHttpTestBase;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncClient;
-import org.apache.http.nio.conn.scheme.Scheme;
-import org.apache.http.nio.conn.scheme.SchemeRegistry;
-import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.params.BasicHttpParams;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class TestAsyncConsumers extends ServerTestBase {
-
-    private HttpHost target;
-    private PoolingClientConnectionManager sessionManager;
-    private HttpAsyncClient httpclient;
-
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        this.localServer.registerDefaultHandlers();
-        int port = this.localServer.getServiceAddress().getPort();
-        this.target = new HttpHost("localhost", port);
-
-        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, new BasicHttpParams());
-        SchemeRegistry schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(new Scheme("http", 80, null));
-        this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
-        this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        this.httpclient.shutdown();
-        super.tearDown();
-    }
+public class TestAsyncConsumers extends AsyncHttpTestBase {
 
     static class ByteCountingConsumer extends AsyncByteConsumer<Long> {
 
@@ -113,7 +78,6 @@ public class TestAsyncConsumers extends 
 
     @Test
     public void testByteConsumer() throws Exception {
-        this.httpclient.start();
         for (int i = 0; i < 5; i++) {
             HttpAsyncGet httpget = new HttpAsyncGet(this.target.toURI() + "/random/20480");
             AsyncByteConsumer<Long> consumer = new ByteCountingConsumer();
@@ -125,7 +89,6 @@ public class TestAsyncConsumers extends 
 
     @Test
     public void testByteConsumerSmallBufffer() throws Exception {
-        this.httpclient.start();
         for (int i = 0; i < 5; i++) {
             HttpAsyncGet httpget = new HttpAsyncGet(this.target.toURI() + "/random/20480");
             AsyncByteConsumer<Long> consumer = new ByteCountingConsumer(512);
@@ -179,7 +142,6 @@ public class TestAsyncConsumers extends 
         }
         String s = sb.toString();
 
-        this.httpclient.start();
         for (int i = 0; i < 5; i++) {
             HttpAsyncPost httppost = new HttpAsyncPost(this.target.toURI() + "/echo/stuff", s);
             AsyncCharConsumer<String> consumer = new BufferingCharConsumer();
@@ -198,7 +160,6 @@ public class TestAsyncConsumers extends 
         }
         String s = sb.toString();
 
-        this.httpclient.start();
         for (int i = 0; i < 5; i++) {
             HttpAsyncPost httppost = new HttpAsyncPost(this.target.toURI() + "/echo/stuff", s);
             AsyncCharConsumer<String> consumer = new BufferingCharConsumer(512);
@@ -217,7 +178,6 @@ public class TestAsyncConsumers extends 
         }
         String s = sb.toString();
 
-        this.httpclient.start();
         HttpAsyncPost httppost = new HttpAsyncPost(this.target.toURI() + "/echo/stuff", s);
         AsyncCharConsumer<String> consumer = Mockito.spy(new BufferingCharConsumer());
         Future<String> future = this.httpclient.execute(httppost, consumer, null);
@@ -231,8 +191,6 @@ public class TestAsyncConsumers extends 
 
     @Test
     public void testResourceReleaseOnException() throws Exception {
-        this.httpclient.start();
-
         HttpAsyncPost httppost = new HttpAsyncPost(this.target.toURI() + "/echo/stuff", "stuff");
         AsyncCharConsumer<String> consumer = Mockito.spy(new BufferingCharConsumer());
         Mockito.doThrow(new IOException("Kaboom")).when(consumer).consumeContent(
@@ -255,8 +213,6 @@ public class TestAsyncConsumers extends 
 
     @Test
     public void testResourceReleaseOnBuildFailure() throws Exception {
-        this.httpclient.start();
-
         HttpAsyncPost httppost = new HttpAsyncPost(this.target.toURI() + "/echo/stuff", "stuff");
         AsyncCharConsumer<String> consumer = Mockito.spy(new BufferingCharConsumer());
         Mockito.doThrow(new HttpException("Kaboom")).when(consumer).buildResult();

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java?rev=1099944&r1=1099943&r2=1099944&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java Thu May  5 20:01:55 2011
@@ -41,7 +41,6 @@ import org.apache.commons.io.output.File
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -49,26 +48,17 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.FileEntity;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
-import org.apache.http.impl.nio.conn.PoolingClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
-import org.apache.http.localserver.ServerTestBase;
-import org.apache.http.nio.client.HttpAsyncClient;
-import org.apache.http.nio.conn.scheme.Scheme;
-import org.apache.http.nio.conn.scheme.SchemeRegistry;
-import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.params.BasicHttpParams;
+import org.apache.http.localserver.AsyncHttpTestBase;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class TestZeroCopy extends ServerTestBase {
+public class TestZeroCopy extends AsyncHttpTestBase {
 
     private static final String[] TEXT = {
         "blah blah blah blah blah blah blah blah blah blah blah blah blah blah",
@@ -81,10 +71,6 @@ public class TestZeroCopy extends Server
     private static File TEST_FILE;
     private File tmpfile;
 
-    private HttpHost target;
-    private PoolingClientConnectionManager sessionManager;
-    private HttpAsyncClient httpclient;
-
     @BeforeClass
     public static void createSrcFile() throws Exception {
         File tmpdir = FileUtils.getTempDirectory();
@@ -110,25 +96,6 @@ public class TestZeroCopy extends Server
         }
     }
 
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        int port = this.localServer.getServiceAddress().getPort();
-        this.target = new HttpHost("localhost", port);
-
-        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, new BasicHttpParams());
-        SchemeRegistry schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(new Scheme("http", 80, null));
-        this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
-        this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        this.httpclient.shutdown();
-        super.tearDown();
-    }
-
     @After
     public void cleanUp() throws Exception {
         if (this.tmpfile != null && this.tmpfile.exists()) {
@@ -232,7 +199,6 @@ public class TestZeroCopy extends Server
         this.localServer.register("/bounce", new TestHandler(false));
         File tmpdir = FileUtils.getTempDirectory();
         this.tmpfile = new File(tmpdir, "dst.test");
-        this.httpclient.start();
         TestZeroCopyPost httppost = new TestZeroCopyPost(this.target.toURI() + "/bounce", false);
         TestZeroCopyConsumer consumer = new TestZeroCopyConsumer(this.tmpfile);
         Future<Integer> future = this.httpclient.execute(httppost, consumer, null);
@@ -260,7 +226,6 @@ public class TestZeroCopy extends Server
         this.localServer.register("/bounce", new TestHandler(true));
         File tmpdir = FileUtils.getTempDirectory();
         this.tmpfile = new File(tmpdir, "dst.test");
-        this.httpclient.start();
         TestZeroCopyPost httppost = new TestZeroCopyPost(this.target.toURI() + "/bounce", true);
         TestZeroCopyConsumer consumer = new TestZeroCopyConsumer(this.tmpfile);
         Future<Integer> future = this.httpclient.execute(httppost, consumer, null);