tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1382314 - in /tomcat/trunk: java/org/apache/coyote/AsyncStateMachine.java test/org/apache/catalina/core/TestAsyncContextImpl.java
Date Sat, 08 Sep 2012 15:08:41 GMT
Author: markt
Date: Sat Sep  8 15:08:40 2012
New Revision: 1382314

URL: http://svn.apache.org/viewvc?rev=1382314&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53843
request.isAsyncStarted() must continue to return true until the dispatch/complete actually
happens (which at the earliest isn't until the thread where startAsync() was called returns
to the container).

Modified:
    tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java
    tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java

Modified: tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java?rev=1382314&r1=1382313&r2=1382314&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java Sat Sep  8 15:08:40 2012
@@ -101,10 +101,10 @@ public class AsyncStateMachine<S> {
         DISPATCHED(false, false, false),
         STARTING(true, true, false),
         STARTED(true, true, false),
-        MUST_COMPLETE(true, false, false),
+        MUST_COMPLETE(true, true, false),
         COMPLETING(true, false, false),
         TIMING_OUT(true, false, false),
-        MUST_DISPATCH(true, false, true),
+        MUST_DISPATCH(true, true, true),
         DISPATCHING(true, false, true),
         READ_WRITE_OP(true,true,false),
         ERROR(true,false,false);

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=1382314&r1=1382313&r2=1382314&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java Sat Sep  8 15:08:40
2012
@@ -1367,4 +1367,90 @@ public class TestAsyncContextImpl extend
         }
     }
 
+    @Test
+    public void testBug53843() 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());
+        Bug53843ServletA servletA = new Bug53843ServletA();
+        Wrapper a = Tomcat.addServlet(ctx, "ServletA", servletA);
+        a.setAsyncSupported(true);
+        Tomcat.addServlet(ctx, "ServletB", new Bug53843ServletB());
+
+        ctx.addServletMapping("/ServletA", "ServletA");
+        ctx.addServletMapping("/ServletB", "ServletB");
+
+        tomcat.start();
+
+        StringBuilder url = new StringBuilder(48);
+        url.append("http://localhost:");
+        url.append(getPort());
+        url.append("/ServletA");
+
+        ByteChunk body = new ByteChunk();
+        int rc = getUrl(url.toString(), body, null);
+
+        assertEquals(HttpServletResponse.SC_OK, rc);
+        assertEquals("OK", body.toString());
+        assertTrue(servletA.isAsyncWhenExpected());
+    }
+
+    private static class Bug53843ServletA extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private boolean isAsyncWhenExpected = true;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            // Should not be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && !req.isAsyncStarted();
+
+            final AsyncContext async = req.startAsync();
+
+            // Should be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && req.isAsyncStarted();
+
+            async.start(new Runnable() {
+
+                @Override
+                public void run() {
+                    // This should be delayed until the original container
+                    // thread exists
+                    async.dispatch("/ServletB");
+                }
+            });
+
+            try {
+                Thread.sleep(3000);
+            } catch (InterruptedException e) {
+                throw new ServletException(e);
+            }
+
+            // Should be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && req.isAsyncStarted();
+        }
+
+        public boolean isAsyncWhenExpected() {
+            return isAsyncWhenExpected;
+        }
+    }
+
+    private static class Bug53843ServletB extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/plain");
+            resp.getWriter().print("OK");
+        }
+    }
 }



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


Mime
View raw message