use of com.yahoo.document.serialization.DocumentSerializer in project vespa by vespa-engine.
the class FieldUpdateTestCase method serializedCopy.
// Copy all field updates using serialization to verify that it is supported
private FieldUpdate serializedCopy(FieldUpdate source, DocumentType docType) {
DocumentSerializer buffer = DocumentSerializerFactory.create42();
source.serialize(buffer);
buffer.getBuf().flip();
FieldUpdate copy = new FieldUpdate(DocumentDeserializerFactory.create42(docman, buffer.getBuf()), docType, Document.SERIALIZED_VERSION);
assertEquals(source, copy);
return copy;
}
use of com.yahoo.document.serialization.DocumentSerializer in project vespa by vespa-engine.
the class DocumentListTestCase method testSelfSerializationAndWriteJavaFile.
@SuppressWarnings("deprecation")
public void testSelfSerializationAndWriteJavaFile() throws Exception {
DocumentTypeManager docMan = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(docMan, "file:src/test/files/documentmanager.cfg");
DocumentType bmType = docMan.getDocumentType("benchmark");
DocumentPut put1 = new DocumentPut(bmType, "userdoc:foo:99999999:1");
put1.getDocument().setFieldValue("headerstring", "foo");
DocumentRemove doc2 = new DocumentRemove(new DocumentId("userdoc:foo:99999999:2"));
DocumentPut put3 = new DocumentPut(bmType, "userdoc:foo:99999999:3");
put3.getDocument().setFieldValue("bodyfloat", new FloatFieldValue(5.5f));
DocumentUpdate docUp = new DocumentUpdate(docMan.getDocumentType("benchmark"), new DocumentId("userdoc:foo:99999999:4"));
docUp.addFieldUpdate(FieldUpdate.createAssign(docUp.getType().getField("bodystring"), new StringFieldValue("ballooooo")));
List<Entry> entries = new ArrayList<Entry>();
entries.add(Entry.create(put1));
entries.add(Entry.create(doc2));
entries.add(Entry.create(put3));
entries.add(Entry.create(docUp));
DocumentList documentList = DocumentList.create(entries);
DocumentSerializer gbuf = DocumentSerializerFactory.create42();
// Add some data to avoid special case where position() is 0 for buffer used.
gbuf.putInt(null, 1234);
int startPos = gbuf.getBuf().position();
documentList.serialize(gbuf);
int size = gbuf.getBuf().position() - startPos;
byte[] data = new byte[size];
gbuf.getBuf().position(startPos);
gbuf.getBuf().get(data);
FileOutputStream stream = new FileOutputStream("./src/test/files/documentlist-java.dat");
stream.write(data);
stream.close();
gbuf.getBuf().position(0);
DocumentList documentList2 = DocumentList.create(docMan, data);
assertEquals(4, documentList2.size());
Entry entry1 = documentList2.get(0);
assertEquals(0L, entry1.getTimestamp());
assertFalse(entry1.isBodyStripped());
assertFalse(entry1.isRemoveEntry());
assertFalse(entry1.isUpdateEntry());
assertTrue(entry1.getDocumentOperation() instanceof DocumentPut);
assertEquals(new StringFieldValue("foo"), ((DocumentPut) entry1.getDocumentOperation()).getDocument().getFieldValue("headerstring"));
Entry entry2 = documentList2.get(1);
assertEquals(0L, entry2.getTimestamp());
assertFalse(entry2.isBodyStripped());
assertTrue(entry2.isRemoveEntry());
assertFalse(entry2.isUpdateEntry());
assertTrue(entry2.getDocumentOperation() instanceof DocumentRemove);
Entry entry3 = documentList2.get(2);
assertEquals(0L, entry3.getTimestamp());
assertFalse(entry3.isBodyStripped());
assertFalse(entry3.isRemoveEntry());
assertFalse(entry3.isUpdateEntry());
assertTrue(entry3.getDocumentOperation() instanceof DocumentPut);
assertEquals(new FloatFieldValue(5.5f), ((DocumentPut) entry3.getDocumentOperation()).getDocument().getFieldValue("bodyfloat"));
Entry entry4 = documentList2.get(3);
assertEquals(0L, entry4.getTimestamp());
assertFalse(entry4.isBodyStripped());
assertFalse(entry4.isRemoveEntry());
assertTrue(entry4.isUpdateEntry());
assertTrue(entry4.getDocumentOperation() instanceof DocumentUpdate);
assertEquals(new StringFieldValue("ballooooo"), ((DocumentUpdate) entry4.getDocumentOperation()).getFieldUpdate(0).getValueUpdate(0).getValue());
}
use of com.yahoo.document.serialization.DocumentSerializer in project vespa by vespa-engine.
the class DynamicDocumentList method serialize.
@Override
public void serialize(Serializer buf) {
if (buf instanceof DocumentSerializer) {
serializeInternal((DocumentSerializer) buf);
} else {
DocumentSerializer serializer = DocumentSerializerFactory.create42();
serializeInternal(serializer);
serializer.getBuf().getByteBuffer().flip();
buf.put(null, serializer.getBuf().getByteBuffer());
}
}
use of com.yahoo.document.serialization.DocumentSerializer in project vespa by vespa-engine.
the class JsonReaderTestCase method testStructUpdate.
@Test
public final void testStructUpdate() throws IOException {
DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}");
assertEquals(1, put.getFieldUpdates().size());
FieldUpdate fu = put.getFieldUpdate(0);
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
AssignValueUpdate avu = (AssignValueUpdate) vu;
assertTrue(avu.getValue() instanceof Struct);
Struct s = (Struct) avu.getValue();
assertEquals(2, s.getFieldCount());
assertEquals(new StringFieldValue("person"), s.getFieldValue(s.getField("sandra")));
GrowableByteBuffer buf = new GrowableByteBuffer();
DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
put.serialize(serializer);
assertEquals(107, buf.position());
}
use of com.yahoo.document.serialization.DocumentSerializer in project vespa by vespa-engine.
the class JsonReaderTestCase method testEmptyStructUpdate.
@Test
public final void testEmptyStructUpdate() throws IOException {
DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { }}}}");
assertEquals(1, put.getFieldUpdates().size());
FieldUpdate fu = put.getFieldUpdate(0);
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
AssignValueUpdate avu = (AssignValueUpdate) vu;
assertTrue(avu.getValue() instanceof Struct);
Struct s = (Struct) avu.getValue();
assertEquals(0, s.getFieldCount());
GrowableByteBuffer buf = new GrowableByteBuffer();
DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
put.serialize(serializer);
assertEquals(69, buf.position());
}
Aggregations