use of com.yahoo.document.Document in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method incompressable_structs_are_serialized_without_buffer_size_overhead_bug.
@Test
public void incompressable_structs_are_serialized_without_buffer_size_overhead_bug() {
CompressionFixture fixture = new CompressionFixture();
Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
Struct nested = new Struct(fixture.nestedType);
nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
// Only 1 struct added. Not enough redundant information that header struct containing map itself
// can be compressed.
map.put(new StringFieldValue("foo"), nested);
doc.setFieldValue("map", map);
GrowableByteBuffer buf = CompressionFixture.asSerialized(doc);
// Explanation of arbitrary value: buffer copy bug meant that incompressable structs were all serialized
// rounded up to 4096 bytes.
assertTrue(buf.remaining() < 4096);
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method stringToArrayOfIntMapTest.
@Test
public final void stringToArrayOfIntMapTest() throws IOException {
String docId = "id:unittest:testMapStringToArrayOfInt::whee";
String fields = "{ \"actualMapStringToArrayOfInt\": { \"bamse\": [1, 2, 3] }}";
Document doc = readDocumentFromJson(docId, fields);
ObjectMapper m = new ObjectMapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
// other fun. This is OK here, because if the casts fail, the should and
// will fail anyway
Map<?, ?> inputMap = (Map<?, ?>) m.readValue(Utf8.toBytes(fields), Map.class).get("actualMapStringToArrayOfInt");
Map<?, ?> generatedMap = (Map<?, ?>) ((Map<?, ?>) generated.get("fields")).get("actualMapStringToArrayOfInt");
assertEquals(inputMap, generatedMap);
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method mapTest.
@Test
public void mapTest() throws IOException {
String fields = "{ \"actualmap\": { \"nalle\": \"kalle\", \"tralle\": \"skalle\" }}";
String docId = "id:unittest:testmap::whee";
Document doc = readDocumentFromJson(docId, fields);
ObjectMapper m = new ObjectMapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
// other fun. This is OK here, because if the casts fail, the should and
// will fail anyway
Map<?, ?> inputMap = (Map<?, ?>) m.readValue(Utf8.toBytes(fields), Map.class).get("actualmap");
Map<?, ?> generatedMap = (Map<?, ?>) ((Map<?, ?>) generated.get("fields")).get("actualmap");
assertEquals(inputMap, generatedMap);
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method readDocumentFromJson.
private Document readDocumentFromJson(String docId, String fields) throws IOException {
InputStream rawDoc = new ByteArrayInputStream(asFeed(docId, fields));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo raw = r.parseDocument().get();
DocumentType docType = r.readDocumentType(raw.documentId);
DocumentPut put = new DocumentPut(new Document(docType, raw.documentId));
new VespaJsonDocumentReader().readPut(raw.fieldsBuffer, put);
return put.getDocument();
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method roundTripEquality.
private void roundTripEquality(final String docId, final String fields) throws IOException {
Document doc = readDocumentFromJson(docId, fields);
assertEqualJson(asDocument(docId, fields), JsonWriter.toByteArray(doc));
}
Aggregations