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 2012/08/30 20:32:18 UTC

svn commit: r1379047 - /tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java

Author: markt
Date: Thu Aug 30 18:32:17 2012
New Revision: 1379047

URL: http://svn.apache.org/viewvc?rev=1379047&view=rev
Log:
Implement fall-back for checking for failure when socket is closed before client can read response. Fixes intermittent issue on Windows.

Modified:
    tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java

Modified: tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java?rev=1379047&r1=1379046&r2=1379047&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java Thu Aug 30 18:32:17 2012
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
@@ -102,7 +104,8 @@ public class TestChunkedInputFilter exte
         Context ctx =
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
 
-        Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet());
+        EchoHeaderServlet servlet = new EchoHeaderServlet();
+        Tomcat.addServlet(ctx, "servlet", servlet);
         ctx.addServletMapping("/", "servlet");
 
         tomcat.start();
@@ -131,14 +134,28 @@ public class TestChunkedInputFilter exte
         client.setRequest(request);
 
         client.connect();
-        client.processRequest();
+        Exception processException = null;
+        try {
+            client.processRequest();
+        } catch (Exception e) {
+            // Socket was probably closed before client had a chance to read
+            // response
+            processException = e;
+        }
 
         if (expectPass) {
             assertTrue(client.isResponse200());
             assertEquals("nullnull7TestValue1TestValue2",
                     client.getResponseBody());
+            assertNull(processException);
+            assertFalse(servlet.getExceptionDuringRead());
         } else {
-            assertTrue(client.getResponseLine(), client.isResponse500());
+            if (processException == null) {
+                assertTrue(client.getResponseLine(), client.isResponse500());
+            } else {
+                // Use fall-back for checking the error occurred
+                assertTrue(servlet.getExceptionDuringRead());
+            }
         }
     }
 
@@ -226,6 +243,8 @@ public class TestChunkedInputFilter exte
     private static class EchoHeaderServlet extends HttpServlet {
         private static final long serialVersionUID = 1L;
 
+        private boolean exceptionDuringRead = false;
+
         @Override
         protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
@@ -238,8 +257,13 @@ public class TestChunkedInputFilter exte
             // Read the body - quick and dirty
             InputStream is = req.getInputStream();
             int count = 0;
-            while (is.read() > -1) {
-                count++;
+            try {
+                while (is.read() > -1) {
+                    count++;
+                }
+            } catch (IOException ioe) {
+                exceptionDuringRead = true;
+                throw ioe;
             }
 
             pw.write(Integer.valueOf(count).toString());
@@ -249,6 +273,10 @@ public class TestChunkedInputFilter exte
             dumpHeader("x-trailer2", req, pw);
         }
 
+        public boolean getExceptionDuringRead() {
+            return exceptionDuringRead;
+        }
+
         private void dumpHeader(String headerName, HttpServletRequest req,
                 PrintWriter pw) {
             String value = req.getHeader(headerName);



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