Search in sources :

Example 31 with GrowableByteBuffer

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

the class SerializeTestCase method testUnderflow.

@Test
public void testUnderflow() {
    BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer());
    buf.putByte(null, (byte) 123);
    buf.flip();
    boolean caught = false;
    try {
        byte[] val = buf.getBytes(null, 2);
    } catch (IllegalArgumentException e) {
        // System.out.println(e);
        caught = true;
    }
    assertThat(caught, is(true));
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test)

Example 32 with GrowableByteBuffer

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

the class DocumentPathUpdateTestCase method testGenerateSerializedFile.

public void testGenerateSerializedFile() throws IOException {
    DocumentUpdate docUp = createDocumentUpdateForSerialization();
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    docUp.serialize(DocumentSerializerFactory.createHead(buffer));
    int size = buffer.position();
    buffer.position(0);
    FileOutputStream fos = new FileOutputStream("src/tests/data/serialize-fieldpathupdate-java.dat");
    fos.write(buffer.array(), 0, size);
    fos.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 33 with GrowableByteBuffer

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

the class DocumentPathUpdateTestCase method testAddSerialization.

public void testAddSerialization() throws Exception {
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    Array strArray = new Array(docType.getField("strarray").getDataType());
    strArray.add(new StringFieldValue("hello hello"));
    strArray.add(new StringFieldValue("blah blah"));
    AddFieldPathUpdate add = new AddFieldPathUpdate(docType, "strarray", "", strArray);
    docUp.addFieldPathUpdate(add);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    docUp.serialize(DocumentSerializerFactory.createHead(buffer));
    buffer.flip();
    DocumentUpdate docUp2 = new DocumentUpdate(DocumentDeserializerFactory.createHead(docMan, buffer));
    assertEquals(docUp, docUp2);
}
Also used : AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 34 with GrowableByteBuffer

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

the class DocumentPathUpdateTestCase method testRemoveSerialization.

public void testRemoveSerialization() throws Exception {
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    RemoveFieldPathUpdate remove = new RemoveFieldPathUpdate(docType, "num", "foobar.num > 0");
    docUp.addFieldPathUpdate(remove);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    docUp.serialize(DocumentSerializerFactory.createHead(buffer));
    buffer.flip();
    DocumentUpdate docUp2 = new DocumentUpdate(DocumentDeserializerFactory.createHead(docMan, buffer));
    assertEquals(docUp, docUp2);
}
Also used : RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 35 with GrowableByteBuffer

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

the class DocumentSerializationTestCase method testSerializeDeserializeWithAnnotations.

@Test
public void testSerializeDeserializeWithAnnotations() throws IOException {
    Document doc = new Document(docType, "doc:foo:bar");
    doc.setFieldValue("age", (byte) 123);
    doc.setFieldValue("story", getAnnotatedString());
    doc.setFieldValue("date", 13829297);
    doc.setFieldValue("friend", 2384L);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(doc);
    buffer.flip();
    FileOutputStream fos = new FileOutputStream("src/tests/data/serializejavawithannotations.dat");
    fos.write(buffer.array(), 0, buffer.limit());
    fos.close();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
    Document doc2 = new Document(deserializer);
    assertEquals(doc, doc2);
    assertNotSame(doc, doc2);
}
Also used : FileOutputStream(java.io.FileOutputStream) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test) AbstractTypesTest(com.yahoo.document.annotation.AbstractTypesTest)

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