Search in sources :

Example 11 with QueryResultPacket

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());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Example 12 with QueryResultPacket

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());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Example 13 with QueryResultPacket

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());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Example 14 with QueryResultPacket

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());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) DecodedPacket(com.yahoo.fs4.PacketDecoder.DecodedPacket) PacketDecoder(com.yahoo.fs4.PacketDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with QueryResultPacket

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());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) DecodedPacket(com.yahoo.fs4.PacketDecoder.DecodedPacket) PacketDecoder(com.yahoo.fs4.PacketDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

QueryResultPacket (com.yahoo.fs4.QueryResultPacket)28 Test (org.junit.Test)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)16 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)16 Query (com.yahoo.search.Query)16 BasicPacket (com.yahoo.fs4.BasicPacket)7 DocumentInfo (com.yahoo.fs4.DocumentInfo)7 ByteBuffer (java.nio.ByteBuffer)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2 PacketDecoder (com.yahoo.fs4.PacketDecoder)2 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryPacket (com.yahoo.fs4.QueryPacket)2 Result (com.yahoo.search.Result)2 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 Packet (com.yahoo.fs4.Packet)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1