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