483427 - AsyncContext complete while pending async Reads/Writes

improved unit test
This commit is contained in:
Greg Wilkins 2015-12-04 10:10:12 +11:00
parent 5afa348aaa
commit ae9dc7922d

View File

@ -614,6 +614,9 @@ public class AsyncServletIOTest
@Test @Test
public void testCompleteWhilePending() throws Exception public void testCompleteWhilePending() throws Exception
{ {
_servlet4.onDA.set(0);
_servlet4.onWP.set(0);
StringBuilder request = new StringBuilder(512); StringBuilder request = new StringBuilder(512);
request.append("POST /ctx/path4/info HTTP/1.1\r\n") request.append("POST /ctx/path4/info HTTP/1.1\r\n")
.append("Host: localhost\r\n") .append("Host: localhost\r\n")
@ -674,7 +677,7 @@ public class AsyncServletIOTest
} }
catch(IOException e) catch(IOException e)
{ {
// ignored
} }
LOG.debug("last: "+last); LOG.debug("last: "+last);
@ -686,8 +689,8 @@ public class AsyncServletIOTest
assertTrue(_servlet4.completed.await(5, TimeUnit.SECONDS)); assertTrue(_servlet4.completed.await(5, TimeUnit.SECONDS));
Thread.sleep(100); Thread.sleep(100);
assertEquals(2,_servlet4.onDA.get()); assertEquals(0,_servlet4.onDA.get());
assertEquals(2,_servlet4.onWP.get()); assertEquals(0,_servlet4.onWP.get());
} }
@ -708,7 +711,6 @@ public class AsyncServletIOTest
in.setReadListener(new ReadListener() in.setReadListener(new ReadListener()
{ {
@Override @Override
public void onError(Throwable t) public void onError(Throwable t)
{ {
@ -719,16 +721,21 @@ public class AsyncServletIOTest
public void onDataAvailable() throws IOException public void onDataAvailable() throws IOException
{ {
onDA.incrementAndGet(); onDA.incrementAndGet();
if (onDA.get()>2)
return;
boolean readF=false;
// Read all available content // Read all available content
while(in.isReady()) while(in.isReady())
if (in.read()<0) {
int c = in.read();
if (c<0)
throw new IllegalStateException(); throw new IllegalStateException();
if (c=='F')
readF=true;
}
if (onDA.get()==1) if (readF)
return; {
onDA.set(0);
final byte[] buffer = new byte[64*1024]; final byte[] buffer = new byte[64*1024];
Arrays.fill(buffer,(byte)'X'); Arrays.fill(buffer,(byte)'X');
@ -742,18 +749,14 @@ public class AsyncServletIOTest
public void onWritePossible() throws IOException public void onWritePossible() throws IOException
{ {
onWP.incrementAndGet(); onWP.incrementAndGet();
if (onWP.get()>2)
return;
while (out.isReady()) while (out.isReady())
out.write(buffer); out.write(buffer);
if (onWP.get()==1)
return;
try try
{ {
// As soon as we are write blocked, complete // As soon as we are write blocked, complete
onWP.set(0);
async.complete(); async.complete();
} }
catch(Exception e) catch(Exception e)
@ -773,6 +776,7 @@ public class AsyncServletIOTest
} }
}); });
} }
}
@Override @Override
public void onAllDataRead() throws IOException public void onAllDataRead() throws IOException