use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming1.
@Test
public void testPacketTrimming1() {
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);
assertEquals(2, w.getResultPackets().size());
List<?> l = w.getResultPackets();
assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
assertEquals(10, ((QueryResultPacket) l.get(1)).getOffset());
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPartialOverlap.
@Test
public void testPartialOverlap() {
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);
// all docs at once
List<?> l = w.getDocuments(0, 20);
assertNotNull(l);
assertEquals(20, l.size());
int n = 0;
for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
DocumentInfo d = (DocumentInfo) i.next();
assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
}
// too far out into the result set
l = w.getDocuments(15, 10);
assertNull(l);
// only from first subdivision
l = w.getDocuments(3, 2);
assertNotNull(l);
assertEquals(2, l.size());
n = 3;
for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
DocumentInfo d = (DocumentInfo) i.next();
assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
}
// only from second subdivision
l = w.getDocuments(15, 5);
assertNotNull(l);
assertEquals(5, l.size());
n = 15;
for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
DocumentInfo d = (DocumentInfo) i.next();
assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
}
// overshoot by 1
l = w.getDocuments(15, 6);
assertNull(l);
// mixed subset
l = w.getDocuments(3, 12);
assertNotNull(l);
assertEquals(12, l.size());
n = 3;
for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
DocumentInfo d = (DocumentInfo) i.next();
assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
}
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class MockFSChannel method receivePackets.
public BasicPacket[] receivePackets(long timeout, int packetCount) {
List<BasicPacket> packets = new java.util.ArrayList<>();
if (lastReceived instanceof QueryPacket) {
lastQueryPacket = (QueryPacket) lastReceived;
QueryResultPacket result = QueryResultPacket.create();
result.setDocstamp(docstamp);
result.setChannel(0);
result.setTotalDocumentCount(2);
result.setOffset(lastQueryPacket.getOffset());
if (lastQueryPacket.getOffset() == 0 && lastQueryPacket.getLastOffset() >= 1) {
result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(123), 2003, 234, 1000));
}
if (lastQueryPacket.getOffset() <= 1 && lastQueryPacket.getLastOffset() >= 2) {
result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(456), 1855, 234, 1001));
}
packets.add(result);
} else if (lastReceived instanceof GetDocSumsPacket) {
addDocsums(packets, lastQueryPacket);
} else if (lastReceived instanceof PingPacket) {
packets.add(new PongPacket(activeDocuments));
}
while (packetCount >= 0 && packets.size() > packetCount) {
packets.remove(packets.size() - 1);
}
return packets.toArray(new BasicPacket[packets.size()]);
}
Aggregations