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:29:10 UTC
svn commit: r1616123 - in
/httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src:
main/java/org/apache/http/impl/nio/client/
test/java/org/apache/http/nio/client/integration/
Author: olegk
Date: Wed Aug 6 08:29:10 2014
New Revision: 1616123
URL: http://svn.apache.org/r1616123
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/branches/4.0.x/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
Modified: httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java?rev=1616123&r1=1616122&r2=1616123&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java (original)
+++ httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java Wed Aug 6 08:29:10 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/branches/4.0.x/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java?rev=1616123&r1=1616122&r2=1616123&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java (original)
+++ httpcomponents/httpasyncclient/branches/4.0.x/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java Wed Aug 6 08:29:10 2014
@@ -28,8 +28,12 @@ package org.apache.http.nio.client.integ
import java.io.IOException;
import java.net.InetSocketAddress;
+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.HttpAsyncTestBase;
import org.apache.http.HttpConnection;
@@ -46,9 +50,11 @@ import org.apache.http.impl.DefaultHttpR
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.NHttpConnectionFactory;
+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;
@@ -57,6 +63,8 @@ import org.apache.http.nio.protocol.Http
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
+import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
+import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
import org.apache.http.nio.reactor.IOReactorStatus;
@@ -103,10 +111,6 @@ public class TestHttpAsyncPrematureTermi
requestHandlerResolver,
expectationVerifier);
- this.httpclient = HttpAsyncClients.custom()
- .setConnectionManager(this.connMgr)
- .build();
-
this.server.start(serviceHandler);
this.httpclient.start();
@@ -286,4 +290,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());
+ }
+
}