diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-06-14 14:41:18 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-06-14 14:41:18 +0200 |
commit | 6ff3df19226036b8ee1bb559f9d73cab40e8d2a0 (patch) | |
tree | 355a7b0623b58983ba655b868341fe479a22eb3d /document/src/test | |
parent | b7f9e7ceaef72489d76683537973b639f8895b84 (diff) |
Remove carriage return
Diffstat (limited to 'document/src/test')
3 files changed, 230 insertions, 230 deletions
diff --git a/document/src/test/java/com/yahoo/document/IncompatibleFieldTypesTest.java b/document/src/test/java/com/yahoo/document/IncompatibleFieldTypesTest.java index 9e0c4e353f2..8ba0bd815ea 100644 --- a/document/src/test/java/com/yahoo/document/IncompatibleFieldTypesTest.java +++ b/document/src/test/java/com/yahoo/document/IncompatibleFieldTypesTest.java @@ -1,44 +1,44 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document;
-
-import com.yahoo.document.datatypes.*;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests for ticket 6394548
- */
-public class IncompatibleFieldTypesTest {
- private DataType arrayOfStrings;
- private StructDataType struct;
- private StructuredFieldValue root;
-
- @Before
- public void setUp() {
- arrayOfStrings = new ArrayDataType(DataType.STRING);
- struct = new StructDataType("fancypants");
- struct.addField(new Field("stringarray", arrayOfStrings, false));
- DataType weightedSetOfStrings = DataType.getWeightedSet(DataType.STRING, false, false);
- struct.addField(new Field("stringws", weightedSetOfStrings, false));
-
- root = struct.createFieldValue();
- root.setFieldValue("stringarray", arrayOfStrings.createFieldValue());
- root.setFieldValue("stringws", weightedSetOfStrings.createFieldValue());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testAddingIncompatibleFieldToArrayFails() {
- System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getClass().getName());
- System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getDataType().toString());
-
- ((Array)root.getFieldValue("stringarray")).add(new IntegerFieldValue(1234));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testAddingIncompatibleFieldToWeightedSetFails() {
- System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getClass().getName());
- System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getDataType().toString());
-
- ((WeightedSet<FieldValue>)root.getFieldValue("stringws")).put(new IntegerFieldValue(1234), 100);
- }
-}
+package com.yahoo.document; + +import com.yahoo.document.datatypes.*; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests for ticket 6394548 + */ +public class IncompatibleFieldTypesTest { + private DataType arrayOfStrings; + private StructDataType struct; + private StructuredFieldValue root; + + @Before + public void setUp() { + arrayOfStrings = new ArrayDataType(DataType.STRING); + struct = new StructDataType("fancypants"); + struct.addField(new Field("stringarray", arrayOfStrings, false)); + DataType weightedSetOfStrings = DataType.getWeightedSet(DataType.STRING, false, false); + struct.addField(new Field("stringws", weightedSetOfStrings, false)); + + root = struct.createFieldValue(); + root.setFieldValue("stringarray", arrayOfStrings.createFieldValue()); + root.setFieldValue("stringws", weightedSetOfStrings.createFieldValue()); + } + + @Test(expected = IllegalArgumentException.class) + public void testAddingIncompatibleFieldToArrayFails() { + System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getClass().getName()); + System.out.println(root.getFieldValue("stringarray").getDataType().createFieldValue().getDataType().toString()); + + ((Array)root.getFieldValue("stringarray")).add(new IntegerFieldValue(1234)); + } + + @Test(expected = IllegalArgumentException.class) + public void testAddingIncompatibleFieldToWeightedSetFails() { + System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getClass().getName()); + System.out.println(root.getFieldValue("stringws").getDataType().createFieldValue().getDataType().toString()); + + ((WeightedSet<FieldValue>)root.getFieldValue("stringws")).put(new IntegerFieldValue(1234), 100); + } +} diff --git a/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java b/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java index ee448bb79b0..6c007bad32a 100644 --- a/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java @@ -1,123 +1,123 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.annotation;
-
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentTypeManager;
-import com.yahoo.document.DocumentTypeManagerConfigurer;
-import com.yahoo.document.StructDataType;
-import com.yahoo.document.datatypes.*;
-import com.yahoo.document.serialization.*;
-import com.yahoo.io.GrowableByteBuffer;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-import static org.junit.Assert.*;
-
-public class Bug6394548TestCase {
- @Test
- public void testSerializeAndDeserializeMultipleAdjacentStructAnnotations() {
- DocumentTypeManager manager = new DocumentTypeManager();
- DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.6394548.cfg");
-
- AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
- AnnotationType featureSetType = registry.getType("morty.RICK_FEATURESET");
- assertNotNull(featureSetType);
-
- Document doc = new Document(manager.getDocumentType("article"), "doc:article:test");
- StringFieldValue sfv = new StringFieldValue("badger waltz");
-
- SpanList root = new SpanList();
- SpanNode node = new Span(0, sfv.getString().length());
- root.add(node);
-
- SpanTree tree = new SpanTree("rick_features", root);
- for (int i = 0; i < 2; ++i) {
- tree.annotate(createBigFeatureSetAnnotation(featureSetType));
- }
-
- sfv.setSpanTree(tree);
- doc.setFieldValue("title", sfv);
- System.out.println(doc.toXml());
- String annotationsBefore = dumpAllAnnotations(tree);
-
- GrowableByteBuffer buffer = new GrowableByteBuffer();
- DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
- serializer.write(doc);
-
- buffer.flip();
- DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buffer);
- Document doc2 = new Document(deserializer);
-
- System.out.println(doc2.toXml());
-
- StringFieldValue readString = (StringFieldValue)doc2.getFieldValue("title");
- SpanTree readTree = readString.getSpanTree("rick_features");
- assertNotNull(readTree);
- String annotationsAfter = dumpAllAnnotations(readTree);
-
- System.out.println("before:\n" + annotationsBefore);
- System.out.println("after:\n" + annotationsAfter);
-
- assertEquals(annotationsBefore, annotationsAfter);
- }
-
- private String dumpAllAnnotations(SpanTree tree) {
- ArrayList<String> tmp = new ArrayList<>();
- for (Annotation anno : tree) {
- Struct s = (Struct)anno.getFieldValue();
- tmp.add(s.toXml());
- }
- Collections.sort(tmp);
- StringBuilder annotations = new StringBuilder();
- for (String s : tmp) {
- annotations.append(s);
- }
- return annotations.toString();
- }
-
- private Annotation createBigFeatureSetAnnotation(AnnotationType featuresetAnno) {
- StructDataType featuresetType = (StructDataType)featuresetAnno.getDataType();
- Struct featureset = featuresetType.createFieldValue();
- System.out.println("featureset type: " + featureset.getDataType().toString());
-
- MapFieldValue<StringFieldValue, IntegerFieldValue> discreteValued
- = (MapFieldValue<StringFieldValue, IntegerFieldValue>)featuresetType.getField("discretevaluedfeatures").getDataType().createFieldValue();
- discreteValued.put(new StringFieldValue("foo"), new IntegerFieldValue(1234));
- discreteValued.put(new StringFieldValue("bar"), new IntegerFieldValue(567890123));
- featureset.setFieldValue("discretevaluedfeatures", discreteValued);
-
- MapFieldValue<StringFieldValue, DoubleFieldValue> realValued
- = (MapFieldValue<StringFieldValue, DoubleFieldValue>)featuresetType.getField("realvaluedfeatures").getDataType().createFieldValue();
- realValued.put(new StringFieldValue("foo"), new DoubleFieldValue(0.75));
- realValued.put(new StringFieldValue("bar"), new DoubleFieldValue(1.5));
- featureset.setFieldValue("realvaluedfeatures", realValued);
-
- Array<StringFieldValue> nested = (Array<StringFieldValue>)featureset.getField("foo10").getDataType().createFieldValue();
- nested.add(new StringFieldValue("baz"));
- nested.add(new StringFieldValue("blargh"));
- featureset.setFieldValue("foo10", nested);
-
- featureset.setFieldValue("foo1", new StringFieldValue("asdf"));
- featureset.setFieldValue("foo4", new StringFieldValue("qwerty"));
- featureset.setFieldValue("foo2", new IntegerFieldValue(555));
- featureset.setFieldValue("foo2", new IntegerFieldValue(8));
- featureset.setFieldValue("foo7", new IntegerFieldValue(1337));
- featureset.setFieldValue("foo8", new IntegerFieldValue(967867));
- featureset.setFieldValue("foo9", new DoubleFieldValue(123.45));
-
- Array<StringFieldValue> attributes = (Array<StringFieldValue>)featureset.getField("foo6").getDataType().createFieldValue();
- attributes.add(new StringFieldValue("adam"));
- attributes.add(new StringFieldValue("jamie"));
- attributes.add(new StringFieldValue("grant"));
- attributes.add(new StringFieldValue("tory"));
- attributes.add(new StringFieldValue("kari"));
- featureset.setFieldValue("variantattribute", attributes);
-
- Annotation anno = new Annotation(featuresetAnno);
- anno.setFieldValue(featureset);
-
- return anno;
- }
-}
+package com.yahoo.document.annotation; + +import com.yahoo.document.Document; +import com.yahoo.document.DocumentTypeManager; +import com.yahoo.document.DocumentTypeManagerConfigurer; +import com.yahoo.document.StructDataType; +import com.yahoo.document.datatypes.*; +import com.yahoo.document.serialization.*; +import com.yahoo.io.GrowableByteBuffer; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; + +import static org.junit.Assert.*; + +public class Bug6394548TestCase { + @Test + public void testSerializeAndDeserializeMultipleAdjacentStructAnnotations() { + DocumentTypeManager manager = new DocumentTypeManager(); + DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.6394548.cfg"); + + AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry(); + AnnotationType featureSetType = registry.getType("morty.RICK_FEATURESET"); + assertNotNull(featureSetType); + + Document doc = new Document(manager.getDocumentType("article"), "doc:article:test"); + StringFieldValue sfv = new StringFieldValue("badger waltz"); + + SpanList root = new SpanList(); + SpanNode node = new Span(0, sfv.getString().length()); + root.add(node); + + SpanTree tree = new SpanTree("rick_features", root); + for (int i = 0; i < 2; ++i) { + tree.annotate(createBigFeatureSetAnnotation(featureSetType)); + } + + sfv.setSpanTree(tree); + doc.setFieldValue("title", sfv); + System.out.println(doc.toXml()); + String annotationsBefore = dumpAllAnnotations(tree); + + GrowableByteBuffer buffer = new GrowableByteBuffer(); + DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer); + serializer.write(doc); + + buffer.flip(); + DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buffer); + Document doc2 = new Document(deserializer); + + System.out.println(doc2.toXml()); + + StringFieldValue readString = (StringFieldValue)doc2.getFieldValue("title"); + SpanTree readTree = readString.getSpanTree("rick_features"); + assertNotNull(readTree); + String annotationsAfter = dumpAllAnnotations(readTree); + + System.out.println("before:\n" + annotationsBefore); + System.out.println("after:\n" + annotationsAfter); + + assertEquals(annotationsBefore, annotationsAfter); + } + + private String dumpAllAnnotations(SpanTree tree) { + ArrayList<String> tmp = new ArrayList<>(); + for (Annotation anno : tree) { + Struct s = (Struct)anno.getFieldValue(); + tmp.add(s.toXml()); + } + Collections.sort(tmp); + StringBuilder annotations = new StringBuilder(); + for (String s : tmp) { + annotations.append(s); + } + return annotations.toString(); + } + + private Annotation createBigFeatureSetAnnotation(AnnotationType featuresetAnno) { + StructDataType featuresetType = (StructDataType)featuresetAnno.getDataType(); + Struct featureset = featuresetType.createFieldValue(); + System.out.println("featureset type: " + featureset.getDataType().toString()); + + MapFieldValue<StringFieldValue, IntegerFieldValue> discreteValued + = (MapFieldValue<StringFieldValue, IntegerFieldValue>)featuresetType.getField("discretevaluedfeatures").getDataType().createFieldValue(); + discreteValued.put(new StringFieldValue("foo"), new IntegerFieldValue(1234)); + discreteValued.put(new StringFieldValue("bar"), new IntegerFieldValue(567890123)); + featureset.setFieldValue("discretevaluedfeatures", discreteValued); + + MapFieldValue<StringFieldValue, DoubleFieldValue> realValued + = (MapFieldValue<StringFieldValue, DoubleFieldValue>)featuresetType.getField("realvaluedfeatures").getDataType().createFieldValue(); + realValued.put(new StringFieldValue("foo"), new DoubleFieldValue(0.75)); + realValued.put(new StringFieldValue("bar"), new DoubleFieldValue(1.5)); + featureset.setFieldValue("realvaluedfeatures", realValued); + + Array<StringFieldValue> nested = (Array<StringFieldValue>)featureset.getField("foo10").getDataType().createFieldValue(); + nested.add(new StringFieldValue("baz")); + nested.add(new StringFieldValue("blargh")); + featureset.setFieldValue("foo10", nested); + + featureset.setFieldValue("foo1", new StringFieldValue("asdf")); + featureset.setFieldValue("foo4", new StringFieldValue("qwerty")); + featureset.setFieldValue("foo2", new IntegerFieldValue(555)); + featureset.setFieldValue("foo2", new IntegerFieldValue(8)); + featureset.setFieldValue("foo7", new IntegerFieldValue(1337)); + featureset.setFieldValue("foo8", new IntegerFieldValue(967867)); + featureset.setFieldValue("foo9", new DoubleFieldValue(123.45)); + + Array<StringFieldValue> attributes = (Array<StringFieldValue>)featureset.getField("foo6").getDataType().createFieldValue(); + attributes.add(new StringFieldValue("adam")); + attributes.add(new StringFieldValue("jamie")); + attributes.add(new StringFieldValue("grant")); + attributes.add(new StringFieldValue("tory")); + attributes.add(new StringFieldValue("kari")); + featureset.setFieldValue("variantattribute", attributes); + + Annotation anno = new Annotation(featuresetAnno); + anno.setFieldValue(featureset); + + return anno; + } +} diff --git a/document/src/test/java/com/yahoo/document/annotation/Bug6425939TestCase.java b/document/src/test/java/com/yahoo/document/annotation/Bug6425939TestCase.java index d34d0da8e82..68a97bc557c 100644 --- a/document/src/test/java/com/yahoo/document/annotation/Bug6425939TestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/Bug6425939TestCase.java @@ -1,66 +1,66 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.annotation;
-
-import com.yahoo.document.DataType;
-import com.yahoo.document.DocumentTypeManager;
-import com.yahoo.document.Field;
-import com.yahoo.document.StructDataType;
-import com.yahoo.document.datatypes.StringFieldValue;
-import com.yahoo.document.datatypes.Struct;
-import com.yahoo.document.serialization.*;
-import com.yahoo.io.GrowableByteBuffer;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class Bug6425939TestCase {
- private DocumentTypeManager man;
- private StructDataType person;
- private AnnotationType personA;
-
- @Before
- public void setUp() {
- man = new DocumentTypeManager();
-
- person = new StructDataType("personStruct");
- person.addField(new Field("foo", DataType.STRING));
- person.addField(new Field("bar", DataType.INT));
- man.register(person);
-
- personA = new AnnotationType("person", person);
- man.getAnnotationTypeRegistry().register(personA);
- }
-
- @Test
- public void canDeserializeAnnotationsOnZeroLengthStrings() {
- StringFieldValue emptyString = new StringFieldValue("");
- emptyString.setSpanTree(createSpanTree());
-
- GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
- DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
- Field strField = new Field("flarn", DataType.STRING);
- serializer.write(strField, emptyString);
- buffer.flip();
-
- // Should not throw exception if bug 6425939 is fixed:
- DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
- StringFieldValue deserializedString = new StringFieldValue();
- deserializer.read(strField, deserializedString);
-
- assertEquals("", deserializedString.getString());
- SpanTree readTree = deserializedString.getSpanTree("SpanTree1");
- assertNotNull(readTree);
- }
-
- private SpanTree createSpanTree() {
- SpanList root = new SpanList();
- SpanTree tree = new SpanTree("SpanTree1", root);
- SpanNode node = new Span(0, 0);
- Struct ps = new Struct(person);
- ps.setFieldValue("foo", "epic badger");
- ps.setFieldValue("bar", 54321);
- tree.annotate(node, new Annotation(personA, ps));
- root.add(node);
- return tree;
- }
-}
+package com.yahoo.document.annotation; + +import com.yahoo.document.DataType; +import com.yahoo.document.DocumentTypeManager; +import com.yahoo.document.Field; +import com.yahoo.document.StructDataType; +import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.document.datatypes.Struct; +import com.yahoo.document.serialization.*; +import com.yahoo.io.GrowableByteBuffer; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class Bug6425939TestCase { + private DocumentTypeManager man; + private StructDataType person; + private AnnotationType personA; + + @Before + public void setUp() { + man = new DocumentTypeManager(); + + person = new StructDataType("personStruct"); + person.addField(new Field("foo", DataType.STRING)); + person.addField(new Field("bar", DataType.INT)); + man.register(person); + + personA = new AnnotationType("person", person); + man.getAnnotationTypeRegistry().register(personA); + } + + @Test + public void canDeserializeAnnotationsOnZeroLengthStrings() { + StringFieldValue emptyString = new StringFieldValue(""); + emptyString.setSpanTree(createSpanTree()); + + GrowableByteBuffer buffer = new GrowableByteBuffer(1024); + DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer); + Field strField = new Field("flarn", DataType.STRING); + serializer.write(strField, emptyString); + buffer.flip(); + + // Should not throw exception if bug 6425939 is fixed: + DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer); + StringFieldValue deserializedString = new StringFieldValue(); + deserializer.read(strField, deserializedString); + + assertEquals("", deserializedString.getString()); + SpanTree readTree = deserializedString.getSpanTree("SpanTree1"); + assertNotNull(readTree); + } + + private SpanTree createSpanTree() { + SpanList root = new SpanList(); + SpanTree tree = new SpanTree("SpanTree1", root); + SpanNode node = new Span(0, 0); + Struct ps = new Struct(person); + ps.setFieldValue("foo", "epic badger"); + ps.setFieldValue("bar", 54321); + tree.annotate(node, new Annotation(personA, ps)); + root.add(node); + return tree; + } +} |