Search in sources :

Example 1 with DecodedPacket

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

the class PacketDecoderTestCase method testErrorPacket.

@Test
public void testErrorPacket() throws BufferTooSmallException {
    ByteBuffer b = ByteBuffer.allocate(100);
    b.putInt(0);
    b.putInt(203);
    b.putInt(1);
    b.putInt(37);
    b.putInt(5);
    b.put(new byte[] { (byte) 'n', (byte) 'a', (byte) 'l', (byte) 'l', (byte) 'e' });
    b.putInt(0, b.position() - 4);
    b.flip();
    DecodedPacket p = PacketDecoder.extractPacket(b);
    ErrorPacket e = (ErrorPacket) p.packet;
    assertEquals("nalle (37)", e.toString());
    assertEquals(203, e.getCode());
    assertEquals(37, e.getErrorCode());
    b = ByteBuffer.allocate(100);
    // warn if encoding support is added untested
    e.encode(b);
    b.position(0);
    assertEquals(4, b.getInt());
    assertEquals(203, b.getInt());
    assertFalse(b.hasRemaining());
}
Also used : ErrorPacket(com.yahoo.fs4.ErrorPacket) DecodedPacket(com.yahoo.fs4.PacketDecoder.DecodedPacket) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ErrorPacket (com.yahoo.fs4.ErrorPacket)1 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1