hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1165245 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/nio/protocol/
Date Mon, 05 Sep 2011 11:42:26 GMT
Author: olegk
Date: Mon Sep  5 11:42:25 2011
New Revision: 1165245

URL: http://svn.apache.org/viewvc?rev=1165245&view=rev
Log:
Fixed several bugs in HttpAsyncRequestExecutor; added test cases for the most fundamental
functionality

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
  (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RequestHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java?rev=1165245&r1=1165244&r2=1165245&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
Mon Sep  5 11:42:25 2011
@@ -401,7 +401,7 @@ public class HttpAsyncClientProtocolHand
         }
 
         public void setResponse(final HttpResponse response) {
-            if (this.request != null) {
+            if (this.response != null) {
                 throw new IllegalStateException("Response already set");
             }
             this.response = response;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1165245&r1=1165244&r2=1165245&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Mon Sep  5 11:42:25 2011
@@ -117,7 +117,7 @@ public class HttpAsyncRequestExecutor {
             final HttpAsyncResponseConsumer<T> responseConsumer,
             final ConnPool<HttpHost, E> connPool,
             final HttpContext context) {
-        return execute(requestProducer, responseConsumer, connPool, context);
+        return execute(requestProducer, responseConsumer, connPool, context, null);
     }
 
     public <T, E extends PoolEntry<HttpHost, NHttpClientConnection>> Future<T>
execute(
@@ -129,20 +129,20 @@ public class HttpAsyncRequestExecutor {
 
     class ConnRequestCallback<T, E extends PoolEntry<HttpHost, NHttpClientConnection>>
implements FutureCallback<E> {
 
-        private final BasicFuture<T> future;
+        private final BasicFuture<T> requestFuture;
         private final HttpAsyncRequestProducer requestProducer;
         private final HttpAsyncResponseConsumer<T> responseConsumer;
         private final ConnPool<HttpHost, E> connPool;
         private final HttpContext context;
 
         ConnRequestCallback(
-                final BasicFuture<T> future,
+                final BasicFuture<T> requestFuture,
                 final HttpAsyncRequestProducer requestProducer,
                 final HttpAsyncResponseConsumer<T> responseConsumer,
                 final ConnPool<HttpHost, E> connPool,
                 final HttpContext context) {
             super();
-            this.future = future;
+            this.requestFuture = requestFuture;
             this.requestProducer = requestProducer;
             this.responseConsumer = responseConsumer;
             this.connPool = connPool;
@@ -150,13 +150,15 @@ public class HttpAsyncRequestExecutor {
         }
 
         public void completed(final E result) {
-            if (this.future.isDone()) {
+            if (this.requestFuture.isDone()) {
                 this.connPool.release(result, true);
                 return;
             }
             NHttpClientConnection conn = result.getConnection();
+            BasicFuture<T> execFuture = new BasicFuture<T>(new RequestExecutionCallback<T,
E>(
+                    this.requestFuture, result, this.connPool));
             HttpAsyncClientExchangeHandler<T> handler = new HttpAsyncClientExchangeHandlerImpl<T>(
-                    this.future, this.requestProducer, this.responseConsumer, this.context,
+                    execFuture, this.requestProducer, this.responseConsumer, this.context,
                     httppocessor, conn, reuseStrategy, params);
             conn.getContext().setAttribute(HttpAsyncClientProtocolHandler.HTTP_HANDLER, handler);
             conn.requestOutput();
@@ -170,7 +172,7 @@ public class HttpAsyncRequestExecutor {
                     releaseResources();
                 }
             } finally {
-                this.future.failed(ex);
+                this.requestFuture.failed(ex);
             }
         }
 
@@ -182,7 +184,7 @@ public class HttpAsyncRequestExecutor {
                     releaseResources();
                 }
             } finally {
-                this.future.cancel(true);
+                this.requestFuture.cancel(true);
             }
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RequestHandler.java?rev=1165245&r1=1165244&r2=1165245&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RequestHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RequestHandler.java
Mon Sep  5 11:42:25 2011
@@ -35,6 +35,7 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
+import org.apache.http.entity.ContentType;
 import org.apache.http.nio.entity.BufferingNHttpEntity;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
 import org.apache.http.nio.entity.NStringEntity;
@@ -59,9 +60,7 @@ final class RequestHandler extends Simpl
     public ConsumingNHttpEntity entityRequest(
             final HttpEntityEnclosingRequest request,
             final HttpContext context) {
-        return new BufferingNHttpEntity(
-                request.getEntity(),
-                new HeapByteBufferAllocator());
+        return new BufferingNHttpEntity(request.getEntity(), new HeapByteBufferAllocator());
     }
 
     @Override
@@ -94,7 +93,7 @@ final class RequestHandler extends Simpl
             }
             content = buffer.toString();
         }
-        NStringEntity entity = new NStringEntity(content, "US-ASCII");
+        NStringEntity entity = NStringEntity.create(content, ContentType.DEFAULT_TEXT);
         entity.setChunked(this.chunking);
         response.setEntity(entity);
     }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java?rev=1165245&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
Mon Sep  5 11:42:25 2011
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.util.Random;
+
+final class RndTestPatternGenerator {
+
+    private static final Random RND = new Random();
+    private static final String TEST_CHARS = "0123456789ABCDEF";
+
+    public static String generateText() {
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < 5; i++) {
+            char rndchar = TEST_CHARS.charAt(RND.nextInt(TEST_CHARS.length() - 1));
+            buffer.append(rndchar);
+        }
+        return buffer.toString();
+    }
+
+    public static int generateCount(int max) {
+        return RND.nextInt(max - 1) + 1;
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/RndTestPatternGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1165245&r1=1165244&r2=1165245&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
Mon Sep  5 11:42:25 2011
@@ -27,19 +27,18 @@
 
 package org.apache.http.nio.protocol;
 
-import java.io.UnsupportedEncodingException;
 import java.net.InetSocketAddress;
-import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Future;
 
 import org.apache.http.HttpCoreNIOTestBase;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpStatus;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.LoggingClientConnectionFactory;
 import org.apache.http.LoggingServerConnectionFactory;
+import org.apache.http.entity.ContentType;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
@@ -49,11 +48,9 @@ import org.apache.http.nio.NHttpServerIO
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
-import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.testserver.SimpleEventListener;
+import org.apache.http.util.EntityUtils;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -90,199 +87,226 @@ public class TestHttpAsyncHandlers exten
         return new LoggingClientConnectionFactory(params);
     }
 
-    private void executeStandardTest(
-            final HttpRequestHandler requestHandler,
-            final NHttpRequestExecutionHandler requestExecutionHandler) throws Exception
{
-        int connNo = 3;
-        int reqNo = 20;
-        Job[] jobs = new Job[connNo * reqNo];
-        for (int i = 0; i < jobs.length; i++) {
-            jobs[i] = new Job();
-        }
-        Queue<Job> queue = new ConcurrentLinkedQueue<Job>();
-        for (int i = 0; i < jobs.length; i++) {
-            queue.add(jobs[i]);
-        }
-
+    private InetSocketAddress start() throws Exception {
         HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
-                new RequestHandlerResolver(new BufferingAsyncRequestHandler(requestHandler)),
+                new RequestHandlerResolver(new BufferingAsyncRequestHandler(new RequestHandler())),
                 this.serverHttpProc,
                 new DefaultConnectionReuseStrategy(),
                 this.serverParams);
-
-        AsyncNHttpClientHandler clientHandler = new AsyncNHttpClientHandler(
-                this.clientHttpProc,
-                requestExecutionHandler,
-                new DefaultConnectionReuseStrategy(),
-                this.clientParams);
-
-        clientHandler.setEventListener(
-                new SimpleEventListener());
-
+        HttpAsyncClientProtocolHandler clientHandler = new HttpAsyncClientProtocolHandler();
         this.server.start(serviceHandler);
         this.client.start(clientHandler);
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
-        InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
         Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        return (InetSocketAddress) endpoint.getAddress();
+    }
 
-        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
-        for (int i = 0; i < connNo; i++) {
-            SessionRequest sessionRequest = this.client.openConnection(
-                    new InetSocketAddress("localhost", serverAddress.getPort()),
-                    queue);
-            connRequests.add(sessionRequest);
+    @Test
+    public void testHttpGets() throws Exception {
+        InetSocketAddress address = start();
+
+        this.connpool.setDefaultMaxPerRoute(3);
+        this.connpool.setMaxTotal(3);
+
+        String pattern = RndTestPatternGenerator.generateText();
+        int count = RndTestPatternGenerator.generateCount(1000);
+
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < count; i++) {
+            buffer.append(pattern);
         }
+        String expectedPattern = buffer.toString();
+
+        HttpHost target = new HttpHost("localhost", address.getPort());
 
-        while (!connRequests.isEmpty()) {
-            SessionRequest sessionRequest = connRequests.remove();
-            sessionRequest.waitFor();
-            if (sessionRequest.getException() != null) {
-                throw sessionRequest.getException();
-            }
-            Assert.assertNotNull(sessionRequest.getSession());
+        Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
+        for (int i = 0; i < 30; i++) {
+            BasicHttpRequest request = new BasicHttpRequest(
+                    "GET", pattern + "x" + count);
+            Future<HttpResponse> future = this.executor.execute(
+                    new BasicAsyncRequestProducer(target, request),
+                    new BasicAsyncResponseConsumer(),
+                    this.connpool);
+            queue.add(future);
         }
 
         Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
-        for (int i = 0; i < jobs.length; i++) {
-            Job testjob = jobs[i];
-            testjob.waitFor();
-            if (testjob.isSuccessful()) {
-                Assert.assertEquals(HttpStatus.SC_OK, testjob.getStatusCode());
-                Assert.assertEquals(testjob.getExpected(), testjob.getResult());
-            } else {
-                Assert.fail(testjob.getFailureMessage());
-            }
+        while (!queue.isEmpty()) {
+            Future<HttpResponse> future = queue.remove();
+            HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(expectedPattern, EntityUtils.toString(response.getEntity()));
         }
     }
 
-    /**
-     * This test case executes a series of simple (non-pipelined) GET requests
-     * over multiple connections. This uses non-blocking output entities.
-     */
     @Test
-    public void testHttpGets() throws Exception {
-        NHttpRequestExecutionHandler requestExecutionHandler = new RequestExecutionHandler()
{
+    public void testHttpPostsWithContentLength() throws Exception {
+        InetSocketAddress address = start();
 
-            @Override
-            protected HttpRequest generateRequest(Job testjob) {
-                String s = testjob.getPattern() + "x" + testjob.getCount();
-                return new BasicHttpRequest("GET", s);
-            }
+        this.connpool.setDefaultMaxPerRoute(3);
+        this.connpool.setMaxTotal(3);
 
-        };
-        executeStandardTest(new RequestHandler(), requestExecutionHandler);
-    }
+        String pattern = RndTestPatternGenerator.generateText();
+        int count = RndTestPatternGenerator.generateCount(1000);
 
-    /**
-     * This test case executes a series of simple (non-pipelined) POST requests
-     * with content length delimited content over multiple connections.
-     * It uses purely asynchronous handlers.
-     */
-    @Test
-    public void testHttpPostsWithContentLength() throws Exception {
-        NHttpRequestExecutionHandler requestExecutionHandler = new RequestExecutionHandler()
{
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < count; i++) {
+            buffer.append(pattern);
+        }
+        String expectedPattern = buffer.toString();
 
-            @Override
-            protected HttpRequest generateRequest(Job testjob) {
-                String s = testjob.getPattern() + "x" + testjob.getCount();
-                HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
s);
-                NStringEntity entity = null;
-                try {
-                    entity = new NStringEntity(testjob.getExpected(), "US-ASCII");
-                    entity.setChunked(false);
-                } catch (UnsupportedEncodingException ignore) {
-                }
-                r.setEntity(entity);
-                return r;
-            }
+        HttpHost target = new HttpHost("localhost", address.getPort());
 
-        };
-        executeStandardTest(new RequestHandler(), requestExecutionHandler);
+        Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
+        for (int i = 0; i < 30; i++) {
+            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
+                    "POST", pattern + "x" + count);
+            NStringEntity entity = NStringEntity.create(expectedPattern, ContentType.DEFAULT_TEXT);
+            request.setEntity(entity);
+            Future<HttpResponse> future = this.executor.execute(
+                    new BasicAsyncRequestProducer(target, request),
+                    new BasicAsyncResponseConsumer(),
+                    this.connpool);
+            queue.add(future);
+        }
+
+        Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
+        while (!queue.isEmpty()) {
+            Future<HttpResponse> future = queue.remove();
+            HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(expectedPattern, EntityUtils.toString(response.getEntity()));
+        }
     }
 
-    /**
-     * This test case executes a series of simple (non-pipelined) POST requests
-     * with chunk coded content content over multiple connections.  This tests
-     * with nonblocking handlers & nonblocking entities.
-     */
     @Test
     public void testHttpPostsChunked() throws Exception {
-        NHttpRequestExecutionHandler requestExecutionHandler = new RequestExecutionHandler()
{
+        InetSocketAddress address = start();
+
+        this.connpool.setDefaultMaxPerRoute(3);
+        this.connpool.setMaxTotal(3);
 
-            @Override
-            protected HttpRequest generateRequest(Job testjob) {
-                String s = testjob.getPattern() + "x" + testjob.getCount();
-                HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
s);
-                NStringEntity entity = null;
-                try {
-                    entity = new NStringEntity(testjob.getExpected(), "US-ASCII");
-                    entity.setChunked(true);
-                } catch (UnsupportedEncodingException ignore) {
-                }
-                r.setEntity(entity);
-                return r;
-            }
+        String pattern = RndTestPatternGenerator.generateText();
+        int count = RndTestPatternGenerator.generateCount(1000);
 
-        };
-        executeStandardTest(new RequestHandler(), requestExecutionHandler);
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < count; i++) {
+            buffer.append(pattern);
+        }
+        String expectedPattern = buffer.toString();
+
+        HttpHost target = new HttpHost("localhost", address.getPort());
+
+        Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
+        for (int i = 0; i < 30; i++) {
+            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
+                    "POST", pattern + "x" + count);
+            NStringEntity entity = NStringEntity.create(expectedPattern, ContentType.DEFAULT_TEXT);
+            entity.setChunked(true);
+            request.setEntity(entity);
+            Future<HttpResponse> future = this.executor.execute(
+                    new BasicAsyncRequestProducer(target, request),
+                    new BasicAsyncResponseConsumer(),
+                    this.connpool);
+            queue.add(future);
+        }
+
+        Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
+        while (!queue.isEmpty()) {
+            Future<HttpResponse> future = queue.remove();
+            HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(expectedPattern, EntityUtils.toString(response.getEntity()));
+        }
     }
 
