Author: remm Date: Wed Feb 20 10:48:18 2019 New Revision: 1853948 URL: http://svn.apache.org/viewvc?rev=1853948&view=rev Log: Improve test
Modified: tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java Modified: tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java?rev=1853948&r1=1853947&r2=1853948&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java (original) +++ tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java Wed Feb 20 10:48:18 2019 @@ -58,6 +58,7 @@ import org.apache.catalina.startup.Tomca import org.apache.catalina.startup.TomcatBaseTest; import org.apache.catalina.valves.TesterAccessLogValve; import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.net.ContainerThreadMarker; public class TestNonBlockingAPI extends TomcatBaseTest { @@ -121,6 +122,7 @@ public class TestNonBlockingAPI extends "http://localhost:" + getPort() + "/", new ByteChunk(), resHeaders, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); + Assert.assertEquals(2000000 * 8, servlet.listener.body.length()); } @@ -465,6 +467,7 @@ public class TestNonBlockingAPI extends private static final long serialVersionUID = 1L; private final boolean async; private final boolean ignoreIsReady; + TestReadListener listener; public NBReadServlet(boolean ignoreIsReady, boolean async) { this.async = async; @@ -504,7 +507,6 @@ public class TestNonBlockingAPI extends }); // step 2 - notify on read ServletInputStream in = req.getInputStream(); - TestReadListener listener; if (async) { listener = new TestAsyncReadListener(actx, false, ignoreIsReady); } else { @@ -634,7 +636,7 @@ public class TestNonBlockingAPI extends @Override public void onError(Throwable throwable) { - log.info("ReadListener.onError"); + log.info("ReadListener.onError totalData=" + body.toString().length()); throwable.printStackTrace(); onErrorInvoked = true; } @@ -642,6 +644,11 @@ public class TestNonBlockingAPI extends private class TestAsyncReadListener extends TestReadListener { + volatile int isReadyCount = 0; + volatile int notReadyCount = 0; + volatile int containerThreadCount = 0; + volatile int nonContainerThreadCount = 0; + public TestAsyncReadListener(AsyncContext ctx, boolean usingNonBlockingWrite, boolean ignoreIsReady) { super(ctx, usingNonBlockingWrite, ignoreIsReady); @@ -649,6 +656,11 @@ public class TestNonBlockingAPI extends @Override public void onDataAvailable() throws IOException { + if (ContainerThreadMarker.isContainerThread()) { + containerThreadCount++; + } else { + nonContainerThreadCount++; + } new Thread() { @Override public void run() { @@ -664,7 +676,13 @@ public class TestNonBlockingAPI extends synchronized (body) { body.append(s); } - if (ignoreIsReady || in.isReady()) { + boolean isReady = ignoreIsReady || in.isReady(); + if (isReady) { + isReadyCount++; + } else { + notReadyCount++; + } + if (isReady) { onDataAvailable(); } } catch (IOException e) { @@ -674,7 +692,21 @@ public class TestNonBlockingAPI extends }.start(); } + @Override + public void onAllDataRead() { + super.onAllDataRead(); + log.info("isReadyCount=" + isReadyCount + " notReadyCount=" + notReadyCount + + " containerThreadCount=" + containerThreadCount + + " nonContainerThreadCount=" + nonContainerThreadCount); + } + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + log.info("isReadyCount=" + isReadyCount + " notReadyCount=" + notReadyCount + + " containerThreadCount=" + containerThreadCount + + " nonContainerThreadCount=" + nonContainerThreadCount); + } } private class TestWriteListener implements WriteListener { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org