diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java index 655c59a9600..f86e132fb2e 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java @@ -39,7 +39,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import javax.servlet.AsyncContext; -import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.WriteListener; import javax.servlet.http.HttpServlet; @@ -941,7 +940,7 @@ public class StreamResetTest extends AbstractTest start(new EmptyHttpServlet() { @Override - protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException { if (request.getPathInfo().equals("/1")) service1(request, response); @@ -1039,18 +1038,15 @@ public class StreamResetTest extends AbstractTest Thread.sleep(1000); // Let the request write, it should not block. requestLatch2.countDown(); - assertTrue(writeLatch1.await(555, TimeUnit.SECONDS)); + assertTrue(writeLatch1.await(5, TimeUnit.SECONDS)); } } private void waitUntilTCPCongested(WriteFlusher flusher) throws TimeoutException, InterruptedException { long start = System.nanoTime(); - while (true) + while (!flusher.isPending()) { - // Yuck! But no other easy way to detect this. - if ("P".equals(flusher.toStateString())) - break; long elapsed = System.nanoTime() - start; if (TimeUnit.NANOSECONDS.toSeconds(elapsed) > 15) throw new TimeoutException(); diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java index cd1e2a06ac6..743f0a1fcef 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java @@ -258,7 +258,7 @@ public abstract class WriteFlusher */ public void write(Callback callback, ByteBuffer... buffers) throws WritePendingException { - callback = Objects.requireNonNull(callback); + Objects.requireNonNull(callback); if (isFailed()) { @@ -523,12 +523,22 @@ public abstract class WriteFlusher boolean isFailed() { - return _state.get().getType() == StateType.FAILED; + return isState(StateType.FAILED); } boolean isIdle() { - return _state.get().getType() == StateType.IDLE; + return isState(StateType.IDLE); + } + + public boolean isPending() + { + return isState(StateType.PENDING); + } + + private boolean isState(StateType type) + { + return _state.get().getType() == type; } public String toStateString()