summaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-06-09 17:52:33 +0200
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-06-12 15:16:33 +0200
commitd165ec86d13eb7ba8635db3408148e82b7456368 (patch)
treed798ba990ff6b6a91d5c6c8d4a550c931f096555 /document/src
parent9a6d1fc6f5635fe917d1a563149764be12822ffc (diff)
Compressor must only compress actual input range, not entire array
Diffstat (limited to 'document/src')
-rw-r--r--document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java69
-rw-r--r--document/src/tests/data/serializejava-compressed.datbin8337 -> 4416 bytes
2 files changed, 66 insertions, 3 deletions
diff --git a/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java b/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java
index a47b6356a36..329d1956e64 100644
--- a/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java
+++ b/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java
@@ -1,27 +1,36 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.serialization;
+import com.yahoo.compress.CompressionType;
+import com.yahoo.document.CompressionConfig;
import com.yahoo.document.DataType;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentType;
+import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.Field;
+import com.yahoo.document.MapDataType;
+import com.yahoo.document.StructDataType;
import com.yahoo.document.datatypes.IntegerFieldValue;
+import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
+import com.yahoo.document.datatypes.Struct;
import com.yahoo.io.GrowableByteBuffer;
import org.junit.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @author Simon Thoresen
+ * @author vekterli
*/
@SuppressWarnings("deprecation")
public class VespaDocumentSerializerTestCase {
@Test
- public void requireThatGetSerializedSizeUsesLatestSerializer() {
+ 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);
@@ -35,7 +44,7 @@ public class VespaDocumentSerializerTestCase {
}
@Test
- public void requireThatPredicateFieldValuesAreSerialized() {
+ public void predicate_field_values_are_serialized() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_predicate", DataType.PREDICATE);
docType.addField(field);
@@ -46,4 +55,58 @@ public class VespaDocumentSerializerTestCase {
DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
+
+ static class CompressionFixture {
+ final DocumentTypeManager manager;
+ final DocumentType docType;
+ final StructDataType nestedType;
+ final MapDataType mapType;
+
+ CompressionFixture() {
+ docType = new DocumentType("map_of_structs");
+ docType.getHeaderType().setCompressionConfig(new CompressionConfig(CompressionType.LZ4));
+
+ nestedType = new StructDataType("nested_type");
+ nestedType.addField(new Field("str", DataType.STRING));
+
+ mapType = new MapDataType(DataType.STRING, nestedType);
+ docType.addField(new Field("map", mapType));
+
+ manager = new DocumentTypeManager();
+ manager.registerDocumentType(docType);
+ }
+
+ static GrowableByteBuffer asSerialized(Document inputDoc) {
+ GrowableByteBuffer buf = new GrowableByteBuffer();
+ inputDoc.serialize(buf);
+ buf.flip();
+ return buf;
+ }
+
+ Document roundtripSerialize(Document inputDoc) {
+ return manager.createDocument(asSerialized(inputDoc));
+ }
+
+ String compressableString() {
+ return "zippy zip mc zippington the 3rd zippy zip";
+ }
+ }
+
+ @Test
+ public void compressed_map_of_compressed_structs_is_supported() {
+ 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(fixture.compressableString()));
+
+ MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
+ map.put(new StringFieldValue("foo"), nested);
+ map.put(new StringFieldValue("bar"), nested);
+ doc.setFieldValue("map", map);
+
+ // Should _not_ throw any deserialization exceptions
+ fixture.roundtripSerialize(doc);
+ }
+
}
diff --git a/document/src/tests/data/serializejava-compressed.dat b/document/src/tests/data/serializejava-compressed.dat
index 5c8721c097c..86875d5f121 100644
--- a/document/src/tests/data/serializejava-compressed.dat
+++ b/document/src/tests/data/serializejava-compressed.dat
Binary files differ