hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1616127 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
Date Wed, 06 Aug 2014 08:32:36 GMT
Author: olegk
Date: Wed Aug  6 08:32:36 2014
New Revision: 1616127

URL: http://svn.apache.org/r1616127
Log:
HTTPASYNC-81: Premature response consumer termination

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java?rev=1616127&r1=1616126&r2=1616127&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
Wed Aug  6 08:32:36 2014
@@ -153,7 +153,11 @@ class DefaultClientExchangeHandlerImpl<T
         this.exec.consumeContent(this.state, decoder, ioctrl);
         if (!decoder.isCompleted() && this.responseConsumer.isDone()) {
             if (this.completed.compareAndSet(false, true)) {
-                this.resultFuture.cancel();
+                try {
+                    this.resultFuture.cancel();
+                } finally {
+                    responseConsumer.close();
+                }
             }
             this.state.setNonReusable();
             releaseConnection();

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java?rev=1616127&r1=1616126&r2=1616127&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
Wed Aug  6 08:32:36 2014
@@ -43,13 +43,16 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.entity.ContentType;
 import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.apache.http.localserver.EchoHandler;
 import org.apache.http.localserver.HttpAsyncTestBase;
+import org.apache.http.localserver.RandomHandler;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.client.methods.HttpAsyncMethods;
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
 import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
 import org.apache.http.nio.protocol.HttpAsyncExchange;
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
@@ -276,7 +279,7 @@ public class TestHttpAsyncPrematureTermi
             }
         };
 
-        final Future<?> future = httpclient.execute(producer, consumer, null, null);
+        final Future<?> future = this.httpclient.execute(producer, consumer, null,
null);
         try {
             future.get();
             Assert.fail();
@@ -290,4 +293,70 @@ public class TestHttpAsyncPrematureTermi
         Assert.assertTrue(failed.get());
     }
 
+    @Test
+    public void testConsumerIsDone() throws Exception {
+        this.serverBootstrap.registerHandler("/echo/*", new BasicAsyncRequestHandler(new
EchoHandler()));
+        this.serverBootstrap.registerHandler("/random/*", new BasicAsyncRequestHandler(new
RandomHandler()));
+
+        final HttpHost target = start();
+
+        final HttpAsyncRequestProducer producer = HttpAsyncMethods.create(target, new HttpGet("/"));
+
+        final AtomicBoolean closed = new AtomicBoolean(false);
+        final AtomicBoolean cancelled = new AtomicBoolean(false);
+        final AtomicBoolean failed = new AtomicBoolean(false);
+
+        final HttpAsyncResponseConsumer<?> consumer = new HttpAsyncResponseConsumer<Object>()
{
+
+            @Override
+            public void close() throws IOException {
+                closed.set(true);
+            }
+
+            @Override
+            public boolean cancel() {
+                cancelled.set(true);
+                return false;
+            }
+
+            @Override
+            public void failed(final Exception ex) {
+                failed.set(true);
+            }
+
+            public void responseReceived(
+                    final HttpResponse response) throws IOException, HttpException {
+            }
+
+            public void consumeContent(
+                    final ContentDecoder decoder, final IOControl ioctrl) throws IOException
{
+            }
+
+            public void responseCompleted(final HttpContext context) {
+            }
+
+            public Exception getException() {
+                return null;
+            }
+
+            public String getResult() {
+                return null;
+            }
+
+            @Override
+            public boolean isDone() {
+                return true; // cancels fetching the response-body
+            }
+        };
+
+        final Future<?> future = this.httpclient.execute(producer, consumer, null,
null);
+        future.get();
+
+        connMgr.shutdown(1000);
+
+        Assert.assertTrue(future.isCancelled());
+        Assert.assertFalse(failed.get());
+        Assert.assertTrue(closed.get());
+    }
+
 }



Mime
View raw message