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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations