Skip to content

Commit 045a064

Browse files
author
Stephane Landelle
committed
Optimize and clean up NettyFuture.done, backport AsyncHttpClient#141
1 parent 7009cad commit 045a064

File tree

3 files changed

+11
-39
lines changed

3 files changed

+11
-39
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyResponseFuture.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ V getContent() throws ExecutionException {
278278
}
279279

280280
public final void done(Callable callable) {
281+
282+
Throwable exception = null;
283+
281284
try {
282285
cancelReaper();
283286

@@ -290,16 +293,21 @@ public final void done(Callable callable) {
290293
try {
291294
callable.call();
292295
} catch (Exception ex) {
293-
throw new RuntimeException(ex);
296+
exception = ex;
294297
}
295298
}
296299
} catch (ExecutionException t) {
297300
return;
298301
} catch (RuntimeException t) {
299-
exEx.compareAndSet(null, new ExecutionException(t));
302+
exception = t.getCause() != null ? t.getCause() : t;
303+
300304
} finally {
301305
latch.countDown();
302306
}
307+
308+
if (exception != null)
309+
exEx.compareAndSet(null, new ExecutionException(exception));
310+
303311
super.done();
304312
}
305313

src/test/java/com/ning/http/client/async/ConnectionPoolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public Response onCompleted(Response response) throws Exception {
303303
} catch (ExecutionException ex) {
304304
assertNotNull(ex);
305305
assertNotNull(ex.getCause());
306-
assertEquals(ex.getCause().getCause().getClass(), IOException.class);
306+
assertEquals(ex.getCause().getClass(), IOException.class);
307307
assertEquals(count.get(), 1);
308308
}
309309
} finally {

src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionPoolTest.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
import static org.testng.Assert.assertNull;
1919
import static org.testng.Assert.fail;
2020

21-
import java.io.IOException;
22-
import java.util.concurrent.ExecutionException;
2321
import java.util.concurrent.TimeUnit;
24-
import java.util.concurrent.atomic.AtomicInteger;
2522

2623
import org.glassfish.grizzly.Connection;
2724
import org.testng.annotations.Test;
2825

29-
import com.ning.http.client.AsyncCompletionHandler;
3026
import com.ning.http.client.AsyncHttpClient;
3127
import com.ning.http.client.AsyncHttpClientConfig;
3228
import com.ning.http.client.ConnectionsPool;
@@ -178,36 +174,4 @@ public void multipleMaxConnectionOpenTest() throws Throwable {
178174
c.close();
179175
}
180176
}
181-
182-
@Override
183-
@Test
184-
public void win7DisconnectTest() throws Throwable {
185-
final AtomicInteger count = new AtomicInteger(0);
186-
187-
AsyncCompletionHandler<Response> handler = new AsyncCompletionHandlerAdapter() {
188-
189-
@Override
190-
public Response onCompleted(Response response) throws Exception {
191-
192-
count.incrementAndGet();
193-
StackTraceElement e = new StackTraceElement("sun.nio.ch.SocketDispatcher", "read0", null, -1);
194-
IOException t = new IOException();
195-
t.setStackTrace(new StackTraceElement[] { e });
196-
throw t;
197-
}
198-
};
199-
200-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().build());
201-
try {
202-
client.prepareGet(getTargetUrl()).execute(handler).get();
203-
fail("Must have received an exception");
204-
} catch (ExecutionException ex) {
205-
assertNotNull(ex);
206-
assertNotNull(ex.getCause());
207-
assertEquals(ex.getCause().getClass(), IOException.class);
208-
assertEquals(count.get(), 1);
209-
} finally {
210-
client.close();
211-
}
212-
}
213177
}

0 commit comments

Comments
 (0)