Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-08-13 04:44:25 -0400
committerGreg Wilkins2015-08-13 04:44:25 -0400
commit108821aacbd363d8eb1cf5a9eeed1476dbec49e9 (patch)
tree5dfec6d6937f23938736a8bf3edec64aae14e691 /jetty-servlet
parent8c0e4f53d3c7f6e6370c51f65b5d74a0a2f051a2 (diff)
downloadorg.eclipse.jetty.project-108821aacbd363d8eb1cf5a9eeed1476dbec49e9.tar.gz
org.eclipse.jetty.project-108821aacbd363d8eb1cf5a9eeed1476dbec49e9.tar.xz
org.eclipse.jetty.project-108821aacbd363d8eb1cf5a9eeed1476dbec49e9.zip
474634 - AsyncListener.onError() handling.
Fixed more tests in jetty-servlets
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java33
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncIOServletTest.java6
2 files changed, 24 insertions, 15 deletions
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
index 11485cacae..ce254a7ada 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
@@ -24,7 +24,10 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
@@ -68,7 +71,7 @@ public class AsyncContextListenersTest
@Test
public void testListenerClearedOnSecondRequest() throws Exception
{
- final AtomicInteger completes = new AtomicInteger();
+ final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
String path = "/path";
prepare(path, new HttpServlet()
{
@@ -86,7 +89,7 @@ public class AsyncContextListenersTest
@Override
public void onComplete(AsyncEvent event) throws IOException
{
- completes.incrementAndGet();
+ completes.get().countDown();
}
@Override
@@ -118,23 +121,23 @@ public class AsyncContextListenersTest
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
// Send a second request
- completes.set(0);
+ completes.set(new CountDownLatch(1));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
}
}
@Test
public void testListenerAddedFromListener() throws Exception
{
- final AtomicInteger completes = new AtomicInteger();
+ final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
String path = "/path";
prepare(path, new HttpServlet()
{
@@ -157,7 +160,7 @@ public class AsyncContextListenersTest
@Override
public void onComplete(AsyncEvent event) throws IOException
{
- completes.incrementAndGet();
+ completes.get().countDown();
}
@Override
@@ -189,22 +192,22 @@ public class AsyncContextListenersTest
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
// Send a second request
- completes.set(0);
+ completes.set(new CountDownLatch(1));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
}
}
@Test
public void testAsyncDispatchAsyncCompletePreservesListener() throws Exception
{
- final AtomicInteger completes = new AtomicInteger();
+ final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
final String path = "/path";
prepare(path + "/*", new HttpServlet()
{
@@ -226,7 +229,7 @@ public class AsyncContextListenersTest
@Override
public void onComplete(AsyncEvent event) throws IOException
{
- completes.incrementAndGet();
+ completes.get().countDown();
}
@Override
@@ -267,16 +270,16 @@ public class AsyncContextListenersTest
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
// Send a second request
- completes.set(0);
+ completes.set(new CountDownLatch(1));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
- Assert.assertEquals(1, completes.get());
+ completes.get().await(10,TimeUnit.SECONDS);
}
}
}
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 d99055ff40..057278b08e 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
@@ -245,6 +245,12 @@ public class AsyncIOServletTest
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
+ if (request.getDispatcherType()==DispatcherType.ERROR)
+ {
+ response.flushBuffer();
+ return;
+ }
+
final AsyncContext asyncContext = request.startAsync(request, response);
request.getInputStream().setReadListener(new ReadListener()
{

Back to the top