Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-02-03 23:58:57 +0000
committerGreg Wilkins2015-02-03 23:58:57 +0000
commitbe127ee0cfaab8ed806773b28ad24a3297824ffa (patch)
tree2b2ede98c516ae9068e3325eb96a9290fdf956ca /jetty-servlet
parent56ff29568fc76232c5372c5a489b38e5b32fcae3 (diff)
downloadorg.eclipse.jetty.project-be127ee0cfaab8ed806773b28ad24a3297824ffa.tar.gz
org.eclipse.jetty.project-be127ee0cfaab8ed806773b28ad24a3297824ffa.tar.xz
org.eclipse.jetty.project-be127ee0cfaab8ed806773b28ad24a3297824ffa.zip
added test for async IO isNotReadyAtEOF
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java
index 79140ef097..7031e7f3f4 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java
@@ -27,6 +27,7 @@ import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+
import javax.servlet.AsyncContext;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
@@ -411,4 +412,90 @@ public class AsyncIOServletTest
if (!latch.await(5, TimeUnit.SECONDS))
Assert.fail();
}
+
+
+ @Test
+ public void testIsNotReadyAtEOF() throws Exception
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+ String text = "Now is the winter of our discontent. How Now Brown Cow. The quick brown fox jumped over the lazy dog.\n";
+ final byte[] data = text.getBytes(StandardCharsets.ISO_8859_1);
+
+ startServer(new HttpServlet()
+ {
+ @Override
+ protected void service(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
+ {
+ response.flushBuffer();
+
+ final AsyncContext async = request.startAsync();
+ final ServletInputStream in = request.getInputStream();
+ final ServletOutputStream out = response.getOutputStream();
+
+ in.setReadListener(new ReadListener()
+ {
+ transient int _i=0;
+ transient boolean _minusOne=false;;
+ transient boolean _finished=false;;
+
+ @Override
+ public void onError(Throwable t)
+ {
+ t.printStackTrace();
+ async.complete();
+ }
+
+ @Override
+ public void onDataAvailable() throws IOException
+ {
+ while(in.isReady())
+ {
+ int b = in.read();
+ if (b==-1)
+ _minusOne=true;
+ else if (data[_i++]!=b)
+ throw new IllegalStateException();
+ }
+
+ if (in.isFinished())
+ _finished=true;
+ }
+
+ @Override
+ public void onAllDataRead() throws IOException
+ {
+ out.write(String.format("i=%d eof=%b finished=%b",_i,_minusOne,_finished).getBytes(StandardCharsets.ISO_8859_1));
+ async.complete();
+ }
+ });
+ }
+ });
+
+ String request = "GET " + path + " HTTP/1.1\r\n" +
+ "Host: localhost:" + connector.getLocalPort() + "\r\n" +
+ "Content-Type: text/plain\r\n"+
+ "Content-Length: "+data.length+"\r\n" +
+ "\r\n";
+
+ try (Socket client = new Socket("localhost", connector.getLocalPort()))
+ {
+ OutputStream output = client.getOutputStream();
+ output.write(request.getBytes("UTF-8"));
+ output.write(data);
+ output.flush();
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
+ String line=in.readLine();
+ assertThat(line, containsString("200 OK"));
+ while (line.length()>0)
+ line=in.readLine();
+ line=in.readLine();
+ assertThat(line, not(containsString(" ")));
+ line=in.readLine();
+ assertThat(line, containsString("i="+data.length+" eof=false finished=true"));
+ }
+
+ if (!latch.await(5, TimeUnit.SECONDS))
+ Assert.fail();
+ }
}

Back to the top