Search in sources :

Example 11 with DocumentPut

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

the class TransientFailureTestCase method testTransientFailures.

public void testTransientFailures() {
    DocprocService service = new DocprocService("transfail");
    CallStack stack = new CallStack();
    stack.addNext(new OkDocProc()).addNext(new TransientFailDocProc());
    service.setCallStack(stack);
    service.setInService(true);
    EndpointSupportingTransientFailures endpoint = new EndpointSupportingTransientFailures();
    DocumentPut put;
    put = new DocumentPut(type, new DocumentId("doc:transfail:bad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(0, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(0, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:verybad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(0, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(1, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:good"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(1, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(1, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:veryverybad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(1, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(2, endpoint.numFail);
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId)

Example 12 with DocumentPut

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

the class SplitterJoinerTestCase method testSplitJoin.

@Test
public void testSplitJoin() {
    ConfigGetter<SplitterJoinerDocumentProcessorConfig> getter = new ConfigGetter<>(SplitterJoinerDocumentProcessorConfig.class);
    ConfigGetter<DocumentmanagerConfig> docManGetter = new ConfigGetter<>(DocumentmanagerConfig.class);
    SplitterJoinerDocumentProcessorConfig cfg = getter.getConfig("file:src/test/java/com/yahoo/docproc/util/splitter-joiner-document-processor.cfg");
    DocumentmanagerConfig docManCfg = docManGetter.getConfig("file:src/test/java/com/yahoo/docproc/util/documentmanager.docindoc.cfg");
    SplitterDocumentProcessor splitter = new SplitterDocumentProcessor(cfg, docManCfg);
    DocumentTypeManager manager = splitter.manager;
    /**
     ** Create documents: ***
     */
    Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
    inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
    inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
    Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
    inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
    inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
    Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
    innerArray.add(inner1);
    innerArray.add(inner2);
    Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
    outer.setFieldValue("innerdocuments", innerArray);
    /**
     ** End create documents ***
     */
    Processing p = Processing.of(new DocumentPut(outer));
    splitter.process(p);
    assertEquals(2, p.getDocumentOperations().size());
    assertThat(((DocumentPut) (p.getDocumentOperations().get(0))).getDocument(), sameInstance(inner1));
    assertThat(((DocumentPut) (p.getDocumentOperations().get(1))).getDocument(), sameInstance(inner2));
    assertThat(((DocumentPut) (p.getVariable(cfg.contextFieldName()))).getDocument(), sameInstance(outer));
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertTrue(innerArray.isEmpty());
    JoinerDocumentProcessor joiner = new JoinerDocumentProcessor(cfg, docManCfg);
    joiner.process(p);
    assertThat(p.getDocumentOperations().size(), equalTo(1));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument(), sameInstance(outer));
    assertThat(p.getVariable(cfg.contextFieldName()), nullValue());
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertThat(innerArray.size(), equalTo(2));
    assertThat(innerArray.get(0), sameInstance(inner1));
    assertThat(innerArray.get(1), sameInstance(inner2));
}
Also used : ConfigGetter(com.yahoo.config.subscription.ConfigGetter) DocumentPut(com.yahoo.document.DocumentPut) SplitterJoinerDocumentProcessorConfig(com.yahoo.config.docproc.SplitterJoinerDocumentProcessorConfig) Document(com.yahoo.document.Document) Processing(com.yahoo.docproc.Processing) Array(com.yahoo.document.datatypes.Array) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Example 13 with DocumentPut

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

the class SplitterDocumentProcessor method process.

@Override
public Progress process(Processing processing) {
    if (processing.getDocumentOperations().size() != 1) {
        // we were given more than one document, return
        log.log(LogLevel.DEBUG, "More than one document given, returning. (Was given " + processing.getDocumentOperations().size() + " documents).");
        return Progress.DONE;
    }
    if (!doProcessOuterDocument(processing.getDocumentOperations().get(0), documentTypeName)) {
        return Progress.DONE;
    }
    Document outerDoc = ((DocumentPut) processing.getDocumentOperations().get(0)).getDocument();
    ;
    @SuppressWarnings("unchecked") Array<Document> innerDocuments = (Array<Document>) outerDoc.getFieldValue(arrayFieldName);
    if (innerDocuments == null) {
        // the document does not have the field, return
        log.log(LogLevel.DEBUG, "The given Document does not have a field value for field " + arrayFieldName + ", returning. (Was given " + outerDoc + ").");
        return Progress.DONE;
    }
    if (innerDocuments.size() == 0) {
        // the array is empty, return
        log.log(LogLevel.DEBUG, "The given Document does not have any elements in array field " + arrayFieldName + ", returning. (Was given " + outerDoc + ").");
        return Progress.DONE;
    }
    split(processing, innerDocuments);
    return Progress.DONE;
}
Also used : Array(com.yahoo.document.datatypes.Array) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 14 with DocumentPut

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

the class FailingDocumentProcessingWithoutExceptionTestCase method assertProcessingWorks.

protected void assertProcessingWorks(DocprocService service) {
    // Create documents
    DocumentType type = new DocumentType("test");
    type.addField("test", DataType.STRING);
    DocumentPut put1 = new DocumentPut(type, new DocumentId("doc:woexception:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:woexception:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:woexception:test:3"));
    // Process them
    service.process(put1);
    service.process(put2);
    service.process(put3);
    while (service.doWork()) {
    }
    // Verify
    assertEquals(new StringFieldValue("done 3"), put1.getDocument().getFieldValue("test"));
    // Due to PROCESSING_FAILED in 2
    assertEquals(new StringFieldValue("done 2"), put2.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done 3"), put3.getDocument().getFieldValue("test"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Example 15 with DocumentPut

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

the class FailingWithErrorTestCase method testErrors.

public void testErrors() {
    DocprocService service = new DocprocService("failing");
    DocumentProcessor first = new ErrorThrowingProcessor();
    service.setCallStack(new CallStack().addLast(first));
    service.setInService(true);
    DocumentType type = new DocumentType("test");
    type.addField("test", DataType.STRING);
    DocumentPut put = new DocumentPut(type, new DocumentId("doc:failing:test:1"));
    put.getDocument().setFieldValue("test", "foobar");
    service.process(put);
    assertEquals(1, service.getQueueSize());
    try {
        while (service.doWork()) {
        }
        fail("Should have gotten OOME here");
    } catch (Throwable t) {
        // we don't want a finally block in doWork()!
        assertEquals(0, service.getQueueSize());
    }
    assertEquals(0, service.getQueueSize());
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Aggregations

DocumentPut (com.yahoo.document.DocumentPut)67 Document (com.yahoo.document.Document)40 DocumentType (com.yahoo.document.DocumentType)35 Test (org.junit.Test)30 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 DocumentOperation (com.yahoo.document.DocumentOperation)13 DocumentId (com.yahoo.document.DocumentId)12 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)11 FieldValue (com.yahoo.document.datatypes.FieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)10 DocumentRemove (com.yahoo.document.DocumentRemove)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)7 Array (com.yahoo.document.datatypes.Array)7 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)6 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)5