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:
parent
191286970a
commit
5f2a7fdfce
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpCookie;
|
import java.net.HttpCookie;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -43,6 +44,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -520,7 +522,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
@Test
|
@Test
|
||||||
public void test_ExchangeIsComplete_OnlyWhenBothRequestAndResponseAreComplete() throws Exception
|
public void test_ExchangeIsComplete_OnlyWhenBothRequestAndResponseAreComplete() throws Exception
|
||||||
{
|
{
|
||||||
start(new EmptyServerHandler());
|
start(new RespondThenConsumeHandler());
|
||||||
|
|
||||||
// Prepare a big file to upload
|
// Prepare a big file to upload
|
||||||
Path targetTestsDir = testdir.getEmptyDir().toPath();
|
Path targetTestsDir = testdir.getEmptyDir().toPath();
|
||||||
|
@ -577,6 +579,23 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
Files.delete(file);
|
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
|
@Test
|
||||||
public void test_ExchangeIsComplete_WhenRequestFailsMidway_WithResponse() throws Exception
|
public void test_ExchangeIsComplete_WhenRequestFailsMidway_WithResponse() throws Exception
|
||||||
|
|
Loading…
Reference in New Issue