fixed http client respond before consumed test.

The server now is a bit lazier if the handler has not consumed content.  It will not block to consume and gives up and closes the connection instead.
This commit is contained in:
Greg Wilkins 2014-12-31 11:48:23 +01:00
parent 191286970a
commit 5f2a7fdfce
1 changed files with 20 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpCookie;
import java.net.URI;
@ -43,6 +44,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@ -520,7 +522,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
@Test
public void test_ExchangeIsComplete_OnlyWhenBothRequestAndResponseAreComplete() throws Exception
{
start(new EmptyServerHandler());
start(new RespondThenConsumeHandler());
// Prepare a big file to upload
Path targetTestsDir = testdir.getEmptyDir().toPath();
@ -577,6 +579,23 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Files.delete(file);
}
private static class RespondThenConsumeHandler extends AbstractHandler
{
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
baseRequest.setHandled(true);
response.setContentLength(0);
response.setStatus(200);
response.flushBuffer();
InputStream in = request.getInputStream();
while(in.read()>=0);
}
}
@Test
public void test_ExchangeIsComplete_WhenRequestFailsMidway_WithResponse() throws Exception