398467 Servlet 3.1 Non Blocking IO

cleaned up test harness
This commit is contained in:
Greg Wilkins 2013-05-28 23:29:38 +10:00
parent f03bc398f8
commit ce662c7ddc
3 changed files with 10 additions and 18 deletions

View File

@ -64,7 +64,7 @@ public class HttpChannelState
IDLE, // Idle request IDLE, // Idle request
DISPATCHED, // Request dispatched to filter/servlet DISPATCHED, // Request dispatched to filter/servlet
ASYNCWAIT, // Suspended and parked ASYNCWAIT, // Suspended and parked
ASYNCIO, // Has been scheduled ASYNCIO, // Has been dispatched for async IO
COMPLETING, // Request is completable COMPLETING, // Request is completable
COMPLETED // Request is complete COMPLETED // Request is complete
} }

View File

@ -642,10 +642,12 @@ write completed - - - ASYNC READY->owp
return false; return false;
} }
// TODO write comments
if (!_complete && _len<BufferUtil.space(_aggregate) && _len<_aggregate.capacity()/4) if (!_complete && _len<BufferUtil.space(_aggregate) && _len<_aggregate.capacity()/4)
{ {
BufferUtil.append(_aggregate, _b, _off, _len); BufferUtil.append(_aggregate, _b, _off, _len);
} }
// TODO write comments
else if (_len>0 && !_flushed) else if (_len>0 && !_flushed)
{ {
ByteBuffer buffer=ByteBuffer.wrap(_b, _off, _len); ByteBuffer buffer=ByteBuffer.wrap(_b, _off, _len);

View File

@ -27,6 +27,7 @@ import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -115,15 +116,9 @@ public class AsyncServletIOTest
@Test @Test
public void testBigWrites() throws Exception public void testBigWrites() throws Exception
{ {
List<String> list=process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400); _count.set(0);
int blocked=0; process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400);
for (String line:list) Assert.assertThat(_count.get(),Matchers.greaterThan(1));
{
if ("-".equals(line))
blocked++;
}
Assert.assertThat(blocked,Matchers.greaterThan(1));
} }
@ -207,7 +202,8 @@ public class AsyncServletIOTest
} }
static AtomicInteger _count = new AtomicInteger();
private static class AsyncIOServlet extends HttpServlet private static class AsyncIOServlet extends HttpServlet
{ {
@ -225,19 +221,16 @@ public class AsyncServletIOTest
final ServletOutputStream out = response.getOutputStream(); final ServletOutputStream out = response.getOutputStream();
out.setWriteListener(new WriteListener() out.setWriteListener(new WriteListener()
{ {
byte[] _owp="-\n".getBytes("ISO-8859-1");
int _w=0; int _w=0;
@Override @Override
public void onWritePossible() throws IOException public void onWritePossible() throws IOException
{ {
//System.err.println("OWP"); //System.err.println("OWP");
out.write(_owp); _count.incrementAndGet();
while (writes!=null && _w< writes.length) while (writes!=null && _w< writes.length)
{ {
if (!out.isReady())
return;
int write=Integer.valueOf(writes[_w++]); int write=Integer.valueOf(writes[_w++]);
if (write==0) if (write==0)
@ -253,9 +246,6 @@ public class AsyncServletIOTest
if (!out.isReady()) if (!out.isReady())
return; return;
} }
if (!out.isReady())
return;
//System.err.println("COMPLETE!!!"); //System.err.println("COMPLETE!!!");
async.complete(); async.complete();