Search in sources :

Example 11 with DocumentRemove

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

the class SimpleDocumentProcessorTestCase method requireThatThrowingTerminatesIteration.

@Test
public void requireThatThrowingTerminatesIteration() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")), new DocumentPut(type, "doc:this:is:a:document2"));
    DocprocService service = setupDocprocService(new SimpleDocumentProcessorThrowingOnRemovesAndUpdates());
    try {
        service.getExecutor().process(p);
    } catch (RuntimeException re) {
    // ok
    }
    assertThat(p.getDocumentOperations().size(), is(3));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
    assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true));
    assertThat(p.getDocumentOperations().get(1).getId().toString(), is("doc:this:is:a:remove"));
    assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), nullValue());
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 12 with DocumentRemove

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

the class JsonReaderTestCase method controlBasicFeed.

protected void controlBasicFeed(JsonReader r) {
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    smokeTestDoc(doc);
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    checkSimpleArrayAdd(update);
    d = r.next();
    DocumentRemove remove = (DocumentRemove) d;
    assertEquals("smoke", remove.getId().getDocType());
    assertNull(r.next());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 13 with DocumentRemove

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

the class VespaJsonDocumentReader method createDocumentOperation.

public DocumentOperation createDocumentOperation(DocumentType documentType, DocumentParseInfo documentParseInfo) {
    final DocumentOperation documentOperation;
    try {
        switch(documentParseInfo.operationType) {
            case PUT:
                documentOperation = new DocumentPut(new Document(documentType, documentParseInfo.documentId));
                readPut(documentParseInfo.fieldsBuffer, (DocumentPut) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            case REMOVE:
                documentOperation = new DocumentRemove(documentParseInfo.documentId);
                break;
            case UPDATE:
                documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId);
                readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            default:
                throw new IllegalStateException("Implementation out of sync with itself. This is a bug.");
        }
    } catch (JsonReaderException e) {
        throw JsonReaderException.addDocId(e, documentParseInfo.documentId);
    }
    if (documentParseInfo.create.isPresent()) {
        if (!(documentOperation instanceof DocumentUpdate)) {
            throw new RuntimeException("Could not set create flag on non update operation.");
        }
        DocumentUpdate update = (DocumentUpdate) documentOperation;
        update.setCreateIfNonExistent(documentParseInfo.create.get());
    }
    return documentOperation;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentUpdate(com.yahoo.document.DocumentUpdate) JsonReaderException(com.yahoo.document.json.JsonReaderException) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Aggregations

DocumentRemove (com.yahoo.document.DocumentRemove)13 DocumentPut (com.yahoo.document.DocumentPut)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)6 Test (org.junit.Test)6 Document (com.yahoo.document.Document)5 DocumentOperation (com.yahoo.document.DocumentOperation)5 DocumentId (com.yahoo.document.DocumentId)4 DocumentType (com.yahoo.document.DocumentType)3 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)2 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)2 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)2 Message (com.yahoo.messagebus.Message)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Tuple2 (com.yahoo.collections.Tuple2)1 Processing (com.yahoo.docproc.Processing)1 TestAndSetCondition (com.yahoo.document.TestAndSetCondition)1 JsonReaderException (com.yahoo.document.json.JsonReaderException)1 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 SyncSession (com.yahoo.documentapi.SyncSession)1