Jetty9 - Improved tests to make them pass.

This commit is contained in:
Simone Bordet 2012-08-23 18:05:43 +02:00
parent 7a5997df9d
commit c009cef661
3 changed files with 835 additions and 800 deletions

View File

@ -25,7 +25,6 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URISyntaxException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -57,7 +56,8 @@ public abstract class AbstractHttpTest
{
server = new Server();
connector = new SelectChannelConnector(server);
server.setConnectors(new Connector[]{connector});
connector.setIdleTimeout(10000);
server.addConnector(connector);
httpParser = new SimpleHttpParser(httpVersion);
((StdErrLog)Log.getLogger(HttpChannel.class)).setHideStacks(true);
}
@ -72,6 +72,7 @@ public abstract class AbstractHttpTest
protected SimpleHttpParser.TestHttpResponse executeRequest() throws URISyntaxException, IOException
{
Socket socket = new Socket("localhost", connector.getLocalPort());
socket.setSoTimeout((int)connector.getIdleTimeout());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String request = "GET / " + httpVersion + "\r\n";
@ -105,6 +106,7 @@ public abstract class AbstractHttpTest
protected class ThrowExceptionOnDemandHandler extends AbstractHandler
{
private final boolean throwException;
private volatile Throwable failure;
protected ThrowExceptionOnDemandHandler(boolean throwException)
{
@ -117,5 +119,15 @@ public abstract class AbstractHttpTest
if (throwException)
throw new TestCommitException();
}
protected void markFailed(Throwable x)
{
this.failure = x;
}
public Throwable failure()
{
return failure;
}
}
}

View File

@ -178,7 +178,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -193,7 +193,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
// Since the 200 was committed, the 500 did not get the chance to be written
assertThat("response code is 200", response.getCode(), is("200"));
assertThat("response body is foobar", response.getBody(), is("foobar"));
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -223,7 +223,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
SimpleHttpParser.TestHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -236,7 +236,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
SimpleHttpParser.TestHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -266,7 +266,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -281,7 +281,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
// Since the 200 was committed, the 500 did not get the chance to be written
assertThat("response code is 200", response.getCode(), is("200"));
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -313,7 +313,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -328,7 +328,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
// Response was committed when we throw, so 200 expected
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
if ("HTTP/1.1".equals(httpVersion))
if (!"HTTP/1.0".equals(httpVersion))
assertHeader(response, "transfer-encoding", "chunked");
}
@ -487,7 +487,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
SimpleHttpParser.TestHttpResponse response = executeRequest();
// Setting a content-length too small causes throws an IllegalStateException
// Setting a content-length too small throws an IllegalStateException
assertThat("response code is 500", response.getCode(), is("500"));
assertThat("response body is not foo", response.getBody(), not(is("foo")));
}
@ -500,6 +500,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
SimpleHttpParser.TestHttpResponse response = executeRequest();
// Setting a content-length too small throws an IllegalStateException
assertThat("response code is 500", response.getCode(), is("500"));
assertThat("response body is not foo", response.getBody(), not(is("foo")));
}