474634 - AsyncListener.onError() handling.
Fixed more tests in jetty-servlets
This commit is contained in:
parent
8c0e4f53d3
commit
108821aacb
|
@ -24,7 +24,10 @@ import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
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.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
import javax.servlet.AsyncEvent;
|
import javax.servlet.AsyncEvent;
|
||||||
|
@ -68,7 +71,7 @@ public class AsyncContextListenersTest
|
||||||
@Test
|
@Test
|
||||||
public void testListenerClearedOnSecondRequest() throws Exception
|
public void testListenerClearedOnSecondRequest() throws Exception
|
||||||
{
|
{
|
||||||
final AtomicInteger completes = new AtomicInteger();
|
final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
|
||||||
String path = "/path";
|
String path = "/path";
|
||||||
prepare(path, new HttpServlet()
|
prepare(path, new HttpServlet()
|
||||||
{
|
{
|
||||||
|
@ -86,7 +89,7 @@ public class AsyncContextListenersTest
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(AsyncEvent event) throws IOException
|
public void onComplete(AsyncEvent event) throws IOException
|
||||||
{
|
{
|
||||||
completes.incrementAndGet();
|
completes.get().countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,23 +121,23 @@ public class AsyncContextListenersTest
|
||||||
SimpleHttpParser parser = new SimpleHttpParser();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(new CountDownLatch(1));
|
||||||
output.write(request.getBytes(StandardCharsets.UTF_8));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerAddedFromListener() throws Exception
|
public void testListenerAddedFromListener() throws Exception
|
||||||
{
|
{
|
||||||
final AtomicInteger completes = new AtomicInteger();
|
final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
|
||||||
String path = "/path";
|
String path = "/path";
|
||||||
prepare(path, new HttpServlet()
|
prepare(path, new HttpServlet()
|
||||||
{
|
{
|
||||||
|
@ -157,7 +160,7 @@ public class AsyncContextListenersTest
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(AsyncEvent event) throws IOException
|
public void onComplete(AsyncEvent event) throws IOException
|
||||||
{
|
{
|
||||||
completes.incrementAndGet();
|
completes.get().countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -189,22 +192,22 @@ public class AsyncContextListenersTest
|
||||||
SimpleHttpParser parser = new SimpleHttpParser();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(new CountDownLatch(1));
|
||||||
output.write(request.getBytes(StandardCharsets.UTF_8));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testAsyncDispatchAsyncCompletePreservesListener() throws Exception
|
public void testAsyncDispatchAsyncCompletePreservesListener() throws Exception
|
||||||
{
|
{
|
||||||
final AtomicInteger completes = new AtomicInteger();
|
final AtomicReference<CountDownLatch> completes = new AtomicReference<>(new CountDownLatch(1));
|
||||||
final String path = "/path";
|
final String path = "/path";
|
||||||
prepare(path + "/*", new HttpServlet()
|
prepare(path + "/*", new HttpServlet()
|
||||||
{
|
{
|
||||||
|
@ -226,7 +229,7 @@ public class AsyncContextListenersTest
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(AsyncEvent event) throws IOException
|
public void onComplete(AsyncEvent event) throws IOException
|
||||||
{
|
{
|
||||||
completes.incrementAndGet();
|
completes.get().countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -267,16 +270,16 @@ public class AsyncContextListenersTest
|
||||||
SimpleHttpParser parser = new SimpleHttpParser();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(new CountDownLatch(1));
|
||||||
output.write(request.getBytes(StandardCharsets.UTF_8));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
Assert.assertEquals(1, completes.get());
|
completes.get().await(10,TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,12 @@ public class AsyncIOServletTest
|
||||||
@Override
|
@Override
|
||||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
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);
|
final AsyncContext asyncContext = request.startAsync(request, response);
|
||||||
request.getInputStream().setReadListener(new ReadListener()
|
request.getInputStream().setReadListener(new ReadListener()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue