Improved generate/parse tests.

This commit is contained in:
Simone Bordet 2015-12-09 11:56:49 +01:00
parent 35da4a3c54
commit e7d8980952
8 changed files with 152 additions and 112 deletions

View File

@ -130,18 +130,23 @@ public class DataGenerateParseTest
} }
}, 4096, 8192); }, 4096, 8192);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
ByteBuffer data = ByteBuffer.wrap(largeContent); for (int i = 0; i < 2; ++i)
generator.generateData(lease, 13, data.slice(), true, data.remaining());
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ ByteBuffer data = ByteBuffer.wrap(largeContent);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()})); 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());
}
} }
} }

View File

@ -96,21 +96,26 @@ public class GoAwayGenerateParseTest
byte[] payload = new byte[16]; byte[] payload = new byte[16];
new Random().nextBytes(payload); new Random().nextBytes(payload);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generateGoAway(lease, lastStreamId, error, payload); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generateGoAway(lease, lastStreamId, error, payload);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
GoAwayFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Assert.assertEquals(lastStreamId, frame.getLastStreamId()); {
Assert.assertEquals(error, frame.getError()); while (buffer.hasRemaining())
Assert.assertArrayEquals(payload, frame.getPayload()); {
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());
}
} }
} }

View File

@ -93,21 +93,26 @@ public class PingGenerateParseTest
byte[] payload = new byte[8]; byte[] payload = new byte[8];
new Random().nextBytes(payload); new Random().nextBytes(payload);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generatePing(lease, payload, true); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generatePing(lease, payload, true);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
PingFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Assert.assertArrayEquals(payload, frame.getPayload()); {
Assert.assertTrue(frame.isReply()); 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 @Test

View File

@ -98,22 +98,27 @@ public class PriorityGenerateParseTest
int weight = 3; int weight = 3;
boolean exclusive = true; boolean exclusive = true;
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generatePriority(lease, streamId, parentStreamId, weight, exclusive); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generatePriority(lease, streamId, parentStreamId, weight, exclusive);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
PriorityFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Assert.assertEquals(streamId, frame.getStreamId()); {
Assert.assertEquals(parentStreamId, frame.getParentStreamId()); while (buffer.hasRemaining())
Assert.assertEquals(weight, frame.getWeight()); {
Assert.assertEquals(exclusive, frame.isExclusive()); 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());
}
} }
} }

View File

@ -115,28 +115,33 @@ public class PushPromiseGenerateParseTest
fields.put("User-Agent", "Jetty"); fields.put("User-Agent", "Jetty");
MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields); 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); // Iterate a few times to be sure generator and parser are properly reset.
generator.generatePushPromise(lease, streamId, promisedStreamId, metaData); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
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()); Assert.assertEquals(1, frames.size());
PushPromiseFrame frame = frames.get(0); PushPromiseFrame frame = frames.get(0);
Assert.assertEquals(streamId, frame.getStreamId()); Assert.assertEquals(streamId, frame.getStreamId());
Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId()); Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId());
MetaData.Request request = (MetaData.Request)frame.getMetaData(); MetaData.Request request = (MetaData.Request)frame.getMetaData();
Assert.assertEquals(metaData.getMethod(), request.getMethod()); Assert.assertEquals(metaData.getMethod(), request.getMethod());
Assert.assertEquals(metaData.getURI(), request.getURI()); Assert.assertEquals(metaData.getURI(), request.getURI());
for (int j = 0; j < fields.size(); ++j) for (int j = 0; j < fields.size(); ++j)
{ {
HttpField field = fields.getField(j); HttpField field = fields.getField(j);
Assert.assertTrue(request.getFields().contains(field)); Assert.assertTrue(request.getFields().contains(field));
}
} }
} }
} }

View File

@ -92,20 +92,25 @@ public class ResetGenerateParseTest
int streamId = 13; int streamId = 13;
int error = 17; int error = 17;
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generateReset(lease, streamId, error); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generateReset(lease, streamId, error);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
ResetFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Assert.assertEquals(streamId, frame.getStreamId()); {
Assert.assertEquals(error, frame.getError()); 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());
}
} }
} }

View File

@ -155,22 +155,27 @@ public class SettingsGenerateParseTest
Integer value = 17; Integer value = 17;
settings1.put(key, value); settings1.put(key, value);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generateSettings(lease, settings1, true); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generateSettings(lease, settings1, true);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
SettingsFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Map<Integer, Integer> settings2 = frame.getSettings(); {
Assert.assertEquals(1, settings2.size()); while (buffer.hasRemaining())
Assert.assertEquals(value, settings2.get(key)); {
Assert.assertTrue(frame.isReply()); parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size());
SettingsFrame frame = frames.get(0);
Map<Integer, Integer> settings2 = frame.getSettings();
Assert.assertEquals(1, settings2.size());
Assert.assertEquals(value, settings2.get(key));
Assert.assertTrue(frame.isReply());
}
} }
} }

View File

@ -92,20 +92,25 @@ public class WindowUpdateGenerateParseTest
int streamId = 13; int streamId = 13;
int windowUpdate = 17; int windowUpdate = 17;
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); // Iterate a few times to be sure generator and parser are properly reset.
generator.generateWindowUpdate(lease, streamId, windowUpdate); for (int i = 0; i < 2; ++i)
for (ByteBuffer buffer : lease.getByteBuffers())
{ {
while (buffer.hasRemaining()) ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
{ generator.generateWindowUpdate(lease, streamId, windowUpdate);
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
}
}
Assert.assertEquals(1, frames.size()); frames.clear();
WindowUpdateFrame frame = frames.get(0); for (ByteBuffer buffer : lease.getByteBuffers())
Assert.assertEquals(streamId, frame.getStreamId()); {
Assert.assertEquals(windowUpdate, frame.getWindowDelta()); 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());
}
} }
} }