use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.
the class TestAsyncContextImpl method testBug50352.
@Test
public void testBug50352() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartRunnable servlet = new AsyncStartRunnable();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
getUrl("http://localhost:" + getPort() + "/");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "Runnable-onComplete-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 200, AsyncStartRunnable.THREAD_SLEEP_TIME, AsyncStartRunnable.THREAD_SLEEP_TIME + REQUEST_TIME);
}
use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.
the class TestAsyncContextImpl method testAsyncStartWithComplete.
@Test
public void testAsyncStartWithComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartWithCompleteServlet servlet = new AsyncStartWithCompleteServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
ByteChunk bc = new ByteChunk();
Map<String, List<String>> headers = new HashMap<>();
getUrl("http://localhost:" + getPort() + "/", bc, headers);
assertEquals("OK", bc.toString());
List<String> contentLength = headers.get("Content-Length");
Assert.assertNotNull(contentLength);
Assert.assertEquals(1, contentLength.size());
Assert.assertEquals("2", contentLength.get(0));
// Check the access log
alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.
the class TestAsyncContextImpl method testAsyncStartNoComplete.
@Test
public void testAsyncStartNoComplete() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// Minimise pauses during test
tomcat.getConnector().setAttribute("connectionTimeout", Integer.valueOf(3000));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartNoCompleteServlet servlet = new AsyncStartNoCompleteServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet the first time
getUrl("http://localhost:" + getPort() + "/?echo=run1");
Assert.assertEquals("OK-run1", getTrack());
resetTracker();
// Call the servlet the second time with a request parameter
getUrl("http://localhost:" + getPort() + "/?echo=run2");
Assert.assertEquals("OK-run2", getTrack());
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
// Check the access log
alv.validateAccessLog(2, 500, AsyncStartNoCompleteServlet.ASYNC_TIMEOUT, AsyncStartNoCompleteServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
}
use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.
the class TestAsyncContextImpl method testListeners.
@Test
public void testListeners() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
TrackingServlet tracking = new TrackingServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "tracking", tracking);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage1", "tracking");
TimeoutServlet timeout = new TimeoutServlet(Boolean.TRUE, null);
Wrapper wrapper2 = Tomcat.addServlet(ctx, "timeout", timeout);
wrapper2.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage2", "timeout");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/stage1");
getUrl(url.toString());
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "DispatchingServletGet-DispatchingServletGet-" + "onStartAsync-TimeoutServletGet-onStartAsync-onTimeout-" + "onComplete-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
Assert.assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 200, TimeoutServlet.ASYNC_TIMEOUT, TimeoutServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
}
use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.
the class TestAsyncContextImpl method testAsyncContextListenerClearing.
// https://bz.apache.org/bugzilla/show_bug.cgi?id=57326
@Test
public void testAsyncContextListenerClearing() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Servlet stage1 = new DispatchingServletTracking("/stage2", true);
Wrapper wrapper1 = Tomcat.addServlet(ctx, "stage1", stage1);
wrapper1.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage1", "stage1");
Servlet stage2 = new DispatchingServletTracking("/stage3", false);
Wrapper wrapper2 = Tomcat.addServlet(ctx, "stage2", stage2);
wrapper2.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage2", "stage2");
Servlet stage3 = new NonAsyncServlet();
Tomcat.addServlet(ctx, "stage3", stage3);
ctx.addServletMappingDecoded("/stage3", "stage3");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
getUrl("http://localhost:" + getPort() + "/stage1");
assertEquals("doGet-startAsync-doGet-startAsync-onStartAsync-NonAsyncServletGet-onComplete-", getTrack());
// Check the access log
alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
Aggregations