-    /**
-     * This test case executes a series of simple (non-pipelined) HTTP/1.0
-     * POST requests over multiple persistent connections. This tests with nonblocking
-     * handlers & entities.
-     */
     @Test
     public void testHttpPostsHTTP10() throws Exception {
-        NHttpRequestExecutionHandler requestExecutionHandler = new RequestExecutionHandler()
{
+        InetSocketAddress address = start();
 
-            @Override
-            protected HttpRequest generateRequest(Job testjob) {
-                String s = testjob.getPattern() + "x" + testjob.getCount();
-                HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
s,
-                        HttpVersion.HTTP_1_0);
-                NStringEntity entity = null;
-                try {
-                    entity = new NStringEntity(testjob.getExpected(), "US-ASCII");
-                } catch (UnsupportedEncodingException ignore) {
-                }
-                r.setEntity(entity);
-                return r;
-            }
+        this.connpool.setDefaultMaxPerRoute(3);
+        this.connpool.setMaxTotal(3);
+
+        String pattern = RndTestPatternGenerator.generateText();
+        int count = RndTestPatternGenerator.generateCount(1000);
+
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < count; i++) {
+            buffer.append(pattern);
+        }
+        String expectedPattern = buffer.toString();
+
+        HttpHost target = new HttpHost("localhost", address.getPort());
+
+        Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
+        for (int i = 0; i < 30; i++) {
+            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
+                    "POST", pattern + "x" + count, HttpVersion.HTTP_1_0);
+            NStringEntity entity = NStringEntity.create(expectedPattern, ContentType.DEFAULT_TEXT);
+            request.setEntity(entity);
+            Future<HttpResponse> future = this.executor.execute(
+                    new BasicAsyncRequestProducer(target, request),
+                    new BasicAsyncResponseConsumer(),
+                    this.connpool);
+            queue.add(future);
+        }
 
-        };
-        executeStandardTest(new RequestHandler(), requestExecutionHandler);
+        Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
+        while (!queue.isEmpty()) {
+            Future<HttpResponse> future = queue.remove();
+            HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(expectedPattern, EntityUtils.toString(response.getEntity()));
+        }
     }
 
-    /**
-     * This test case executes a series of simple (non-pipelined) POST requests
-     * over multiple connections using the 'expect: continue' handshake.  This test
-     * uses nonblocking handlers & entities.
-     */
     @Test
     public void testHttpPostsWithExpectContinue() throws Exception {
-        NHttpRequestExecutionHandler requestExecutionHandler = new RequestExecutionHandler()
{
+        InetSocketAddress address = start();
+
+        this.connpool.setDefaultMaxPerRoute(3);
+        this.connpool.setMaxTotal(3);
+
+        String pattern = RndTestPatternGenerator.generateText();
+        int count = RndTestPatternGenerator.generateCount(1000);
+
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < count; i++) {
+            buffer.append(pattern);
+        }
+        String expectedPattern = buffer.toString();
+
+        HttpHost target = new HttpHost("localhost", address.getPort());
+
+        Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
+        for (int i = 0; i < 30; i++) {
+            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
+                    "POST", pattern + "x" + count);
+            request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,
true);
+            NStringEntity entity = NStringEntity.create(expectedPattern, ContentType.DEFAULT_TEXT);
+            request.setEntity(entity);
+            Future<HttpResponse> future = this.executor.execute(
+                    new BasicAsyncRequestProducer(target, request),
+                    new BasicAsyncResponseConsumer(),
+                    this.connpool);
+            queue.add(future);
+        }
 
