hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1616438 - 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 Thu, 07 Aug 2014 08:39:47 GMT
Author: olegk
Date: Thu Aug  7 08:39:46 2014
New Revision: 1616438

URL: http://svn.apache.org/r1616438
Log:
HTTPASYNC-81: ensure request produce is closed in case of a premature exchange termination
Contributed by Markus Kull <markus.kull at 1und1.de>

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=1616438&r1=1616437&r2=1616438&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
Thu Aug  7 08:39:46 2014
@@ -152,15 +152,14 @@ class DefaultClientExchangeHandlerImpl<T
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
         this.exec.consumeContent(this.state, decoder, ioctrl);
         if (!decoder.isCompleted() && this.responseConsumer.isDone()) {
-            if (this.completed.compareAndSet(false, true)) {
-                try {
-                    this.resultFuture.cancel();
-                } finally {
-                    responseConsumer.close();
-                }
-            }
             this.state.setNonReusable();
-            releaseConnection();
+            try {
+                this.completed.set(true);
+                releaseConnection();
+                this.resultFuture.cancel();
+            } finally {
+                close();
+            }
         }
     }
 

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=1616438&r1=1616437&r2=1616438&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
Thu Aug  7 08:39:46 2014
@@ -33,6 +33,7 @@ import java.util.concurrent.ExecutionExc
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpException;
@@ -53,6 +54,7 @@ import org.apache.http.nio.client.method
 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.BasicAsyncRequestProducer;
 import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
 import org.apache.http.nio.protocol.HttpAsyncExchange;
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
@@ -300,28 +302,32 @@ public class TestHttpAsyncPrematureTermi
 
         final HttpHost target = start();
 
-        final HttpAsyncRequestProducer producer = HttpAsyncMethods.create(target, new HttpGet("/"));
+        final AtomicInteger producerClosed = new AtomicInteger(0);
+        final AtomicInteger consumerClosed = new AtomicInteger(0);
 
-        final AtomicBoolean closed = new AtomicBoolean(false);
-        final AtomicBoolean cancelled = new AtomicBoolean(false);
-        final AtomicBoolean failed = new AtomicBoolean(false);
+        final HttpAsyncRequestProducer producer = new BasicAsyncRequestProducer(target, new
HttpGet("/")) {
+
+            @Override
+            public synchronized void close() throws IOException {
+                producerClosed.incrementAndGet();
+                super.close();
+            }
+        };
 
         final HttpAsyncResponseConsumer<?> consumer = new HttpAsyncResponseConsumer<Object>()
{
 
             @Override
             public void close() throws IOException {
-                closed.set(true);
+                consumerClosed.incrementAndGet();
             }
 
             @Override
             public boolean cancel() {
-                cancelled.set(true);
                 return false;
             }
 
             @Override
             public void failed(final Exception ex) {
-                failed.set(true);
             }
 
             public void responseReceived(
@@ -355,8 +361,10 @@ public class TestHttpAsyncPrematureTermi
         connMgr.shutdown(1000);
 
         Assert.assertTrue(future.isCancelled());
-        Assert.assertFalse(failed.get());
-        Assert.assertTrue(closed.get());
+        Assert.assertTrue(future.isCancelled());
+
+        Assert.assertEquals(1, producerClosed.get());
+        Assert.assertEquals(1, consumerClosed.get());
     }
 
 }



Mime
View raw message