Search in sources :

Example 16 with DocumentPut

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

the class ProcessingUpdateTestCase method testProcessingUpdates.

public void testProcessingUpdates() {
    DocumentType articleType = new DocumentType("article");
    articleType.addField(new Field("body", DataType.STRING, true));
    articleType.addField(new Field("title", DataType.STRING, true));
    dtm = new DocumentTypeManager();
    dtm.registerDocumentType(articleType);
    put = new DocumentPut(articleType, "doc:banana:apple");
    put.getDocument().setFieldValue("body", "this is the body of the article, blah blah blah");
    FieldUpdate upd = FieldUpdate.createAssign(articleType.getField("body"), new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"));
    update = new DocumentUpdate(articleType, new DocumentId("doc:grape:orange"));
    update.addFieldUpdate(upd);
    DocprocService service = new DocprocService("update");
    DocumentProcessor firstP = new TitleDocumentProcessor();
    service.setCallStack(new CallStack().addLast(firstP));
    service.setInService(true);
    Processing p = new Processing();
    p.addDocumentOperation(put);
    p.addDocumentOperation(update);
    service.process(p);
    while (service.doWork()) {
    }
    List<DocumentOperation> operations = p.getDocumentOperations();
    Document first = ((DocumentPut) operations.get(0)).getDocument();
    assertEquals(new StringFieldValue("this is the body of the article, blah blah blah"), first.getFieldValue("body"));
    assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
    DocumentUpdate second = (DocumentUpdate) operations.get(1);
    FieldUpdate firstUpd = second.getFieldUpdate(0);
    assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
    assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0).getValue());
    FieldUpdate secondUpd = second.getFieldUpdate(1);
    assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
    assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 17 with DocumentPut

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

the class DocprocExecutor method logProgress.

private void logProgress(Processing processing, DocumentProcessor.Progress progress, Call call) {
    StringBuilder message = new StringBuilder();
    boolean first = true;
    message.append(call.getDocumentProcessorId()).append(" of class ").append(call.getDocumentProcessor().getClass().getSimpleName()).append(" returned ").append(progress).append(" for the documents: [");
    for (DocumentOperation op : processing.getDocumentOperations()) {
        if (first) {
            first = false;
        } else {
            message.append(", ");
        }
        if (op instanceof DocumentPut) {
            message.append(Utf8.toString(JsonWriter.toByteArray(((DocumentPut) op).getDocument())));
        } else {
            message.append(op.toString());
        }
    }
    message.append("]");
    log.log(LogLevel.SPAM, message.toString());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut)

Example 18 with DocumentPut

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

the class DocumentProcessingAbstractTestCase method assertProcessingWorks.

/**
 * Asserts that a document processing service works
 */
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:test:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:test:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:test:test:3"));
    // Process them
    service.process(put1);
    service.process(put2);
    service.process(put3);
    while (service.doWork()) {
    }
    // Verify
    assertEquals(new StringFieldValue("done"), put1.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done"), put2.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done"), 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 19 with DocumentPut

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

the class FailingDocumentProcessingTestCase 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:failing:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:failing:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:failing: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 exception 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 20 with DocumentPut

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

the class FailingPermanentlyDocumentProcessingTestCase 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:permanentfailure:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:permanentfailure:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:permanentfailure: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 PERMANENT_FAILURE in 2
    assertEquals(new StringFieldValue("done 2"), put2.getDocument().getFieldValue("test"));
    // service is disabled now
    assertNull(put3.getDocument().getFieldValue("test"));
    assertFalse(service.isInService());
    service.setInService(true);
    while (service.doWork()) {
    }
    assertEquals(new StringFieldValue("done 3"), put3.getDocument().getFieldValue("test"));
    assertTrue(service.isInService());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) 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