Search in sources :

Example 11 with DocumentTypeManager

use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.

the class SpanTreeTestCase method testCyclicReferences.

@Test
public void testCyclicReferences() {
    DocumentTypeManager docMan = new DocumentTypeManager();
    AnnotationTypeRegistry reg = docMan.getAnnotationTypeRegistry();
    StringFieldValue strfval = new StringFieldValue("hohohoho");
    SpanList root = new SpanList();
    SpanTree tree = new SpanTree("habahaba", root);
    strfval.setSpanTree(tree);
    // set up types:
    AnnotationType endTagType = new AnnotationType("endtag");
    AnnotationType beginTagType = new AnnotationType("begintag");
    AnnotationReferenceDataType refToBeginTagDataType = new AnnotationReferenceDataType(beginTagType);
    AnnotationReferenceDataType refToEndTagDataType = new AnnotationReferenceDataType(endTagType);
    endTagType.setDataType(refToBeginTagDataType);
    beginTagType.setDataType(refToEndTagDataType);
    // register types:
    reg.register(endTagType);
    reg.register(beginTagType);
    docMan.register(refToBeginTagDataType);
    docMan.register(refToEndTagDataType);
    // set up annotations and their references to each other:
    AnnotationReference refToBeginTag = new AnnotationReference(refToBeginTagDataType);
    AnnotationReference refToEndTag = new AnnotationReference(refToEndTagDataType);
    Annotation beginTag = new Annotation(beginTagType, refToEndTag);
    Annotation endTag = new Annotation(endTagType, refToBeginTag);
    refToBeginTag.setReference(beginTag);
    refToEndTag.setReference(endTag);
    // create spans:
    Span beginTagSpan = new Span(0, 1);
    Span endTagSpan = new Span(1, 1);
    root.add(beginTagSpan);
    root.add(endTagSpan);
    // annotate spans:
    tree.annotate(beginTagSpan, beginTag);
    tree.annotate(endTagSpan, endTag);
    // none of the below statements should lead to a StackOverflowError:
    assertFalse(endTag.toString().equals(beginTag.toString()));
    assertTrue(endTag.hashCode() != beginTag.hashCode());
    assertFalse(endTag.equals(beginTag));
    assertFalse(beginTag.equals(endTag));
    StringFieldValue copyString = strfval.clone();
    assertEquals(strfval, copyString);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(new Field("stringfield", DataType.STRING), strfval);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(docMan, buffer);
    StringFieldValue stringFieldValue2 = new StringFieldValue();
    deserializer.read(new Field("stringfield", DataType.STRING), stringFieldValue2);
    assertEquals(strfval, stringFieldValue2);
    assertNotSame(strfval, stringFieldValue2);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Example 12 with DocumentTypeManager

use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.

the class XMLNumericFieldErrorMsgTestCase method setupTypes.

private static DocumentTypeManager setupTypes() {
    DocumentTypeManager dtm = new DocumentTypeManager();
    DocumentType docType = new DocumentType("doctype");
    docType.addField("bytefield", DataType.BYTE);
    docType.addField("intfield", DataType.INT);
    docType.addField("longfield", DataType.LONG);
    docType.addField("floatfield", DataType.FLOAT);
    docType.addField("doublefield", DataType.DOUBLE);
    dtm.register(docType);
    return dtm;
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType)

Example 13 with DocumentTypeManager

use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForIntegers.

@Test
public void requireDescriptiveErrorMsgForIntegers() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <intfield></intfield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'intfield': Invalid integer \"\""), is(true));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Document(com.yahoo.document.Document) DeserializationException(com.yahoo.document.serialization.DeserializationException) Test(org.junit.Test)

Example 14 with DocumentTypeManager

use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForFloats.

@Test
public void requireDescriptiveErrorMsgForFloats() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <floatfield></floatfield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'floatfield': Invalid float \"\""), is(true));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Document(com.yahoo.document.Document) DeserializationException(com.yahoo.document.serialization.DeserializationException) Test(org.junit.Test)

Example 15 with DocumentTypeManager

use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.

the class Bug6394548TestCase method testSerializeAndDeserializeMultipleAdjacentStructAnnotations.

@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);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Aggregations

DocumentTypeManager (com.yahoo.document.DocumentTypeManager)35 Test (org.junit.Test)18 DocumentType (com.yahoo.document.DocumentType)17 Document (com.yahoo.document.Document)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)7 Field (com.yahoo.document.Field)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DeserializationException (com.yahoo.document.serialization.DeserializationException)5 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)5 DocumentPut (com.yahoo.document.DocumentPut)4 IlscriptsConfig (com.yahoo.vespa.configdefinition.IlscriptsConfig)4 StructDataType (com.yahoo.document.StructDataType)3 Before (org.junit.Before)3 DocumentUpdate (com.yahoo.document.DocumentUpdate)2 DocumentmanagerConfig (com.yahoo.document.config.DocumentmanagerConfig)2 Array (com.yahoo.document.datatypes.Array)2 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)2 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)2 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)2 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)2