Search in sources :

Example 16 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class GroupingTestCase method assertSerialize.

private static void assertSerialize(Grouping grouping) {
    BufferSerializer buf = new BufferSerializer();
    grouping.serializeWithId(buf);
    buf.flip();
    Grouping other = (Grouping) Grouping.create(buf);
    assertEquals(grouping, other);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer)

Example 17 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class SparseSketchTest method requireThatSerializationRetainAllData.

@Test
public void requireThatSerializationRetainAllData() {
    SparseSketch from = new SparseSketch();
    from.aggregate(42);
    from.aggregate(1337);
    SparseSketch to = new SparseSketch();
    BufferSerializer buffer = new BufferSerializer();
    from.serialize(buffer);
    buffer.flip();
    to.deserialize(buffer);
    assertEquals(from, to);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) Test(org.junit.Test)

Example 18 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class ExpressionTestCase method assertSerialize.

private static Identifiable assertSerialize(Identifiable node) {
    BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer());
    node.serializeWithId(buf);
    buf.flip();
    Identifiable created = Identifiable.create(buf);
    assertEquals(node, created);
    assertEquals(buf.getBuf().hasRemaining(), false);
    Identifiable cloned = created.clone();
    assertEquals(node, cloned);
    BufferSerializer createdBuffer = new BufferSerializer(new GrowableByteBuffer());
    BufferSerializer clonedBuffer = new BufferSerializer(new GrowableByteBuffer());
    created.serializeWithId(createdBuffer);
    cloned.serializeWithId(clonedBuffer);
    assertEquals(createdBuffer.getBuf().limit(), clonedBuffer.getBuf().limit());
    assertEquals(createdBuffer.position(), clonedBuffer.position());
    createdBuffer.getBuf().flip();
    clonedBuffer.getBuf().flip();
    for (int i = 0; i < createdBuffer.getBuf().limit(); i++) {
        assertEquals(createdBuffer.getBuf().get(), clonedBuffer.getBuf().get());
    }
    return created;
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Identifiable(com.yahoo.vespa.objects.Identifiable)

Example 19 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class ExpressionTestCase method assertResultNode.

private static void assertResultNode(ResultNode node) {
    BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer());
    long oldInteger = node.getInteger();
    double oldFloat = node.getFloat();
    String oldString = node.getString();
    byte[] oldRaw = node.getRaw();
    node.serialize(buf);
    buf.flip();
    node.deserialize(buf);
    assertEquals(oldInteger, node.getInteger());
    assertEquals(oldFloat, node.getFloat());
    assertEquals(oldString, node.getString());
    assertEquals(oldRaw.length, node.getRaw().length);
    buf = new BufferSerializer(new GrowableByteBuffer());
    node.serializeWithId(buf);
    buf.flip();
    node.deserializeWithId(buf);
    assertEquals(oldInteger, node.getInteger());
    assertEquals(oldFloat, node.getFloat());
    assertEquals(oldString, node.getString());
    assertEquals(oldRaw.length, node.getRaw().length);
    buf = new BufferSerializer(new GrowableByteBuffer());
    node.serializeWithId(buf);
    buf.flip();
    ResultNode obj = (ResultNode) Identifiable.create(buf);
    assertEquals(oldInteger, obj.getInteger());
    assertEquals(oldFloat, obj.getFloat());
    assertEquals(oldString, obj.getString());
    assertEquals(oldRaw.length, obj.getRaw().length);
    assertSerialize(node);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 20 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class ResultNodeTest method assertCorrectSerialization.

public void assertCorrectSerialization(ResultNode from, ResultNode to) {
    BufferSerializer buffer = new BufferSerializer();
    from.serialize(buffer);
    buffer.flip();
    to.deserialize(buffer);
    assertThat(from.onCmp(to), is(0));
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer)

Aggregations

BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)21 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)9 Test (org.junit.Test)7 Grouping (com.yahoo.searchlib.aggregation.Grouping)4 Identifiable (com.yahoo.vespa.objects.Identifiable)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)1 Raw (com.yahoo.document.datatypes.Raw)1 LoadType (com.yahoo.documentapi.messagebus.loadtypes.LoadType)1 Coverage (com.yahoo.search.result.Coverage)1 Utf8Array (com.yahoo.text.Utf8Array)1 Utf8String (com.yahoo.text.Utf8String)1 DocumentSummary (com.yahoo.vdslib.DocumentSummary)1 SearchResult (com.yahoo.vdslib.SearchResult)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1