make some LocalHTTPD tests require no Keep-Alive
This commit is contained in:
parent
e3b26b76f6
commit
fc65502ce4
@ -125,8 +125,7 @@ public class LocalHTTPDTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doTest404() throws Exception {
|
public void doTest404() throws Exception {
|
||||||
URL url = new URL("http://localhost:8888/xxx/yyy.html");
|
HttpURLConnection connection = getNoKeepAliveConnection("http://localhost:8888/xxx/yyy.html");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setReadTimeout(5000);
|
connection.setReadTimeout(5000);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
Assert.assertEquals(404, connection.getResponseCode());
|
Assert.assertEquals(404, connection.getResponseCode());
|
||||||
@ -193,7 +192,7 @@ public class LocalHTTPDTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeadRequest() throws IOException {
|
public void testHeadRequest() throws IOException, InterruptedException {
|
||||||
File indexFile = new File(webRoot, "index.html");
|
File indexFile = new File(webRoot, "index.html");
|
||||||
IOUtils.copy(classLoader.getResourceAsStream("index.html"),
|
IOUtils.copy(classLoader.getResourceAsStream("index.html"),
|
||||||
new FileOutputStream(indexFile));
|
new FileOutputStream(indexFile));
|
||||||
@ -212,6 +211,7 @@ public class LocalHTTPDTest {
|
|||||||
|
|
||||||
assertEquals(200, connection.getResponseCode());
|
assertEquals(200, connection.getResponseCode());
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
Thread.sleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -340,9 +340,7 @@ public class LocalHTTPDTest {
|
|||||||
public void testRangeHeaderWithStartPositionOnly() throws IOException {
|
public void testRangeHeaderWithStartPositionOnly() throws IOException {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL("http://localhost:8888/testdir/test.html");
|
connection = getNoKeepAliveConnection("http://localhost:8888/testdir/test.html");
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestProperty("Connection", "close");
|
|
||||||
connection.addRequestProperty("range", "bytes=10-");
|
connection.addRequestProperty("range", "bytes=10-");
|
||||||
connection.setReadTimeout(5000);
|
connection.setReadTimeout(5000);
|
||||||
String responseString = IOUtils.toString(connection.getInputStream(), "UTF-8");
|
String responseString = IOUtils.toString(connection.getInputStream(), "UTF-8");
|
||||||
@ -414,10 +412,8 @@ public class LocalHTTPDTest {
|
|||||||
while (status == -1) {
|
while (status == -1) {
|
||||||
System.out.println("testIfNoneMatchHeader connect attempt");
|
System.out.println("testIfNoneMatchHeader connect attempt");
|
||||||
try {
|
try {
|
||||||
URL url = new URL("http://localhost:8888/testdir/test.html");
|
connection = getNoKeepAliveConnection("http://localhost:8888/testdir/test.html");
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestProperty("if-none-match", "*");
|
connection.setRequestProperty("if-none-match", "*");
|
||||||
connection.setRequestProperty("Connection", "close");
|
|
||||||
connection.connect();
|
connection.connect();
|
||||||
status = connection.getResponseCode();
|
status = connection.getResponseCode();
|
||||||
} finally {
|
} finally {
|
||||||
@ -446,4 +442,11 @@ public class LocalHTTPDTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HttpURLConnection getNoKeepAliveConnection(String urlString) throws IOException {
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestProperty("Connection", "Close"); // avoid keep-alive
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user