Search in sources :

Example 11 with BasicPacket

use of com.yahoo.fs4.BasicPacket 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()]);
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) PingPacket(com.yahoo.fs4.PingPacket) PongPacket(com.yahoo.fs4.PongPacket) QueryPacket(com.yahoo.fs4.QueryPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 12 with BasicPacket

use of com.yahoo.fs4.BasicPacket in project vespa by vespa-engine.

the class PacketCacheTestCase method createCacheEntry.

/**
 * Creates a 64-byte packet in an array wrapped in a PacketWrapper
 */
private PacketWrapper createCacheEntry(CacheKey key) throws BufferTooSmallException {
    ByteBuffer data = ByteBuffer.allocate(length);
    data.put(queryResultPacketData);
    data.flip();
    BasicPacket[] content = new BasicPacket[] { PacketDecoder.extractPacket(data).packet };
    return new PacketWrapper(key, content);
}
Also used : BasicPacket(com.yahoo.fs4.BasicPacket) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BasicPacket (com.yahoo.fs4.BasicPacket)12 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)7 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)4 DocumentInfo (com.yahoo.fs4.DocumentInfo)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)3 PingPacket (com.yahoo.fs4.PingPacket)3 Packet (com.yahoo.fs4.Packet)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryPacket (com.yahoo.fs4.QueryPacket)2 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)2 IOException (java.io.IOException)2 PacketDecoder (com.yahoo.fs4.PacketDecoder)1 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)1 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)1 Pong (com.yahoo.prelude.Pong)1 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)1 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1