Search in sources :

Example 6 with DocumentOperation

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

the class IndexingProcessorTestCase method requireThatIndexerForwardsUpdatesOfUnknownType.

@Test
public void requireThatIndexerForwardsUpdatesOfUnknownType() {
    DocumentUpdate input = new DocumentUpdate(new DocumentType("unknown"), "doc:scheme:");
    DocumentOperation output = process(input);
    assertSame(input, output);
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 7 with DocumentOperation

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

the class IndexingProcessorTestCase method process.

private DocumentOperation process(DocumentOperation input) {
    Processing proc = new Processing();
    proc.getDocumentOperations().add(input);
    indexer.process(proc);
    List<DocumentOperation> lst = proc.getDocumentOperations();
    assertEquals(1, lst.size());
    return lst.get(0);
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) Processing(com.yahoo.docproc.Processing)

Example 8 with DocumentOperation

use of com.yahoo.document.DocumentOperation 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 9 with DocumentOperation

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

the class MbusRequestContext method processingDone.

@Override
public void processingDone(List<Processing> processings) {
    List<DocumentMessage> messages = new ArrayList<>();
    if (messageFactory != null) {
        for (Processing processing : processings) {
            for (DocumentOperation documentOperation : processing.getDocumentOperations()) {
                messages.add(messageFactory.fromDocumentOperation(processing, documentOperation));
            }
        }
    }
    if (log.isLoggable(LogLevel.DEBUG)) {
        log.log(LogLevel.DEBUG, "Forwarding " + messages.size() + " messages from " + processings.size() + " processings.");
    }
    if (messages.isEmpty()) {
        dispatchResponse(Response.Status.OK);
        return;
    }
    long inputSequenceId = requestMsg.getSequenceId();
    ResponseMerger responseHandler = new ResponseMerger(requestMsg, messages.size(), this);
    for (Message message : messages) {
        // See comment for internalNoThrottledSource.
        dispatchRequest(message, (inputSequenceId == message.getSequenceId()) ? getUri().getPath() : "/" + internalNoThrottledSource, responseHandler);
    }
}
Also used : DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) DocumentOperation(com.yahoo.document.DocumentOperation) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) ArrayList(java.util.ArrayList) Processing(com.yahoo.docproc.Processing)

Example 10 with DocumentOperation

use of com.yahoo.document.DocumentOperation 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)

Aggregations

DocumentOperation (com.yahoo.document.DocumentOperation)23 DocumentPut (com.yahoo.document.DocumentPut)13 Document (com.yahoo.document.Document)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Test (org.junit.Test)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentType (com.yahoo.document.DocumentType)5 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DocumentId (com.yahoo.document.DocumentId)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Processing (com.yahoo.docproc.Processing)2 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)2 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)2 FieldUpdate (com.yahoo.document.update.FieldUpdate)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 SplitterDocumentProcessor.doProcessOuterDocument (com.yahoo.docproc.util.SplitterDocumentProcessor.doProcessOuterDocument)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1 Field (com.yahoo.document.Field)1