You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/04/16 23:41:38 UTC

svn commit: r1094061 - /tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java

Author: markt
Date: Sat Apr 16 21:41:38 2011
New Revision: 1094061

URL: http://svn.apache.org/viewvc?rev=1094061&view=rev
Log:
Additional test case to check access log and return code when error servlet does not flush the response.

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=1094061&r1=1094060&r2=1094061&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java Sat Apr 16 21:41:38 2011
@@ -851,7 +851,7 @@ public class TestAsyncContextImpl extend
         wrapper.setAsyncSupported(true);
         ctx.addServletMapping("/stage1", "dispatch");
 
-        ErrorServlet error = new ErrorServlet();
+        ErrorServlet error = new ErrorServlet(true);
         Tomcat.addServlet(ctx, "error", error);
         ctx.addServletMapping("/stage2", "error");
 
@@ -897,11 +897,19 @@ public class TestAsyncContextImpl extend
 
         private static final long serialVersionUID = 1L;
 
+        private boolean flush = false;
+
+        public ErrorServlet(boolean flush) {
+            this.flush = flush;
+        }
+        
         @Override
         protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
             resp.getWriter().write("ErrorServletGet-");
-            resp.flushBuffer();
+            if (flush) {
+                resp.flushBuffer();
+            }
             throw new ServletException("Opps.");
         }
     }
@@ -1044,4 +1052,45 @@ public class TestAsyncContextImpl extend
             }); 
         }
     }
+
+    public void testErrorHandling() throws Exception {
+        // Setup Tomcat instance
+        Tomcat tomcat = getTomcatInstance();
+        
+        // Must have a real docBase - just use temp
+        File docBase = new File(System.getProperty("java.io.tmpdir"));
+        
+        Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
+
+        ErrorServlet error = new ErrorServlet(false);
+        Tomcat.addServlet(ctx, "error", error);
+        ctx.addServletMapping("/error", "error");
+
+        TesterAccessLogValve alv = new TesterAccessLogValve();
+        ctx.getPipeline().addValve(alv);
+        
+        tomcat.start();
+        
+        StringBuilder url = new StringBuilder(48);
+        url.append("http://localhost:");
+        url.append(getPort());
+        url.append("/error");
+        
+        int rc = getUrl(url.toString(), new ByteChunk(), null);
+        
+        assertEquals(500, rc);
+        
+        // Without this test may complete before access log has a chance to log
+        // the request
+        Thread.sleep(REQUEST_TIME);
+        
+        // Check the access log
+        List<Entry> entries = alv.getEntries();
+        assertEquals(1, entries.size());
+        Entry entry = entries.get(0);
+        assertEquals(500, entry.getStatus());
+        assertTrue(entry.toString(), entry.getTime() > 0);
+        assertTrue(entry.toString(), entry.getTime() < REQUEST_TIME);
+
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org