-            @Override
-            protected HttpRequest generateRequest(Job testjob) {
-                String s = testjob.getPattern() + "x" + testjob.getCount();
-                HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
s);
-                NStringEntity entity = null;
-                try {
-                    entity = new NStringEntity(testjob.getExpected(), "US-ASCII");
-                } catch (UnsupportedEncodingException ignore) {
-                }
-                r.setEntity(entity);
-                r.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,
true);
-                return r;
-            }
+        Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
-        };
-        executeStandardTest(new RequestHandler(), requestExecutionHandler);
+        while (!queue.isEmpty()) {
+            Future<HttpResponse> future = queue.remove();
+            HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(expectedPattern, EntityUtils.toString(response.getEntity()));
+        }
     }
 
 }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java?rev=1165245&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
Mon Sep  5 11:42:25 2011
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import org.apache.http.LoggingSSLClientConnectionFactory;
+import org.apache.http.LoggingSSLServerConnectionFactory;
+import org.apache.http.SSLTestContexts;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.params.HttpParams;
+
+/**
+ * HttpCore NIO integration tests for async handlers using SSL.
+ */
+public class TestHttpsAsyncHandlers extends TestHttpAsyncHandlers {
+
+    @Override
+    protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+            final HttpParams params) throws Exception {
+        return new LoggingSSLServerConnectionFactory(SSLTestContexts.createServerSSLContext(),
params);
+    }
+
+    @Override
+    protected NHttpConnectionFactory<NHttpClientIOTarget> createClientConnectionFactory(
+            final HttpParams params) throws Exception {
+        return new LoggingSSLClientConnectionFactory(SSLTestContexts.createClientSSLContext(),
params);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpsAsyncHandlers.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message