use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class MapTestCase method assertCorrectSerialization.
private void assertCorrectSerialization(MapDataType mapType, MapFieldValue<? extends FieldValue, ? extends FieldValue> map) {
Field f = new Field("", mapType);
DocumentTypeManager man = new DocumentTypeManager();
man.register(mapType);
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
serializer.write(f, map);
buffer.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
MapFieldValue<FieldValue, FieldValue> map2 = new MapFieldValue<FieldValue, FieldValue>(mapType);
deserializer.read(f, map2);
assertNotSame(map, map2);
for (Map.Entry<?, ?> e : map.entrySet()) {
assertEquals(e.getValue(), map2.get(e.getKey()));
}
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class StringTestCase method serializeAndAssert.
private void serializeAndAssert(StringFieldValue stringFieldValue) {
Field f = new Field("text", DataType.STRING);
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
serializer.write(f, stringFieldValue);
buffer.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
StringFieldValue stringFieldValue2 = new StringFieldValue();
deserializer.read(f, stringFieldValue2);
assertEquals(stringFieldValue, stringFieldValue2);
assertNotSame(stringFieldValue, stringFieldValue2);
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class StringTestCase method testSerializeDeserialize.
/* public void testSpanTree() {
StringFieldValue annotatedText = new StringFieldValue("banana airlines");
SpanList lingTree = new SpanList();
annotatedText.setSpanTree("linguistics", lingTree);
for (Annotation anAnnotation : annotatedText.getSpanTree("linguistics")) {
System.err.println(anAnnotation);
}
}*/
@Test
public void testSerializeDeserialize() throws Exception {
java.lang.String test = "Hello hello";
BufferSerializer data = new BufferSerializer(new GrowableByteBuffer(100, 2.0f));
StringFieldValue value = new StringFieldValue(test);
value.serialize(data);
data.getBuf().position(0);
StringFieldValue tmp = new StringFieldValue();
DocumentDeserializer deser = DocumentDeserializerFactory.create42(null, data.getBuf());
tmp.deserialize(deser);
java.lang.String test2 = tmp.getString();
assertEquals(test, test2);
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class StringTestCase method testNestedSpanTreeBug4187377.
@Test
public void testNestedSpanTreeBug4187377() {
AnnotationType type = new AnnotationType("ann", DataType.STRING);
StringFieldValue outerString = new StringFieldValue("Ballooo");
SpanTree outerTree = new SpanTree("outer");
outerString.setSpanTree(outerTree);
SpanList outerRoot = (SpanList) outerTree.getRoot();
Span outerSpan = new Span(0, 1);
outerRoot.add(outerSpan);
StringFieldValue innerString = new StringFieldValue("innerBalloooo");
outerTree.annotate(outerSpan, new Annotation(type, innerString));
SpanTree innerTree = new SpanTree("inner");
innerString.setSpanTree(innerTree);
SpanList innerRoot = (SpanList) innerTree.getRoot();
Span innerSpan = new Span(0, 1);
innerRoot.add(innerSpan);
innerTree.annotate(innerSpan, new Annotation(type));
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
try {
serializer.write(null, outerString);
fail("Should have failed, nested span trees are not supported.");
} catch (SerializationException se) {
// OK!
}
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class DocInDocTestCase method testDocInDoc.
@Test
public void testDocInDoc() {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/documentmanager.docindoc.cfg");
Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
innerArray.add(inner1);
innerArray.add(inner2);
Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
outer.setFieldValue("innerdocuments", innerArray);
DocumentSerializer serializer = DocumentSerializerFactory.create42();
serializer.write(outer);
GrowableByteBuffer buf = serializer.getBuf();
buf.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buf);
Document outerDeserialized = new Document(deserializer);
assertEquals(outer, outerDeserialized);
assertNotSame(outer, outerDeserialized);
}
Aggregations