From 51631c2a46718715687034b89adec809adaf722c Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 19 Sep 2014 10:33:09 +0200 Subject: [PATCH] Made the test more robust, avoiding WritePendingExceptions. --- .../jetty/http2/client/FlowControlTest.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/FlowControlTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/FlowControlTest.java index 7ce625d6ea6..4daf0b9e3d3 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/FlowControlTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/FlowControlTest.java @@ -648,9 +648,20 @@ public class FlowControlTest extends AbstractTest session.newStream(requestFrame, streamPromise, new Stream.Listener.Adapter()); Stream stream = streamPromise.get(5, TimeUnit.SECONDS); ByteBuffer data = ByteBuffer.allocate(FlowControl.DEFAULT_WINDOW_SIZE); - stream.data(new DataFrame(stream.getId(), data, false), Callback.Adapter.INSTANCE); + final CountDownLatch dataLatch = new CountDownLatch(1); + stream.data(new DataFrame(stream.getId(), data, false), new Callback.Adapter() + { + @Override + public void succeeded() + { + dataLatch.countDown(); + } + }); + Assert.assertTrue(dataLatch.await(5, TimeUnit.SECONDS)); - // Now the client is supposed to not send more frames, but what if it does ? + + // Now the client is supposed to not send more frames. + // If it does, the connection must be closed. HTTP2Session http2Session = (HTTP2Session)session; ByteBufferPool.Lease lease = new ByteBufferPool.Lease(connector.getByteBufferPool()); ByteBuffer extraData = ByteBuffer.allocate(1024); @@ -695,9 +706,19 @@ public class FlowControlTest extends AbstractTest session.newStream(requestFrame, streamPromise, new Stream.Listener.Adapter()); Stream stream = streamPromise.get(5, TimeUnit.SECONDS); ByteBuffer data = ByteBuffer.allocate(FlowControl.DEFAULT_WINDOW_SIZE); - stream.data(new DataFrame(stream.getId(), data, false), Callback.Adapter.INSTANCE); + final CountDownLatch dataLatch = new CountDownLatch(1); + stream.data(new DataFrame(stream.getId(), data, false), new Callback.Adapter() + { + @Override + public void succeeded() + { + dataLatch.countDown(); + } + }); + Assert.assertTrue(dataLatch.await(5, TimeUnit.SECONDS)); - // Now the client is supposed to not send more frames, but what if it does ? + // Now the client is supposed to not send more frames. + // If it does, the connection must be closed. HTTP2Session http2Session = (HTTP2Session)session; ByteBufferPool.Lease lease = new ByteBufferPool.Lease(connector.getByteBufferPool()); ByteBuffer extraData = ByteBuffer.allocate(1024);