use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming9.
@Test
public void testPacketTrimming9() {
CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
PacketWrapper w = createResult(key, 0, 10, 100);
QueryResultPacket q = createQueryResultPacket(10, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(11, 9, 100);
w.addResultPacket(q);
q = createQueryResultPacket(20, 10, 100);
w.addResultPacket(q);
assertEquals(3, w.getResultPackets().size());
List<?> l = w.getResultPackets();
assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
assertEquals(10, ((QueryResultPacket) l.get(1)).getOffset());
assertEquals(20, ((QueryResultPacket) l.get(2)).getOffset());
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming12.
@Test
public void testPacketTrimming12() {
CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
PacketWrapper w = createResult(key, 0, 10, 100);
QueryResultPacket q = createQueryResultPacket(4, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(12, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(16, 10, 100);
w.addResultPacket(q);
assertEquals(4, w.getResultPackets().size());
q = createQueryResultPacket(8, 10, 100);
w.addResultPacket(q);
assertEquals(3, w.getResultPackets().size());
List<?> l = w.getResultPackets();
assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
assertEquals(8, ((QueryResultPacket) l.get(1)).getOffset());
assertEquals(16, ((QueryResultPacket) l.get(2)).getOffset());
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming6.
@Test
public void testPacketTrimming6() {
CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
PacketWrapper w = createResult(key, 0, 10, 100);
QueryResultPacket q = createQueryResultPacket(5, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(10, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(60, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(65, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(70, 10, 100);
w.addResultPacket(q);
assertEquals(4, w.getResultPackets().size());
List<?> l = w.getResultPackets();
assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
assertEquals(10, ((QueryResultPacket) l.get(1)).getOffset());
assertEquals(60, ((QueryResultPacket) l.get(2)).getOffset());
assertEquals(70, ((QueryResultPacket) l.get(3)).getOffset());
}
use of com.yahoo.fs4.QueryResultPacket 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.QueryResultPacket 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());
}
Aggregations