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 2013/05/01 11:38:54 UTC

svn commit: r1477939 - /tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java

Author: markt
Date: Wed May  1 09:38:53 2013
New Revision: 1477939

URL: http://svn.apache.org/r1477939
Log:
Take the PrintWriter out of the test - it adds too much buffering which makes figuring out what the non-blocking API is meant to be doing harder than it needs to be.
Increase the timeouts to allow debugging.

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=1477939&r1=1477938&r2=1477939&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteOutputStream.java Wed May  1 09:38:53 2013
@@ -17,7 +17,6 @@
 package org.apache.catalina.connector;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.servlet.AsyncContext;
@@ -35,6 +34,7 @@ import org.apache.catalina.Context;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 public class TestCoyoteOutputStream extends TomcatBaseTest {
@@ -83,7 +83,8 @@ public class TestCoyoteOutputStream exte
         tomcat.start();
 
         ByteChunk bc = new ByteChunk();
-        int rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
+        // Extend timeout to 5 mins for debugging
+        int rc = getUrl("http://localhost:" + getPort() + "/", bc, 300000, null, null);
 
         int totalCount = asyncWriteTarget + syncWriteTarget;
         StringBuilder sb = new StringBuilder(totalCount * 16);
@@ -121,17 +122,20 @@ public class TestCoyoteOutputStream exte
 
 
             AsyncContext asyncCtxt = req.startAsync();
+            // Inifinite timeout for debugging
+            asyncCtxt.setTimeout(0);
             asyncCtxt.start(new AsyncTask(asyncCtxt, sos));
         }
 
         private void doAsyncWrite(AsyncContext asyncCtxt,
-                ServletOutputStream sos) {
-            PrintWriter pw = new PrintWriter(sos);
+                ServletOutputStream sos) throws IOException {
             while (sos.isReady()) {
                 int next = asyncWriteCount.getAndIncrement();
                 if (next < asyncWriteTarget) {
-                    pw.println("OK - " + next);
-                    pw.flush();
+                    sos.write(
+                            ("OK - " + next + System.lineSeparator()).getBytes(
+                                    B2CConverter.UTF_8));
+                    sos.flush();
                 } else {
                     doSyncWrite(asyncCtxt, sos);
                     break;
@@ -140,13 +144,12 @@ public class TestCoyoteOutputStream exte
         }
 
         private void doSyncWrite(AsyncContext asyncCtxt,
-                ServletOutputStream sos) {
+                ServletOutputStream sos) throws IOException {
             asyncCtxt.complete();
-            PrintWriter pw = new PrintWriter(sos);
             for (int i = asyncWriteTarget;
                     i < syncWriteTarget + asyncWriteTarget; i++) {
-                pw.println("OK - " + i);
-                pw.flush();
+                sos.write(("OK - " + i + System.lineSeparator()).getBytes(
+                        B2CConverter.UTF_8));
             }
         }
 
@@ -163,7 +166,11 @@ public class TestCoyoteOutputStream exte
             @Override
             public void run() {
                 sos.setWriteListener(new MyWriteListener(asyncCtxt, sos));
-                doAsyncWrite(asyncCtxt, sos);
+                try {
+                    doAsyncWrite(asyncCtxt, sos);
+                } catch (IOException ioe) {
+                    throw new RuntimeException(ioe);
+                }
             }
         }
 



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