tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1478543 - /tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java
Date Thu, 02 May 2013 20:59:47 GMT
Author: markt
Date: Thu May  2 20:59:45 2013
New Revision: 1478543

URL: http://svn.apache.org/r1478543
Log:
Fix test. Can't continue writing to output after an async complete

Modified:
    tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java?rev=1478543&r1=1478542&r2=1478543&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java Thu May  2
20:59:45 2013
@@ -76,16 +76,20 @@ public class TestCoyoteOutputStream exte
 
         Context root = tomcat.addContext("", TEMP_DIR);
         Wrapper w = Tomcat.addServlet(root, "nbWrite",
-                new NonBlockingWriteServlet(asyncWriteTarget, syncWriteTarget));
+                new NonBlockingWriteServlet(asyncWriteTarget));
         w.setAsyncSupported(true);
-        root.addServletMapping("/", "nbWrite");
+        root.addServletMapping("/nbWrite", "nbWrite");
+        Tomcat.addServlet(root, "write",
+                new BlockingWriteServlet(asyncWriteTarget, syncWriteTarget));
+        w.setAsyncSupported(true);
+        root.addServletMapping("/write", "write");
 
         tomcat.start();
 
         ByteChunk bc = new ByteChunk();
         // Extend timeout to 5 mins for debugging
-        int rc = getUrl("http://localhost:" + getPort() + "/", bc, 300000, null,
-                null);
+        int rc = getUrl("http://localhost:" + getPort() + "/nbWrite", bc,
+                300000, null, null);
 
         int totalCount = asyncWriteTarget + syncWriteTarget;
         StringBuilder sb = new StringBuilder(totalCount * 16);
@@ -103,14 +107,12 @@ public class TestCoyoteOutputStream exte
     private static final class NonBlockingWriteServlet extends HttpServlet {
 
         private static final long serialVersionUID = 1L;
+
         private final int asyncWriteTarget;
-        private final int syncWriteTarget;
         private final AtomicInteger asyncWriteCount = new AtomicInteger(0);
 
-        public NonBlockingWriteServlet(int asyncWriteTarget,
-                int syncWriteTarget) {
+        public NonBlockingWriteServlet(int asyncWriteTarget) {
             this.asyncWriteTarget = asyncWriteTarget;
-            this.syncWriteTarget = syncWriteTarget;
         }
 
         @Override
@@ -138,22 +140,12 @@ public class TestCoyoteOutputStream exte
                                     B2CConverter.UTF_8));
                     sos.flush();
                 } else {
-                    doSyncWrite(asyncCtxt, sos);
+                    asyncCtxt.dispatch("/write");
                     break;
                 }
             }
         }
 
-        private void doSyncWrite(AsyncContext asyncCtxt,
-                ServletOutputStream sos) throws IOException {
-            asyncCtxt.complete();
-            for (int i = asyncWriteTarget;
-                    i < syncWriteTarget + asyncWriteTarget; i++) {
-                sos.write(("OK - " + i + System.lineSeparator()).getBytes(
-                        B2CConverter.UTF_8));
-            }
-        }
-
         private class AsyncTask implements Runnable {
 
             private final AsyncContext asyncCtxt;
@@ -197,4 +189,31 @@ public class TestCoyoteOutputStream exte
             }
         }
     }
+
+    private static final class BlockingWriteServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private final int start;
+        private final int len;
+
+        public BlockingWriteServlet(int start, int len) {
+            this.start = start;
+            this.len = len;
+        }
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            resp.setContentType("text/plain");
+            resp.setCharacterEncoding("UTF-8");
+            ServletOutputStream sos = resp.getOutputStream();
+
+            for (int i = start; i < start + len; i++) {
+                sos.write(("OK - " + i + System.lineSeparator()).getBytes(
+                        B2CConverter.UTF_8));
+            }
+        }
+    }
 }



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


Mime
View raw message