You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2016/11/28 12:46:24 UTC
svn commit: r1771730 -
/tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
Author: violetagg
Date: Mon Nov 28 12:46:23 2016
New Revision: 1771730
URL: http://svn.apache.org/viewvc?rev=1771730&view=rev
Log:
Update unit test that reproduces the exceptions reported with bug 60409.
Modified:
tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
Modified: tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java?rev=1771730&r1=1771729&r2=1771730&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java Mon Nov 28 12:46:23 2016
@@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletRes
import static org.junit.Assert.assertEquals;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.apache.catalina.Context;
@@ -156,14 +157,14 @@ public class TestSendFile extends Tomcat
}
+ @Ignore
@Test
public void testBug60409() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context ctx = tomcat.addContext("", TEMP_DIR);
File file = generateFile(TEMP_DIR, "", EXPECTED_CONTENT_LENGTH);
- CountDownLatch latch = new CountDownLatch(2);
- Tomcat.addServlet(ctx, "test", new Bug60409Servlet(file, latch));
+ Tomcat.addServlet(ctx, "test", new Bug60409Servlet(file));
ctx.addServletMappingDecoded("/", "test");
tomcat.start();
@@ -172,11 +173,14 @@ public class TestSendFile extends Tomcat
getUrl("http://localhost:" + getPort() + "/test/?" + Globals.SENDFILE_SUPPORTED_ATTR
+ "=true", bc, null);
+ CountDownLatch latch = new CountDownLatch(2);
List<Throwable> exceptions = new ArrayList<>();
- new Thread(new RequestExecutor("http://localhost:" + getPort() + "/test/", exceptions))
- .start();
- new Thread(new RequestExecutor("http://localhost:" + getPort() + "/test/", exceptions))
- .start();
+ new Thread(
+ new RequestExecutor("http://localhost:" + getPort() + "/test/", latch, exceptions))
+ .start();
+ new Thread(
+ new RequestExecutor("http://localhost:" + getPort() + "/test/", latch, exceptions))
+ .start();
latch.await(3000, TimeUnit.MILLISECONDS);
@@ -188,20 +192,18 @@ public class TestSendFile extends Tomcat
private static final class Bug60409Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final File file;
- private final CountDownLatch latch;
- Bug60409Servlet(File file, CountDownLatch latch) {
+ Bug60409Servlet(File file) {
this.file = file;
- this.latch = latch;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
- resp.setContentType("'application/octet-stream");
- resp.setCharacterEncoding("ISO-8859-1");
- resp.setContentLengthLong(file.length());
- if (Boolean.TRUE.equals(req.getAttribute(Globals.SENDFILE_SUPPORTED_ATTR))) {
+ if (Boolean.valueOf(req.getParameter(Globals.SENDFILE_SUPPORTED_ATTR))) {
+ resp.setContentType("'application/octet-stream");
+ resp.setCharacterEncoding("ISO-8859-1");
+ resp.setContentLengthLong(file.length());
req.setAttribute(Globals.SENDFILE_FILENAME_ATTR, file.getAbsolutePath());
req.setAttribute(Globals.SENDFILE_FILE_START_ATTR, new Long(0));
req.setAttribute(Globals.SENDFILE_FILE_END_ATTR, new Long(file.length()));
@@ -216,7 +218,6 @@ public class TestSendFile extends Tomcat
e.printStackTrace();
}
resp.getOutputStream().write(c);
- latch.countDown();
}
}
@@ -224,10 +225,12 @@ public class TestSendFile extends Tomcat
private static final class RequestExecutor implements Runnable {
private final String url;
+ private final CountDownLatch latch;
private final List<Throwable> exceptions;
- public RequestExecutor(String url, List<Throwable> exceptions) {
+ RequestExecutor(String url, CountDownLatch latch, List<Throwable> exceptions) {
this.url = url;
+ this.latch = latch;
this.exceptions = exceptions;
}
@@ -236,10 +239,13 @@ public class TestSendFile extends Tomcat
try {
ByteChunk result = new ByteChunk();
int rc = getUrl(url, result, null);
- Assert.assertTrue(rc == HttpServletResponse.SC_OK);
+ Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+ Assert.assertEquals(1024, result.getLength());
} catch (Throwable e) {
e.printStackTrace();
exceptions.add(e);
+ } finally {
+ latch.countDown();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org