use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class GetDocSumsPacketTestCase method assertPacket.
private static void assertPacket(boolean sendQuery, Result result, byte[] expected) throws BufferTooSmallException {
GetDocSumsPacket packet = GetDocSumsPacket.create(result, "default", sendQuery);
ByteBuffer buf = ByteBuffer.allocate(1024);
packet.encode(buf);
buf.flip();
byte[] actual = new byte[buf.remaining()];
buf.get(actual);
// assertEquals(Arrays.toString(expected), Arrays.toString(actual));
assertEquals("Equal length", expected.length, actual.length);
for (int i = 0; i < expected.length; ++i) {
if (expected[i] == IGNORE) {
actual[i] = IGNORE;
}
}
assertArrayEquals(expected, actual);
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class PacketDecoderTestCase method testPartialWithMoreRoom.
/**
* In this testcase we have a partial packet and room for
* more data
*/
@Test
public void testPartialWithMoreRoom() throws BufferTooSmallException {
ByteBuffer data = ByteBuffer.allocate(len);
data.put(queryResultPacketData, 0, 10);
data.flip();
PacketDecoder.DecodedPacket p = PacketDecoder.extractPacket(data);
assertTrue(p == null);
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class PacketDecoderTestCase method testOneAndAHalfPackets.
/**
* In this testcase we have one and a half packet
*/
@Test
public void testOneAndAHalfPackets() throws BufferTooSmallException {
int half = len / 2;
ByteBuffer data = ByteBuffer.allocate(len + half);
data.put(queryResultPacketData);
data.put(queryResultPacketData, 0, half);
assertEquals((len + half), data.position());
data.flip();
// the first packet we should be able to extract just fine
BasicPacket p1 = PacketDecoder.extractPacket(data).packet;
assertTrue(p1 instanceof QueryResultPacket);
PacketDecoder.DecodedPacket p2 = PacketDecoder.extractPacket(data);
assertTrue(p2 == null);
// at this point the buffer should be ready for more
// reading so position should be at the end and limit
// should be at capacity
assertEquals(half, data.position());
assertEquals(data.capacity(), data.limit());
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class PacketDecoderTestCase method testOnePacket.
/**
* In this testcase we have exactly one packet which fills the
* entire buffer
*/
@Test
public void testOnePacket() throws BufferTooSmallException {
ByteBuffer data = ByteBuffer.allocate(len);
data.put(queryResultPacketData);
data.flip();
// not really necessary for testing, but these help visualize
// the state the buffer should be in so a reader of this test
// will not have to
assertEquals(0, data.position());
assertEquals(len, data.limit());
assertEquals(len, data.capacity());
assertEquals(data.limit(), data.capacity());
PacketDecoder.DecodedPacket p = PacketDecoder.extractPacket(data);
assertTrue(p.packet instanceof QueryResultPacket);
// now the buffer should have position == capacity == limit
assertEquals(len, data.position());
assertEquals(len, data.limit());
assertEquals(len, data.capacity());
// next call to decode on same bufer should result
// in null and buffer should be reset for writing.
p = PacketDecoder.extractPacket(data);
assertTrue(p == null);
// make sure the buffer is now ready for reading
assertEquals(0, data.position());
assertEquals(len, data.limit());
assertEquals(len, data.capacity());
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class PacketDecoderTestCase method testThreeBytesPacket.
/**
* In this testcase we only have 3 bytes so we can't
* even determine the size of the packet.
*/
@Test
public void testThreeBytesPacket() throws BufferTooSmallException {
ByteBuffer data = ByteBuffer.allocate(len);
data.put(queryResultPacketData, 0, 3);
data.flip();
// packetLength() should return -1 since we don't even have
// the size of the packet
assertEquals(-1, PacketDecoder.packetLength(data));
// since we can't determine the size we don't get a packet.
// the buffer should now be at offset 3 so we can read more
// data and limit should be set to capacity
PacketDecoder.DecodedPacket p = PacketDecoder.extractPacket(data);
assertTrue(p == null);
assertEquals(3, data.position());
assertEquals(len, data.limit());
assertEquals(len, data.capacity());
}
Aggregations