405551 - InputStreamResponseListener.await returns null when request fails.
Moved the success/failure logic to onComplete(), to be notified even if only the request fails.
This commit is contained in:
parent
9885449bdf
commit
f57a4a45a6
|
@ -129,29 +129,24 @@ public class InputStreamResponseListener extends Response.Listener.Empty
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Response response, Throwable failure)
|
||||
{
|
||||
LOG.debug("Queuing failure {} {}", FAILURE, failure);
|
||||
queue.offer(FAILURE);
|
||||
responseLatch.countDown();
|
||||
resultLatch.countDown();
|
||||
this.failure = failure;
|
||||
signal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Response response)
|
||||
{
|
||||
LOG.debug("Queuing end of content {}{}", EOF, "");
|
||||
queue.offer(EOF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
this.result = result;
|
||||
if (result.isSucceeded())
|
||||
{
|
||||
LOG.debug("Queuing end of content {}{}", EOF, "");
|
||||
queue.offer(EOF);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("Queuing failure {} {}", FAILURE, failure);
|
||||
queue.offer(FAILURE);
|
||||
this.failure = result.getFailure();
|
||||
responseLatch.countDown();
|
||||
}
|
||||
resultLatch.countDown();
|
||||
signal();
|
||||
}
|
||||
|
||||
protected boolean await()
|
||||
|
@ -176,7 +171,7 @@ public class InputStreamResponseListener extends Response.Listener.Empty
|
|||
{
|
||||
synchronized (this)
|
||||
{
|
||||
notify();
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -445,6 +445,20 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest
|
|||
Assert.assertNull(failure.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputStreamResponseListenerFailedBeforeResponse() throws Exception
|
||||
{
|
||||
start(new EmptyServerHandler());
|
||||
|
||||
InputStreamResponseListener listener = new InputStreamResponseListener();
|
||||
// Connect to the wrong port
|
||||
client.newRequest("localhost", 0)
|
||||
.scheme(scheme)
|
||||
.send(listener);
|
||||
Result result = listener.await(5, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test(expected = ExecutionException.class)
|
||||
public void testInputStreamContentProviderThrowingWhileReading() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue