Search in sources :

Example 11 with Packet

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());
}
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 12 with Packet

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());
}
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)

Example 13 with Packet

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

Example 14 with Packet

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

Example 15 with Packet

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

Aggregations

Test (org.junit.Test)14 ByteBuffer (java.nio.ByteBuffer)12 BasicPacket (com.yahoo.fs4.BasicPacket)10 QueryPacket (com.yahoo.fs4.QueryPacket)10 Query (com.yahoo.search.Query)9 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)8 IOException (java.io.IOException)5 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)4 Packet (com.yahoo.fs4.Packet)4 PacketDecoder (com.yahoo.fs4.PacketDecoder)4 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)4 Location (org.bukkit.Location)4 DocumentInfo (com.yahoo.fs4.DocumentInfo)3 PingPacket (com.yahoo.fs4.PingPacket)3 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)3 Packet (ejip123.Packet)3 BufferTooSmallException (com.yahoo.fs4.BufferTooSmallException)2 DocsumPacket (com.yahoo.fs4.DocsumPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2