use of com.yahoo.fs4.Packet 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.Packet 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.Packet 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());
}
use of com.yahoo.fs4.Packet in project vespa by vespa-engine.
the class QueryResultTestCase method testDecodeQueryResultMoreHits.
@Test
public void testDecodeQueryResultMoreHits() {
byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
ByteBuffer buffer = ByteBuffer.allocate(200);
buffer.put(packetData);
buffer.flip();
BasicPacket packet = PacketDecoder.decode(buffer);
assertTrue(packet instanceof QueryResultPacket);
QueryResultPacket result = (QueryResultPacket) packet;
assertEquals(2, result.getDocuments().size());
DocumentInfo document1 = result.getDocuments().get(0);
assertEquals(gid1, document1.getGlobalId());
DocumentInfo document2 = result.getDocuments().get(1);
assertEquals(gid2, document2.getGlobalId());
assertEquals(6, result.getNodesQueried());
assertEquals(5, result.getNodesReplied());
}
use of com.yahoo.fs4.Packet in project vespa by vespa-engine.
the class QueryResultTestCase method testDecodeQueryResultX.
@Test
public void testDecodeQueryResultX() {
byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
ByteBuffer buffer = ByteBuffer.allocate(200);
buffer.put(packetData);
buffer.flip();
BasicPacket packet = PacketDecoder.decode(buffer);
assertTrue(packet instanceof QueryResultPacket);
QueryResultPacket result = (QueryResultPacket) packet;
assertTrue(result.getMldFeature());
assertEquals(5, result.getTotalDocumentCount());
assertEquals(25, result.getMaxRank());
assertEquals(111, result.getDocstamp());
assertEquals(89, result.getCoverageDocs());
assertEquals(90, result.getActiveDocs());
assertEquals(91, result.getSoonActiveDocs());
assertEquals(1, result.getDegradedReason());
assertEquals(2, result.getDocuments().size());
DocumentInfo document1 = result.getDocuments().get(0);
assertEquals(gid1, document1.getGlobalId());
assertEquals(23.0, document1.getMetric(), delta);
assertEquals(7, document1.getPartId());
assertEquals(36, document1.getDistributionKey());
DocumentInfo document2 = result.getDocuments().get(1);
assertEquals(gid2, document2.getGlobalId());
assertEquals(21.0, document2.getMetric(), delta);
assertEquals(8, document2.getPartId());
assertEquals(37, document2.getDistributionKey());
}
Aggregations