diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/DataGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/DataGenerateParseTest.java index dd7f83760d8..2db99624324 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/DataGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/DataGenerateParseTest.java @@ -130,18 +130,23 @@ public class DataGenerateParseTest } }, 4096, 8192); - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - ByteBuffer data = ByteBuffer.wrap(largeContent); - generator.generateData(lease, 13, data.slice(), true, data.remaining()); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + ByteBuffer data = ByteBuffer.wrap(largeContent); + generator.generateData(lease, 13, data.slice(), true, data.remaining()); - Assert.assertEquals(largeContent.length, frames.size()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(largeContent.length, frames.size()); + } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/GoAwayGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/GoAwayGenerateParseTest.java index b53225a36ec..a51874170e5 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/GoAwayGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/GoAwayGenerateParseTest.java @@ -96,21 +96,26 @@ public class GoAwayGenerateParseTest byte[] payload = new byte[16]; new Random().nextBytes(payload); - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generateGoAway(lease, lastStreamId, error, payload); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generateGoAway(lease, lastStreamId, error, payload); - Assert.assertEquals(1, frames.size()); - GoAwayFrame frame = frames.get(0); - Assert.assertEquals(lastStreamId, frame.getLastStreamId()); - Assert.assertEquals(error, frame.getError()); - Assert.assertArrayEquals(payload, frame.getPayload()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + GoAwayFrame frame = frames.get(0); + Assert.assertEquals(lastStreamId, frame.getLastStreamId()); + Assert.assertEquals(error, frame.getError()); + Assert.assertArrayEquals(payload, frame.getPayload()); + } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PingGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PingGenerateParseTest.java index b3e85aeab48..96f20c17742 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PingGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PingGenerateParseTest.java @@ -93,21 +93,26 @@ public class PingGenerateParseTest byte[] payload = new byte[8]; new Random().nextBytes(payload); - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generatePing(lease, payload, true); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generatePing(lease, payload, true); - Assert.assertEquals(1, frames.size()); - PingFrame frame = frames.get(0); - Assert.assertArrayEquals(payload, frame.getPayload()); - Assert.assertTrue(frame.isReply()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + PingFrame frame = frames.get(0); + Assert.assertArrayEquals(payload, frame.getPayload()); + Assert.assertTrue(frame.isReply()); + } } @Test diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PriorityGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PriorityGenerateParseTest.java index 44dbc0cebba..664c4dd181b 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PriorityGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PriorityGenerateParseTest.java @@ -98,22 +98,27 @@ public class PriorityGenerateParseTest int weight = 3; boolean exclusive = true; - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generatePriority(lease, streamId, parentStreamId, weight, exclusive); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generatePriority(lease, streamId, parentStreamId, weight, exclusive); - Assert.assertEquals(1, frames.size()); - PriorityFrame frame = frames.get(0); - Assert.assertEquals(streamId, frame.getStreamId()); - Assert.assertEquals(parentStreamId, frame.getParentStreamId()); - Assert.assertEquals(weight, frame.getWeight()); - Assert.assertEquals(exclusive, frame.isExclusive()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + PriorityFrame frame = frames.get(0); + Assert.assertEquals(streamId, frame.getStreamId()); + Assert.assertEquals(parentStreamId, frame.getParentStreamId()); + Assert.assertEquals(weight, frame.getWeight()); + Assert.assertEquals(exclusive, frame.isExclusive()); + } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java index 78a08f9796d..fd3d50c68f4 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java @@ -115,28 +115,33 @@ public class PushPromiseGenerateParseTest fields.put("User-Agent", "Jetty"); MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields); - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generatePushPromise(lease, streamId, promisedStreamId, metaData); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generatePushPromise(lease, streamId, promisedStreamId, metaData); + + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } } - } - Assert.assertEquals(1, frames.size()); - PushPromiseFrame frame = frames.get(0); - Assert.assertEquals(streamId, frame.getStreamId()); - Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId()); - MetaData.Request request = (MetaData.Request)frame.getMetaData(); - Assert.assertEquals(metaData.getMethod(), request.getMethod()); - Assert.assertEquals(metaData.getURI(), request.getURI()); - for (int j = 0; j < fields.size(); ++j) - { - HttpField field = fields.getField(j); - Assert.assertTrue(request.getFields().contains(field)); + Assert.assertEquals(1, frames.size()); + PushPromiseFrame frame = frames.get(0); + Assert.assertEquals(streamId, frame.getStreamId()); + Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId()); + MetaData.Request request = (MetaData.Request)frame.getMetaData(); + Assert.assertEquals(metaData.getMethod(), request.getMethod()); + Assert.assertEquals(metaData.getURI(), request.getURI()); + for (int j = 0; j < fields.size(); ++j) + { + HttpField field = fields.getField(j); + Assert.assertTrue(request.getFields().contains(field)); + } } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/ResetGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/ResetGenerateParseTest.java index 66633e64e2f..8936c5372f1 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/ResetGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/ResetGenerateParseTest.java @@ -92,20 +92,25 @@ public class ResetGenerateParseTest int streamId = 13; int error = 17; - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generateReset(lease, streamId, error); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generateReset(lease, streamId, error); - Assert.assertEquals(1, frames.size()); - ResetFrame frame = frames.get(0); - Assert.assertEquals(streamId, frame.getStreamId()); - Assert.assertEquals(error, frame.getError()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + ResetFrame frame = frames.get(0); + Assert.assertEquals(streamId, frame.getStreamId()); + Assert.assertEquals(error, frame.getError()); + } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/SettingsGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/SettingsGenerateParseTest.java index 15343f406ca..c0a7ee633a7 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/SettingsGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/SettingsGenerateParseTest.java @@ -155,22 +155,27 @@ public class SettingsGenerateParseTest Integer value = 17; settings1.put(key, value); - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generateSettings(lease, settings1, true); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generateSettings(lease, settings1, true); - Assert.assertEquals(1, frames.size()); - SettingsFrame frame = frames.get(0); - Map settings2 = frame.getSettings(); - Assert.assertEquals(1, settings2.size()); - Assert.assertEquals(value, settings2.get(key)); - Assert.assertTrue(frame.isReply()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + SettingsFrame frame = frames.get(0); + Map settings2 = frame.getSettings(); + Assert.assertEquals(1, settings2.size()); + Assert.assertEquals(value, settings2.get(key)); + Assert.assertTrue(frame.isReply()); + } } } diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/WindowUpdateGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/WindowUpdateGenerateParseTest.java index 3cd2e6bdcc8..1a53d241e0f 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/WindowUpdateGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/WindowUpdateGenerateParseTest.java @@ -92,20 +92,25 @@ public class WindowUpdateGenerateParseTest int streamId = 13; int windowUpdate = 17; - ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); - generator.generateWindowUpdate(lease, streamId, windowUpdate); - - for (ByteBuffer buffer : lease.getByteBuffers()) + // Iterate a few times to be sure generator and parser are properly reset. + for (int i = 0; i < 2; ++i) { - while (buffer.hasRemaining()) - { - parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); - } - } + ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); + generator.generateWindowUpdate(lease, streamId, windowUpdate); - Assert.assertEquals(1, frames.size()); - WindowUpdateFrame frame = frames.get(0); - Assert.assertEquals(streamId, frame.getStreamId()); - Assert.assertEquals(windowUpdate, frame.getWindowDelta()); + frames.clear(); + for (ByteBuffer buffer : lease.getByteBuffers()) + { + while (buffer.hasRemaining()) + { + parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); + } + } + + Assert.assertEquals(1, frames.size()); + WindowUpdateFrame frame = frames.get(0); + Assert.assertEquals(streamId, frame.getStreamId()); + Assert.assertEquals(windowUpdate, frame.getWindowDelta()); + } } }