Author: markt
Date: Thu Sep  5 22:40:50 2013
New Revision: 1520447

URL: http://svn.apache.org/r1520447
Log:
Add a simple non-blocking write test that currently fails. This won't impact 
the CI systems since the class is excluded from the unit tests.

Modified:
    
tomcat/trunk/test/org/apache/catalina/nonblocking/TesterAjpNonBlockingClient.java

Modified: 
tomcat/trunk/test/org/apache/catalina/nonblocking/TesterAjpNonBlockingClient.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/nonblocking/TesterAjpNonBlockingClient.java?rev=1520447&r1=1520446&r2=1520447&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/nonblocking/TesterAjpNonBlockingClient.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/nonblocking/TesterAjpNonBlockingClient.java
 Thu Sep  5 22:40:50 2013
@@ -16,10 +16,15 @@
  */
 package org.apache.catalina.nonblocking;
 
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.net.SocketFactory;
 import javax.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
@@ -29,14 +34,14 @@ import org.apache.catalina.nonblocking.T
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.ByteChunk;
 
+/**
+ * This is not a standard set of unit tests. This is a set of test clients for
+ * AJP support of Servlet 3.1 non-blocking IO. It assumes that there is an 
httpd
+ * instance listening on localhost:80 that is redirecting all traffic to a
+ * default Tomcat 8 instance that includes the examples web application.
+ */
 public class TesterAjpNonBlockingClient extends TomcatBaseTest {
 
-    /**
-     * This is not a standard unit test. This is a test client for AJP
-     * non-blocking reads. It assumes that there is an httpd instance listening
-     * on localhost:80 that is redirecting all traffic to a default Tomcat 8
-     * instance that includes the examples web application.
-     */
     @Test
     public void doTestAJPNonBlockingRead() throws Exception {
 
@@ -50,4 +55,47 @@ public class TesterAjpNonBlockingClient 
 
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
     }
+
+
+    @Test
+    public void testNonBlockingWrite() throws Exception {
+
+        SocketFactory factory = SocketFactory.getDefault();
+        Socket s = factory.createSocket("localhost", 80);
+
+        ByteChunk result = new ByteChunk();
+        OutputStream os = s.getOutputStream();
+        os.write(("GET /examples/servlets/nonblocking/numberwriter 
HTTP/1.1\r\n" +
+                "Host: localhost\r\n" +
+                "Connection: close\r\n" +
+                "\r\n").getBytes(StandardCharsets.ISO_8859_1));
+        os.flush();
+
+        InputStream is = s.getInputStream();
+        byte[] buffer = new byte[8192];
+
+        int read = 0;
+        int readSinceLastPause = 0;
+        while (read != -1) {
+            read = is.read(buffer);
+            if (read > 0) {
+                result.append(buffer, 0, read);
+            }
+            readSinceLastPause += read;
+            if (readSinceLastPause > 40000) {
+                readSinceLastPause = 0;
+                Thread.sleep(500);
+            }
+        }
+
+        os.close();
+        is.close();
+        s.close();
+
+        // Validate the result
+        String resultString = result.toString();
+        log.info("Client read " + resultString.length() + " bytes");
+
+        Assert.assertTrue(resultString.contains("00000000000000010000"));
+    }
 }



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

Reply via email to