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 2014/08/06 10:31:59 UTC
svn commit: r1616126 - 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
Author: olegk
Date: Wed Aug 6 08:31:59 2014
New Revision: 1616126
URL: http://svn.apache.org/r1616126
Log:
HTTPASYNC-81: request producer and response producer #failed methods never get called in case of a connection request failure (for instance due to unknown or invalid hostname)
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=1616126&r1=1616125&r2=1616126&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:31:59 2014
@@ -314,11 +314,7 @@ class DefaultClientExchangeHandlerImpl<T
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + this.state.getId() + "] connection request failed");
}
- try {
- this.resultFuture.failed(ex);
- } finally {
- close();
- }
+ failed(ex);
}
private void connectionRequestCancelled() {
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=1616126&r1=1616125&r2=1616126&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:31:59 2014
@@ -27,10 +27,13 @@
package org.apache.http.nio.client.integration;
import java.io.IOException;
+import java.net.UnknownHostException;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.http.localserver.HttpAsyncTestBase;
import org.apache.http.HttpConnection;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
@@ -39,14 +42,20 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
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.HttpAsyncTestBase;
+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.BasicAsyncResponseProducer;
import org.apache.http.nio.protocol.HttpAsyncExchange;
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
+import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.junit.Assert;
@@ -207,4 +216,78 @@ public class TestHttpAsyncPrematureTermi
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
+ @Test
+ public void testConnectionRequestFailure() throws Exception {
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .build();
+ this.httpclient.start();
+
+ final HttpGet get = new HttpGet("http://stuff.invalid/");
+ final HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
+
+ 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 {
+ throw new IllegalStateException();
+ }
+
+ public void consumeContent(
+ final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
+ throw new IllegalStateException();
+ }
+
+ public void responseCompleted(final HttpContext context) {
+ throw new IllegalStateException();
+ }
+
+ public Exception getException() {
+ return null;
+ }
+
+ public String getResult() {
+ return null;
+ }
+
+ @Override
+ public boolean isDone() {
+ return false;
+ }
+ };
+
+ final Future<?> future = httpclient.execute(producer, consumer, null, null);
+ try {
+ future.get();
+ Assert.fail();
+ } catch (ExecutionException e) {
+ Assert.assertTrue(e.getCause() instanceof UnknownHostException);
+ }
+ this.connMgr.shutdown(1000);
+
+ Assert.assertTrue(closed.get());
+ Assert.assertFalse(cancelled.get());
+ Assert.assertTrue(failed.get());
+ }
+
}