aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-06-07 13:13:45 +0200
committergjoranv <gv@verizonmedia.com>2022-06-08 11:45:31 +0200
commit5fce9fedea4b8259d8d1bc1d26d47cc3b837b252 (patch)
tree5ae004ca96fa829088302972cbe33dd00c611a48 /document/src/test/java/com/yahoo
parent40cf39429211d66616f8dce58198ecdfe43735eb (diff)
Further GC document level compression. Avoids a buffer copy that is no longer relevant.
Diffstat (limited to 'document/src/test/java/com/yahoo')
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java31
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentTestCase.java28
2 files changed, 24 insertions, 35 deletions
diff --git a/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java b/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java
index 77b621a3c36..1a5016fb155 100644
--- a/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
-import com.yahoo.compress.CompressionType;
import com.yahoo.document.annotation.AbstractTypesTest;
import com.yahoo.document.datatypes.Array;
import com.yahoo.document.datatypes.BoolFieldValue;
@@ -13,7 +12,10 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.Raw;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.WeightedSet;
-import com.yahoo.document.serialization.*;
+import com.yahoo.document.serialization.DocumentDeserializer;
+import com.yahoo.document.serialization.DocumentDeserializerFactory;
+import com.yahoo.document.serialization.DocumentSerializer;
+import com.yahoo.document.serialization.DocumentSerializerFactory;
import com.yahoo.io.GrowableByteBuffer;
import org.junit.Test;
@@ -27,9 +29,10 @@ import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Tests serialization of all versions.
@@ -92,7 +95,7 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
doc.setFieldValue("intfield", 5);
doc.setFieldValue("floatfield", -9.23);
doc.setFieldValue("stringfield", "This is a string.");
- doc.setFieldValue("longfield", new LongFieldValue(398420092938472983l));
+ doc.setFieldValue("longfield", new LongFieldValue(398420092938472983L));
doc.setFieldValue("doublefield", new DoubleFieldValue(98374532.398820));
doc.setFieldValue("bytefield", new ByteFieldValue(254));
doc.setFieldValue("boolfield", new BoolFieldValue(true));
@@ -120,8 +123,8 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
class TestDoc {
- String testFile;
- int version;
+ final String testFile;
+ final int version;
TestDoc(String testFile, int version) {
this.testFile = testFile;
@@ -133,10 +136,8 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
List<TestDoc> tests = new ArrayList<>();
tests.add(new TestDoc(path + "document-java-currentversion-uncompressed.dat", Document.SERIALIZED_VERSION));
- tests.add(new TestDoc(path + "document-java-currentversion-lz4-9.dat", Document.SERIALIZED_VERSION));
tests.add(new TestDoc(path + "document-java-v8-uncompressed.dat", 8));
tests.add(new TestDoc(cpppath + "document-cpp-currentversion-uncompressed.dat", 7));
- tests.add(new TestDoc(cpppath + "document-cpp-currentversion-lz4-9.dat", 7));
tests.add(new TestDoc(cpppath + "document-cpp-v8-uncompressed.dat", 7));
for (TestDoc test : tests) {
File f = new File(test.testFile);
@@ -146,7 +147,7 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
int remaining = buffer.length;
while (remaining > 0) {
int read = fin.read(buffer, pos, remaining);
- assertFalse(read == -1);
+ assertNotEquals(-1, read);
pos += read;
remaining -= read;
}
@@ -159,7 +160,7 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
assertEquals(-9.23, ((FloatFieldValue)doc.getFieldValue("floatfield")).getFloat(), 1E-6);
assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
- assertEquals(new LongFieldValue(398420092938472983l), doc.getFieldValue("longfield"));
+ assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
assertEquals(98374532.398820, ((DoubleFieldValue)doc.getFieldValue("doublefield")).getDouble(), 1E-6);
assertEquals(new ByteFieldValue((byte)254), doc.getFieldValue("bytefield"));
// Todo add cpp serialization
@@ -167,20 +168,20 @@ public class DocumentSerializationTestCase extends AbstractTypesTest {
ByteBuffer bbuffer = ((Raw)doc.getFieldValue("rawfield")).getByteBuffer();
if (!Arrays.equals("RAW DATA".getBytes(), bbuffer.array())) {
System.err.println("Expected 'RAW DATA' but got '" + new String(bbuffer.array()) + "'.");
- assertTrue(false);
+ fail();
}
if (test.version > 6) {
Document docInDoc = (Document)doc.getFieldValue("docfield");
- assertTrue(docInDoc != null);
+ assertNotNull(docInDoc);
assertEquals(new StringFieldValue("Elvis is dead"),
docInDoc.getFieldValue("stringindocfield"));
}
Array array = (Array)doc.getFieldValue("arrayoffloatfield");
- assertTrue(array != null);
+ assertNotNull(array);
assertEquals(1.0f, ((FloatFieldValue)array.get(0)).getFloat(), 1E-6);
assertEquals(2.0f, ((FloatFieldValue)array.get(1)).getFloat(), 1E-6);
WeightedSet wset = (WeightedSet)doc.getFieldValue("wsfield");
- assertTrue(wset != null);
+ assertNotNull(wset);
assertEquals(Integer.valueOf(50), wset.get(new StringFieldValue("Weighted 0")));
assertEquals(Integer.valueOf(199), wset.get(new StringFieldValue("Weighted 1")));
}
diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java
index e2bdd846dd1..f1c74ad6efc 100644
--- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java
@@ -3,7 +3,6 @@ package com.yahoo.document;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.yahoo.compress.CompressionType;
import com.yahoo.document.datatypes.Array;
import com.yahoo.document.datatypes.BoolFieldValue;
import com.yahoo.document.datatypes.ByteFieldValue;
@@ -29,8 +28,8 @@ import org.junit.Test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
@@ -217,7 +216,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
doc.setFieldValue("long", longVal);
}
- class VariableIteratorHandler extends FieldPathIteratorHandler {
+ static class VariableIteratorHandler extends FieldPathIteratorHandler {
public String retVal = "";
@@ -462,7 +461,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
}
}
- class RemoveIteratorHandler extends FieldPathIteratorHandler {
+ static class RemoveIteratorHandler extends FieldPathIteratorHandler {
public ModificationStatus doModify(FieldValue fv) {
return ModificationStatus.REMOVED;
@@ -639,17 +638,6 @@ public class DocumentTestCase extends DocumentTestCaseBase {
}
@Test
- public void testCppDocCompressed() throws IOException {
- docMan = setUpCppDocType();
- byte[] data = readFile("src/test/document/serializecpp-lz4-level9.dat");
- ByteBuffer buf = ByteBuffer.wrap(data);
-
- Document doc = docMan.createDocument(new GrowableByteBuffer(buf));
-
- validateCppDoc(doc);
- }
-
- @Test
public void testCppDoc() throws IOException {
docMan = setUpCppDocType();
byte[] data = readFile("src/test/document/serializecpp.dat");
@@ -794,7 +782,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
BufferSerializer buf = new BufferSerializer();
try {
new Document(DocumentDeserializerFactory.create6(docMan, buf.getBuf()));
- assertTrue(false);
+ fail();
} catch (Exception e) {
assertTrue(true);
}
@@ -802,7 +790,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
buf = BufferSerializer.wrap("Hello world".getBytes());
try {
new Document(DocumentDeserializerFactory.create6(docMan, buf.getBuf()));
- assertTrue(false);
+ fail();
} catch (Exception e) {
assertTrue(true);
}
@@ -983,7 +971,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
setUpSertestDocType();
Document doc = getSertestDocument();
String json = doc.toJson();
- Map<String, Object> parsed = new ObjectMapper().readValue(json, new TypeReference<Map<String, Object>>() {
+ Map<String, Object> parsed = new ObjectMapper().readValue(json, new TypeReference<>() {
});
assertEquals(parsed.get("id"), "id:ns:sertest::foobar");
assertTrue(parsed.get("fields") instanceof Map);
@@ -1218,11 +1206,11 @@ public class DocumentTestCase extends DocumentTestCaseBase {
}
@Test
- public void testDocumentIdWithNonTextCharacterCanBeDeserialized() throws UnsupportedEncodingException {
+ public void testDocumentIdWithNonTextCharacterCanBeDeserialized() {
DocumentIdFixture f = new DocumentIdFixture();
// Document id = "id:a:b::0x7c"
- String docId = new String(new byte[]{105, 100, 58, 97, 58, 98, 58, 58, 7, 99}, "UTF-8");
+ String docId = new String(new byte[]{105, 100, 58, 97, 58, 98, 58, 58, 7, 99}, StandardCharsets.UTF_8);
f.serialize(docId);
Document result = f.deserialize();