Search in sources :

Example 6 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class MapTestCase method assertCorrectSerialization.

private void assertCorrectSerialization(MapDataType mapType, MapFieldValue<? extends FieldValue, ? extends FieldValue> map) {
    Field f = new Field("", mapType);
    DocumentTypeManager man = new DocumentTypeManager();
    man.register(mapType);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(f, map);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
    MapFieldValue<FieldValue, FieldValue> map2 = new MapFieldValue<FieldValue, FieldValue>(mapType);
    deserializer.read(f, map2);
    assertNotSame(map, map2);
    for (Map.Entry<?, ?> e : map.entrySet()) {
        assertEquals(e.getValue(), map2.get(e.getKey()));
    }
}
Also used : Field(com.yahoo.document.Field) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Map(java.util.Map)

Example 7 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class StringTestCase method serializeAndAssert.

private void serializeAndAssert(StringFieldValue stringFieldValue) {
    Field f = new Field("text", DataType.STRING);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(f, stringFieldValue);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
    StringFieldValue stringFieldValue2 = new StringFieldValue();
    deserializer.read(f, stringFieldValue2);
    assertEquals(stringFieldValue, stringFieldValue2);
    assertNotSame(stringFieldValue, stringFieldValue2);
}
Also used : Field(com.yahoo.document.Field) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 8 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class StringTestCase method testSerializeDeserialize.

/*    public void testSpanTree() {
        StringFieldValue annotatedText = new StringFieldValue("banana airlines");
        SpanList lingTree = new SpanList();
        annotatedText.setSpanTree("linguistics", lingTree);
        for (Annotation anAnnotation : annotatedText.getSpanTree("linguistics")) {
            System.err.println(anAnnotation);
        }
    }*/
@Test
public void testSerializeDeserialize() throws Exception {
    java.lang.String test = "Hello hello";
    BufferSerializer data = new BufferSerializer(new GrowableByteBuffer(100, 2.0f));
    StringFieldValue value = new StringFieldValue(test);
    value.serialize(data);
    data.getBuf().position(0);
    StringFieldValue tmp = new StringFieldValue();
    DocumentDeserializer deser = DocumentDeserializerFactory.create42(null, data.getBuf());
    tmp.deserialize(deser);
    java.lang.String test2 = tmp.getString();
    assertEquals(test, test2);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test) AbstractTypesTest(com.yahoo.document.annotation.AbstractTypesTest)

Example 9 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class StringTestCase method testNestedSpanTreeBug4187377.

@Test
public void testNestedSpanTreeBug4187377() {
    AnnotationType type = new AnnotationType("ann", DataType.STRING);
    StringFieldValue outerString = new StringFieldValue("Ballooo");
    SpanTree outerTree = new SpanTree("outer");
    outerString.setSpanTree(outerTree);
    SpanList outerRoot = (SpanList) outerTree.getRoot();
    Span outerSpan = new Span(0, 1);
    outerRoot.add(outerSpan);
    StringFieldValue innerString = new StringFieldValue("innerBalloooo");
    outerTree.annotate(outerSpan, new Annotation(type, innerString));
    SpanTree innerTree = new SpanTree("inner");
    innerString.setSpanTree(innerTree);
    SpanList innerRoot = (SpanList) innerTree.getRoot();
    Span innerSpan = new Span(0, 1);
    innerRoot.add(innerSpan);
    innerTree.annotate(innerSpan, new Annotation(type));
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    try {
        serializer.write(null, outerString);
        fail("Should have failed, nested span trees are not supported.");
    } catch (SerializationException se) {
    // OK!
    }
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) SpanList(com.yahoo.document.annotation.SpanList) Span(com.yahoo.document.annotation.Span) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test) AbstractTypesTest(com.yahoo.document.annotation.AbstractTypesTest)

Example 10 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class DocInDocTestCase method testDocInDoc.

@Test
public void testDocInDoc() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/documentmanager.docindoc.cfg");
    Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
    inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
    inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
    Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
    inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
    inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
    Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
    innerArray.add(inner1);
    innerArray.add(inner2);
    Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
    outer.setFieldValue("innerdocuments", innerArray);
    DocumentSerializer serializer = DocumentSerializerFactory.create42();
    serializer.write(outer);
    GrowableByteBuffer buf = serializer.getBuf();
    buf.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buf);
    Document outerDeserialized = new Document(deserializer);
    assertEquals(outer, outerDeserialized);
    assertNotSame(outer, outerDeserialized);
}
Also used : Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test)

Aggregations

GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)74 Test (org.junit.Test)34 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)18 Document (com.yahoo.document.Document)9 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)9 Field (com.yahoo.document.Field)8 ByteBuffer (java.nio.ByteBuffer)8 FileOutputStream (java.io.FileOutputStream)6 DocumentType (com.yahoo.document.DocumentType)5 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)4 Raw (com.yahoo.document.datatypes.Raw)4 Struct (com.yahoo.document.datatypes.Struct)4 Grouping (com.yahoo.searchlib.aggregation.Grouping)4 Array (com.yahoo.document.datatypes.Array)3 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)3 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)3 FieldUpdate (com.yahoo.document.update.FieldUpdate)3 IOException (java.io.IOException)3