From ce662c7ddc57346468d86744130d4f1d84344670 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 28 May 2013 23:29:38 +1000 Subject: [PATCH] 398467 Servlet 3.1 Non Blocking IO cleaned up test harness --- .../jetty/server/HttpChannelState.java | 2 +- .../org/eclipse/jetty/server/HttpOutput.java | 2 ++ .../jetty/servlet/AsyncServletIOTest.java | 24 ++++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java index 7acd906aa77..e8e69b42c10 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java @@ -64,7 +64,7 @@ public class HttpChannelState IDLE, // Idle request DISPATCHED, // Request dispatched to filter/servlet ASYNCWAIT, // Suspended and parked - ASYNCIO, // Has been scheduled + ASYNCIO, // Has been dispatched for async IO COMPLETING, // Request is completable COMPLETED // Request is complete } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java index ba842ee11b2..c0d572fb5a8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java @@ -642,10 +642,12 @@ write completed - - - ASYNC READY->owp return false; } + // TODO write comments if (!_complete && _len0 && !_flushed) { ByteBuffer buffer=ByteBuffer.wrap(_b, _off, _len); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletIOTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletIOTest.java index cb7a936fa69..c8cf55ea2cf 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletIOTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletIOTest.java @@ -27,6 +27,7 @@ import java.net.Socket; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.AsyncContext; import javax.servlet.ServletException; @@ -115,15 +116,9 @@ public class AsyncServletIOTest @Test public void testBigWrites() throws Exception { - List list=process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400); - int blocked=0; - for (String line:list) - { - if ("-".equals(line)) - blocked++; - } - - Assert.assertThat(blocked,Matchers.greaterThan(1)); + _count.set(0); + process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400); + Assert.assertThat(_count.get(),Matchers.greaterThan(1)); } @@ -207,7 +202,8 @@ public class AsyncServletIOTest } - + + static AtomicInteger _count = new AtomicInteger(); private static class AsyncIOServlet extends HttpServlet { @@ -225,19 +221,16 @@ public class AsyncServletIOTest final ServletOutputStream out = response.getOutputStream(); out.setWriteListener(new WriteListener() { - byte[] _owp="-\n".getBytes("ISO-8859-1"); int _w=0; @Override public void onWritePossible() throws IOException { //System.err.println("OWP"); - out.write(_owp); + _count.incrementAndGet(); while (writes!=null && _w< writes.length) { - if (!out.isReady()) - return; int write=Integer.valueOf(writes[_w++]); if (write==0) @@ -253,9 +246,6 @@ public class AsyncServletIOTest if (!out.isReady()) return; } - - if (!out.isReady()) - return; //System.err.println("COMPLETE!!!"); async.complete();