Search in sources :

Example 66 with GrowableByteBuffer

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

the class DocumentTestCase method testV6Doc.

@Test
public void testV6Doc() throws IOException {
    docMan = setUpCppDocType();
    byte[] data = readFile("src/tests/data/serializev6.dat");
    ByteBuffer buf = ByteBuffer.wrap(data);
    Document doc = docMan.createDocument(new GrowableByteBuffer(buf));
    validateCppDocNotMap(doc);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test)

Example 67 with GrowableByteBuffer

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

the class DocumentTestCase method testCompressionConfigured.

@Test
public void testCompressionConfigured() {
    int size_uncompressed;
    {
        DocumentTypeManager docMan = new DocumentTypeManager();
        docMan.configure("file:src/tests/data/cppdocument.cfg");
        Document doc = new Document(docMan.getDocumentType("serializetest"), new DocumentId("doc:test:test"));
        doc.setFieldValue("stringfield", "compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me ");
        GrowableByteBuffer data = new GrowableByteBuffer();
        doc.serialize(data);
        size_uncompressed = data.position();
    }
    DocumentTypeManager docMan = new DocumentTypeManager();
    docMan.configure("file:src/tests/data/compressed.cfg");
    Document doc = new Document(docMan.getDocumentType("serializetest"), new DocumentId("doc:test:test"));
    doc.setFieldValue("stringfield", "compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me compress me ");
    GrowableByteBuffer data = new GrowableByteBuffer();
    doc.serialize(data);
    int size_compressed = data.position();
    assertTrue(size_compressed + " < " + size_uncompressed, size_compressed < size_uncompressed);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test)

Example 68 with GrowableByteBuffer

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

the class DocumentPathUpdateTestCase method testAssignSerialization.

public void testAssignSerialization() throws Exception {
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    AssignFieldPathUpdate ass = new AssignFieldPathUpdate(docType, "num", "", "3");
    ass.setCreateMissingPath(false);
    docUp.addFieldPathUpdate(ass);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    docUp.serialize(DocumentSerializerFactory.createHead(buffer));
    buffer.flip();
    DocumentUpdate docUp2 = new DocumentUpdate(DocumentDeserializerFactory.createHead(docMan, buffer));
    assertEquals(docUp, docUp2);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 69 with GrowableByteBuffer

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

the class DocumentUpdateTestCase method testRequireThatCreateIfNonExistentFlagIsSerializedAndDeserialized.

public void testRequireThatCreateIfNonExistentFlagIsSerializedAndDeserialized() {
    docUp.setCreateIfNonExistent(true);
    DocumentSerializer serializer = DocumentSerializerFactory.createHead(new GrowableByteBuffer());
    docUp.serialize(serializer);
    serializer.getBuf().flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.createHead(docMan, serializer.getBuf());
    DocumentUpdate deserialized = new DocumentUpdate(deserializer);
    assertEquals(docUp, deserialized);
    assertTrue(deserialized.getCreateIfNonExistent());
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 70 with GrowableByteBuffer

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

the class DocumentUpdateTestCase method testSerialize.

public void testSerialize() {
    docUp.addFieldUpdate(assignSingle);
    docUp.addFieldUpdate(addMultiList);
    DocumentDeserializer buf = DocumentDeserializerFactory.create42(docMan, new GrowableByteBuffer());
    docUp.serialize((DocumentUpdateWriter) buf);
    buf.getBuf().flip();
    try {
        FileOutputStream fos = new FileOutputStream("src/test/files/updateser.dat");
        fos.write(buf.getBuf().array(), 0, buf.getBuf().remaining());
        fos.close();
    } catch (Exception e) {
    }
    assertEquals(// version
    2 + // docid doc:foo:bar\0
    (11 + 1) + // contents
    1 + // doctype foobar\0\0\0
    (6 + 1 + 2) + // num field updates
    4 + // field update 1:
    (// field id
    4 + // num valueupdates
    4 + (// valueUpdateClassID
    4 + // valuepresent
    1 + // value
    (1 + 1 + 9 + 1)) + // field update 2
    (// field id
    4 + // num valueupdates
    4 + (// valueUpdateClassID
    4 + // value
    (4 + 4 + 4 + (1 + 1 + 2 + 1) + 4 + (1 + 1 + 2 + 1) + 4 + (1 + 1 + 2 + 1))))), buf.getBuf().remaining());
    DocumentUpdate docUpDeser = new DocumentUpdate(buf);
    assertEquals(docUp.getDocumentType(), docUpDeser.getDocumentType());
    assertEquals(docUp, docUpDeser);
}
Also used : FileOutputStream(java.io.FileOutputStream) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) ParseException(com.yahoo.document.select.parser.ParseException) IOException(java.io.IOException)

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