use of com.yahoo.io.GrowableByteBuffer 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.io.GrowableByteBuffer 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());
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class SerializationTestUtils method serializeDocument.
public static byte[] serializeDocument(Document doc) {
GrowableByteBuffer out = new GrowableByteBuffer();
DocumentSerializerFactory.create42(out).write(doc);
out.flip();
byte[] buf = new byte[out.remaining()];
out.get(buf);
return buf;
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method predicate_field_values_are_serialized.
@Test
public void predicate_field_values_are_serialized() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_predicate", DataType.PREDICATE);
docType.addField(field);
Document doc = new Document(docType, "doc:scheme:");
PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
doc.setFieldValue("my_predicate", predicate);
DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method get_serialized_size_uses_latest_serializer.
@Test
public void get_serialized_size_uses_latest_serializer() {
DocumentType docType = new DocumentType("my_type");
docType.addField("my_str", DataType.STRING);
docType.addField("my_int", DataType.INT);
Document doc = new Document(docType, "doc:scheme:");
doc.setFieldValue("my_str", new StringFieldValue("foo"));
doc.setFieldValue("my_int", new IntegerFieldValue(69));
GrowableByteBuffer buf = new GrowableByteBuffer();
doc.serialize(buf);
assertEquals(buf.position(), VespaDocumentSerializer42.getSerializedSize(doc));
}
Aggregations