use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class QueryTestCase method packetToBytes.
public static byte[] packetToBytes(Packet packet) {
try {
ByteBuffer buffer = ByteBuffer.allocate(500);
buffer.limit(0);
packet.encode(buffer, 0);
byte[] encoded = new byte[buffer.position()];
buffer.rewind();
buffer.get(encoded);
return encoded;
} catch (BufferTooSmallException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class QueryTestCase method testPhraseEqualsPhraseWithPhraseSegment.
@Test
public void testPhraseEqualsPhraseWithPhraseSegment() throws BufferTooSmallException {
Query query = new Query();
PhraseItem p = new PhraseItem();
PhraseSegmentItem ps = new PhraseSegmentItem("a b", false, false);
ps.addItem(new WordItem("a"));
ps.addItem(new WordItem("b"));
p.addItem(ps);
query.getModel().getQueryTree().setRoot(p);
query.setTimeout(0);
QueryPacket queryPacket = QueryPacket.create(query);
ByteBuffer buffer1 = ByteBuffer.allocate(1024);
queryPacket.encode(buffer1, 0);
query = new Query();
p = new PhraseItem();
p.addItem(new WordItem("a"));
p.addItem(new WordItem("b"));
query.getModel().getQueryTree().setRoot(p);
query.setTimeout(0);
queryPacket = QueryPacket.create(query);
assertNotNull(queryPacket);
ByteBuffer buffer2 = ByteBuffer.allocate(1024);
queryPacket.encode(buffer2, 0);
byte[] encoded1 = new byte[buffer1.position()];
buffer1.rewind();
buffer1.get(encoded1);
byte[] encoded2 = new byte[buffer2.position()];
buffer2.rewind();
buffer2.get(encoded2);
assertEqualArrays(encoded2, encoded1);
}
use of com.yahoo.fs4.BufferTooSmallException 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());
}
use of com.yahoo.fs4.BufferTooSmallException in project vespa by vespa-engine.
the class PacketDecoderTestCase method testTooSmallBufferForPacket.
/**
* Test the case where the buffer is too small for the
* packet
*/
@Test
public void testTooSmallBufferForPacket() {
ByteBuffer data = ByteBuffer.allocate(10);
data.put(queryResultPacketData, 0, 10);
data.flip();
try {
PacketDecoder.extractPacket(data);
fail();
} catch (BufferTooSmallException e) {
}
}
use of com.yahoo.fs4.BufferTooSmallException 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);
}
Aggregations