Search in sources :

Example 31 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class SerializationTestUtils method deserializeDocument.

public static Document deserializeDocument(byte[] buf, TestDocumentFactory factory) {
    Document document = factory.createDocument();
    DocumentDeserializerFactory.create42(factory.typeManager(), new GrowableByteBuffer(ByteBuffer.wrap(buf))).read(document);
    return document;
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document)

Example 32 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class SerializationTestUtils method assertDeserializeFromFile.

private static void assertDeserializeFromFile(Path path, Document document, TestDocumentFactory factory) throws IOException {
    byte[] buf = Files.readAllBytes(path);
    Document deserializedDocument = deserializeDocument(buf, factory);
    assertEquals(path.toString(), document, deserializedDocument);
}
Also used : Document(com.yahoo.document.Document)

Example 33 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class SerializationTestUtils method assertFieldInDocumentSerialization.

public static void assertFieldInDocumentSerialization(TestDocumentFactory documentFactory, String fieldName, FieldValue serializableFieldValue) {
    Document document = documentFactory.createDocument();
    document.setFieldValue(fieldName, serializableFieldValue);
    byte[] buf = serializeDocument(document);
    Document deserializedDocument = deserializeDocument(buf, documentFactory);
    assertEquals(document, deserializedDocument);
    assertEquals(serializableFieldValue, deserializedDocument.getFieldValue(fieldName));
}
Also used : Document(com.yahoo.document.Document)

Example 34 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class TensorFieldValueSerializationTestCase method assertSerializationMatchesCpp.

private static void assertSerializationMatchesCpp(String fileName, TensorFieldValue tensor) throws IOException {
    Document document = docFactory.createDocument();
    document.setFieldValue(TENSOR_FIELD, tensor);
    SerializationTestUtils.assertSerializationMatchesCpp(TENSOR_FILES, fileName, document, docFactory);
}
Also used : Document(com.yahoo.document.Document) SerializationTestUtils.deserializeDocument(com.yahoo.document.serialization.SerializationTestUtils.deserializeDocument) SerializationTestUtils.serializeDocument(com.yahoo.document.serialization.SerializationTestUtils.serializeDocument)

Example 35 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class VespaDocumentSerializerTestCase method compressed_map_of_compressed_structs_is_supported.

@Test
public void compressed_map_of_compressed_structs_is_supported() {
    CompressionFixture fixture = new CompressionFixture();
    Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
    Struct nested = new Struct(fixture.nestedType);
    nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
    MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
    map.put(new StringFieldValue("foo"), nested);
    map.put(new StringFieldValue("bar"), nested);
    doc.setFieldValue("map", map);
    // Should _not_ throw any deserialization exceptions
    Document result = fixture.roundtripSerialize(doc);
    assertEquals(doc, result);
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Document(com.yahoo.document.Document) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8