Author: markt Date: Fri Dec 5 09:35:40 2014 New Revision: 1643209 URL: http://svn.apache.org/viewvc?rev=1643209&view=rev Log: Create (currently failing) test cases for https://issues.apache.org/bugzilla/show_bug.cgi?id=57252
Modified: tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java Modified: tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java?rev=1643209&r1=1643208&r2=1643209&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java (original) +++ tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java Fri Dec 5 09:35:40 2014 @@ -1243,15 +1243,25 @@ public class TestAsyncContextImpl extend @Test public void testBug51197a() throws Exception { - doTestBug51197(false); + doTestBug51197(false, false); } @Test public void testBug51197b() throws Exception { - doTestBug51197(true); + doTestBug51197(true, false); } - private void doTestBug51197(boolean threaded) throws Exception { + @Test + public void testBug51197c() throws Exception { + doTestBug51197(false, true); + } + + @Test + public void testBug51197d() throws Exception { + doTestBug51197(true, true); + } + + private void doTestBug51197(boolean threaded, boolean customError) throws Exception { // Setup Tomcat instance Tomcat tomcat = getTomcatInstance(); @@ -1265,6 +1275,17 @@ public class TestAsyncContextImpl extend wrapper.setAsyncSupported(true); ctx.addServletMapping("/asyncErrorServlet", "asyncErrorServlet"); + if (customError) { + CustomErrorServlet customErrorServlet = new CustomErrorServlet(); + Tomcat.addServlet(ctx, "customErrorServlet", customErrorServlet); + ctx.addServletMapping("/customErrorServlet", "customErrorServlet"); + + ErrorPage ep = new ErrorPage(); + ep.setLocation("/customErrorServlet"); + + ctx.addErrorPage(ep); + } + TesterAccessLogValve alv = new TesterAccessLogValve(); ctx.getPipeline().addValve(alv); @@ -1284,7 +1305,14 @@ public class TestAsyncContextImpl extend // responsibility when an error occurs on an application thread. // Calling sendError() followed by complete() and expecting the standard // error page mechanism to kick in could be viewed as handling the error - assertTrue(res.getLength() > 0); + String responseBody = res.toString(); + Assert.assertNotNull(responseBody); + assertTrue(responseBody.length() > 0); + if (customError) { + assertTrue(responseBody, responseBody.contains(CustomErrorServlet.ERROR_MESSAGE)); + } else { + assertTrue(responseBody, responseBody.contains(AsyncErrorServlet.ERROR_MESSAGE)); + } // Without this test may complete before access log has a chance to log // the request @@ -1295,6 +1323,21 @@ public class TestAsyncContextImpl extend REQUEST_TIME); } + private static class CustomErrorServlet extends GenericServlet { + + private static final long serialVersionUID = 1L; + + public static final String ERROR_MESSAGE = "Custom error page"; + + @Override + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + res.getWriter().println(ERROR_MESSAGE); + } + + } + + private static class AsyncErrorServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -1310,21 +1353,17 @@ public class TestAsyncContextImpl extend } @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) + protected void doGet(HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { - final AsyncContext actxt = req.startAsync(); + AsyncContext actxt = req.startAsync(); actxt.setTimeout(TIMEOUT); if (threaded) { actxt.start(new Runnable() { @Override public void run() { try { - HttpServletResponse resp = - (HttpServletResponse) actxt.getResponse(); resp.sendError(status, ERROR_MESSAGE); - // Complete so there is no delay waiting for the - // timeout actxt.complete(); } catch (IOException e) { // Ignore @@ -1332,7 +1371,8 @@ public class TestAsyncContextImpl extend } }); } else { - resp.sendError(status); + resp.sendError(status, ERROR_MESSAGE); + actxt.complete(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org