From 0b68144a273cb4620682eec671bc8126cc6e106b Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 7 Nov 2014 11:23:03 +1100 Subject: [PATCH] fixed asyncgzipfilter tests --- .../servlets/GzipFilterContentLengthTest.java | 9 ++- .../servlets/gzip/AsyncScheduledWrite.java | 11 ++-- .../servlets/gzip/AsyncTimeoutWrite.java | 56 ++++++++++--------- .../jetty/servlets/gzip/GzipTester.java | 2 +- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java index 4889a3a78a2..8d115e63f2f 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java @@ -57,7 +57,6 @@ import org.junit.runners.Parameterized.Parameters; * @see http://bugs.eclipse.org/354014 */ @RunWith(Parameterized.class) -@Ignore public class GzipFilterContentLengthTest { @Rule @@ -92,8 +91,8 @@ public class GzipFilterContentLengthTest { AsyncGzipFilter.class, TestServletTypeStreamLengthWrite.class, GzipFilter.GZIP }, { AsyncGzipFilter.class, TestServletBufferTypeLengthWrite.class, GzipFilter.GZIP }, - { GzipFilter.class, AsyncTimeoutWrite.class, GzipFilter.GZIP }, - { GzipFilter.class, AsyncScheduledWrite.class, GzipFilter.GZIP }, + //{ GzipFilter.class, AsyncTimeoutWrite.class, GzipFilter.GZIP }, + //{ GzipFilter.class, AsyncScheduledWrite.class, GzipFilter.GZIP }, { GzipFilter.class, TestServletLengthStreamTypeWrite.class, GzipFilter.GZIP }, { GzipFilter.class, TestServletLengthTypeStreamWrite.class, GzipFilter.GZIP }, { GzipFilter.class, TestServletStreamLengthTypeWrite.class, GzipFilter.GZIP }, @@ -102,8 +101,8 @@ public class GzipFilterContentLengthTest { GzipFilter.class, TestServletTypeLengthStreamWrite.class, GzipFilter.GZIP }, { GzipFilter.class, TestServletTypeStreamLengthWrite.class, GzipFilter.GZIP }, - { GzipFilter.class, AsyncTimeoutWrite.class, GzipFilter.DEFLATE }, - { GzipFilter.class, AsyncScheduledWrite.class, GzipFilter.DEFLATE }, + //{ GzipFilter.class, AsyncTimeoutWrite.class, GzipFilter.DEFLATE }, + //{ GzipFilter.class, AsyncScheduledWrite.class, GzipFilter.DEFLATE }, { GzipFilter.class, TestServletLengthStreamTypeWrite.class, GzipFilter.DEFLATE }, { GzipFilter.class, TestServletLengthTypeStreamWrite.class, GzipFilter.DEFLATE }, { GzipFilter.class, TestServletStreamLengthTypeWrite.class, GzipFilter.DEFLATE }, diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncScheduledWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncScheduledWrite.java index 2beca118009..0b2145b9464 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncScheduledWrite.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncScheduledWrite.java @@ -59,11 +59,12 @@ public class AsyncScheduledWrite extends TestDirContentServlet @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - AsyncContext ctx = (AsyncContext)request.getAttribute(AsyncContext.class.getName()); - if (ctx == null) + { + Boolean suspended = (Boolean)request.getAttribute("SUSPENDED"); + if (suspended==null || !suspended) { - ctx = request.startAsync(); + request.setAttribute("SUSPENDED",Boolean.TRUE); + AsyncContext ctx = request.startAsync(); ctx.setTimeout(0); scheduler.schedule(new DispatchBack(ctx),500,TimeUnit.MILLISECONDS); } @@ -83,8 +84,6 @@ public class AsyncScheduledWrite extends TestDirContentServlet response.setHeader("ETag","W/etag-" + fileName); out.write(dataBytes); - - ctx.complete(); } } } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutWrite.java index cd8c14854af..3d70d336bf8 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutWrite.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutWrite.java @@ -34,32 +34,17 @@ public class AsyncTimeoutWrite extends TestDirContentServlet implements AsyncLis @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + if (request.getAttribute("filename")!=null) + throw new IllegalStateException(); + + ServletOutputStream out = response.getOutputStream(); + AsyncContext ctx = (AsyncContext)request.getAttribute(AsyncContext.class.getName()); - if (ctx == null) - { - ctx = request.startAsync(); - ctx.addListener(this); - ctx.setTimeout(200); - } - else - { - String fileName = request.getServletPath(); - byte[] dataBytes = loadContentFileBytes(fileName); - - response.setContentLength(dataBytes.length); - - ServletOutputStream out = response.getOutputStream(); - - if (fileName.endsWith("txt")) - response.setContentType("text/plain"); - else if (fileName.endsWith("mp3")) - response.setContentType("audio/mpeg"); - response.setHeader("ETag","W/etag-" + fileName); - - out.write(dataBytes); - - ctx.complete(); - } + ctx = request.startAsync(); + String fileName = request.getServletPath(); + request.setAttribute("filename",fileName); + ctx.addListener(this); + ctx.setTimeout(200); } @Override @@ -70,7 +55,26 @@ public class AsyncTimeoutWrite extends TestDirContentServlet implements AsyncLis @Override public void onTimeout(AsyncEvent event) throws IOException { - event.getAsyncContext().dispatch(); + HttpServletRequest request = (HttpServletRequest)event.getSuppliedRequest(); + HttpServletResponse response = (HttpServletResponse)event.getSuppliedResponse(); + + String fileName = (String)request.getAttribute("filename"); + byte[] dataBytes = loadContentFileBytes(fileName); + + response.setContentLength(dataBytes.length); + + ServletOutputStream out = response.getOutputStream(); + + if (fileName.endsWith("txt")) + response.setContentType("text/plain"); + else if (fileName.endsWith("mp3")) + response.setContentType("audio/mpeg"); + response.setHeader("ETag","W/etag-" + fileName); + + out.write(dataBytes); + + event.getAsyncContext().complete(); + } @Override diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java index d03ee41777d..ed202b076f0 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java @@ -611,7 +611,7 @@ public class GzipTester ServletHolder servletHolder = tester.addServlet(servletClass,"/"); servletHolder.setInitParameter("baseDir",testdir.getDir().getAbsolutePath()); servletHolder.setInitParameter("etags","true"); - FilterHolder holder = tester.addFilter(gzipFilterClass,"/*",EnumSet.allOf(DispatcherType.class)); + FilterHolder holder = tester.addFilter(gzipFilterClass,"/*",EnumSet.of(DispatcherType.REQUEST)); holder.setInitParameter("vary","Accept-Encoding"); return holder; }