diff options
author | Greg Wilkins | 2010-12-09 16:49:46 +0000 |
---|---|---|
committer | Greg Wilkins | 2010-12-09 16:49:46 +0000 |
commit | 312cf416ec9d7118b7a0f1b3ade17857bfcdb986 (patch) | |
tree | 0dd6e5a05d6244fe7d9f4e787824b5823a9cb26c /jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java | |
parent | 703aca344906a0b64c44a241b35d5849a8df753f (diff) | |
download | org.eclipse.jetty.project-312cf416ec9d7118b7a0f1b3ade17857bfcdb986.tar.gz org.eclipse.jetty.project-312cf416ec9d7118b7a0f1b3ade17857bfcdb986.tar.xz org.eclipse.jetty.project-312cf416ec9d7118b7a0f1b3ade17857bfcdb986.zip |
minor cleanups and test improvements
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2603 7e9141cc-0065-0410-87d8-b60c137991c4
Diffstat (limited to 'jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java')
-rw-r--r-- | jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java | 139 |
1 files changed, 134 insertions, 5 deletions
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index 61d045acf7..e1cb8f45d4 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -22,14 +22,20 @@ import java.io.OutputStream; import java.net.Socket; import javax.net.ssl.SSLException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import junit.framework.Assert; +import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.IO; import org.junit.Test; public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { + protected static final int MAX_IDLE_TIME=250; + static { System.setProperty("org.eclipse.jetty.io.nio.IDLE_TICK","100"); @@ -37,7 +43,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture @Test - public void testSelectConnectorMaxIdleWithRequest10() throws Exception + public void testMaxIdleWithRequest10() throws Exception { configureServer(new HelloWorldHandler()); Socket client=newSocket(HOST,_connector.getLocalPort()); @@ -68,7 +74,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture } @Test - public void testSelectConnectorMaxIdleWithRequest11() throws Exception + public void testMaxIdleWithRequest11() throws Exception { configureServer(new EchoHandler()); Socket client=newSocket(HOST,_connector.getLocalPort()); @@ -102,7 +108,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture @Test - public void testSelectConnectorMaxIdleNoRequest() throws Exception + public void testMaxIdleNoRequest() throws Exception { configureServer(new EchoHandler()); Socket client=newSocket(HOST,_connector.getLocalPort()); @@ -127,7 +133,130 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture } Assert.assertTrue(System.currentTimeMillis()-start<5000); - } - + + @Test + public void testMaxIdleWithSlowRequest() throws Exception + { + configureServer(new EchoHandler()); + Socket client=newSocket(HOST,_connector.getLocalPort()); + client.setSoTimeout(10000); + + assertFalse(client.isClosed()); + + OutputStream os=client.getOutputStream(); + InputStream is=client.getInputStream(); + + String content="Wibble\r\n"; + byte[] contentB=content.getBytes("utf-8"); + os.write(( + "GET / HTTP/1.0\r\n"+ + "host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+ + "connection: keep-alive\r\n"+ + "Content-Length: "+(contentB.length*20)+"\r\n"+ + "Content-Type: text/plain\r\n"+ + "Connection: close\r\n"+ + "\r\n").getBytes("utf-8")); + os.flush(); + + for (int i =0;i<20;i++) + { + Thread.sleep(50); + os.write(contentB); + os.flush(); + } + + String in = IO.toString(is); + int offset=0; + for (int i =0;i<20;i++) + { + offset=in.indexOf("Wibble",offset+1); + Assert.assertTrue(""+i,offset>0); + } + } + + @Test + public void testMaxIdleWithSlowResponse() throws Exception + { + configureServer(new SlowResponseHandler()); + Socket client=newSocket(HOST,_connector.getLocalPort()); + client.setSoTimeout(10000); + + assertFalse(client.isClosed()); + + OutputStream os=client.getOutputStream(); + InputStream is=client.getInputStream(); + + os.write(( + "GET / HTTP/1.0\r\n"+ + "host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+ + "connection: keep-alive\r\n"+ + "Connection: close\r\n"+ + "\r\n").getBytes("utf-8")); + os.flush(); + + String in = IO.toString(is); + int offset=0; + for (int i =0;i<20;i++) + { + offset=in.indexOf("Hello World",offset+1); + Assert.assertTrue(""+i,offset>0); + } + } + + @Test + public void testMaxIdleWithWait() throws Exception + { + configureServer(new WaitHandler()); + Socket client=newSocket(HOST,_connector.getLocalPort()); + client.setSoTimeout(10000); + + assertFalse(client.isClosed()); + + OutputStream os=client.getOutputStream(); + InputStream is=client.getInputStream(); + + os.write(( + "GET / HTTP/1.0\r\n"+ + "host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+ + "connection: keep-alive\r\n"+ + "Connection: close\r\n"+ + "\r\n").getBytes("utf-8")); + os.flush(); + + String in = IO.toString(is); + int offset=in.indexOf("Hello World"); + Assert.assertTrue(offset>0); + } + + protected static class SlowResponseHandler extends AbstractHandler + { + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + response.setStatus(200); + OutputStream out = response.getOutputStream(); + + for (int i=0;i<20;i++) + { + out.write("Hello World\r\n".getBytes()); + out.flush(); + try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();} + } + out.close(); + } + } + + protected static class WaitHandler extends AbstractHandler + { + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + response.setStatus(200); + OutputStream out = response.getOutputStream(); + try{Thread.sleep(2000);}catch(Exception e){e.printStackTrace();} + out.write("Hello World\r\n".getBytes()); + out.flush(); + } + } } |