Author: markt Date: Mon Dec 5 09:02:54 2016 New Revision: 1772609 URL: http://svn.apache.org/viewvc?rev=1772609&view=rev Log: Add test for async dispatch
Modified: tomcat/trunk/test/org/apache/coyote/http2/TestStreamProcessor.java Modified: tomcat/trunk/test/org/apache/coyote/http2/TestStreamProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestStreamProcessor.java?rev=1772609&r1=1772608&r2=1772609&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestStreamProcessor.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestStreamProcessor.java Mon Dec 5 09:02:54 2016 @@ -76,7 +76,38 @@ public class TestStreamProcessor extends "3-Body-17\n" + "3-Body-8\n" + "3-EndOfStream\n", output.getTrace()); + } + + + @Test + public void testAsyncDispatch() throws Exception { + enableHttp2(); + + Tomcat tomcat = getTomcatInstance(); + + // Map the async servlet to /simple so we can re-use the HTTP/2 handling + // logic from the super class. + Context ctxt = tomcat.addContext("", null); + Tomcat.addServlet(ctxt, "simple", new SimpleServlet()); + ctxt.addServletMappingDecoded("/simple", "simple"); + Wrapper w = Tomcat.addServlet(ctxt, "async", new AsyncDispatch()); + w.setAsyncSupported(true); + ctxt.addServletMappingDecoded("/async", "async"); + + tomcat.start(); + + openClientConnection(); + doHttpUpgrade(); + sendClientPreface(); + validateHttp2InitialResponse(); + + byte[] frameHeader = new byte[9]; + ByteBuffer headersPayload = ByteBuffer.allocate(128); + buildGetRequest(frameHeader, headersPayload, null, 3, "/async"); + writeFrame(frameHeader, headersPayload); + readSimpleGetResponse(); + Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace()); } @@ -108,6 +139,30 @@ public class TestStreamProcessor extends } catch (Exception e) { e.printStackTrace(); } + } + }); + } + } + + + private static final class AsyncDispatch extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + final AsyncContext asyncContext = request.startAsync(request, response); + asyncContext.start(new Runnable() { + + @Override + public void run() { + try { + asyncContext.dispatch("/simple"); + } catch (Exception e) { + e.printStackTrace(); + } } }); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org