Search in sources :

Example 6 with DocumentRemove

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

the class JsonReaderTestCase method testCompleteFeedWithEmptyDoc.

@Test
public final void testCompleteFeedWithEmptyDoc() {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": {}}" + ", " + "{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": {}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    assertEquals("smoke", doc.getId().getDocType());
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    assertEquals("testarray", update.getId().getDocType());
    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) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 7 with DocumentRemove

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

the class Destination method handleMessage.

public void handleMessage(Message msg) {
    Reply reply = ((DocumentMessage) msg).createReply();
    try {
        switch(msg.getType()) {
            case DocumentProtocol.MESSAGE_GETDOCUMENT:
                reply = new GetDocumentReply(local.get(((GetDocumentMessage) msg).getDocumentId()));
                break;
            case DocumentProtocol.MESSAGE_PUTDOCUMENT:
                local.put(((PutDocumentMessage) msg).getDocumentPut());
                break;
            case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
                local.remove(new DocumentRemove(((RemoveDocumentMessage) msg).getDocumentId()));
                break;
            case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
                local.update(((UpdateDocumentMessage) msg).getDocumentUpdate());
                break;
            default:
                throw new UnsupportedOperationException("Unsupported message type '" + msg.getType() + "'.");
        }
    } catch (Exception e) {
        reply = new EmptyReply();
        reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, e.toString()));
    }
    msg.swapState(reply);
    session.reply(reply);
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) Error(com.yahoo.messagebus.Error)

Example 8 with DocumentRemove

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

the class AbstractDocumentApiTestCase method requireThatSyncSessionWorks.

@Test
public void requireThatSyncSessionWorks() {
    SyncSession session = access().createSyncSession(new SyncParameters());
    DocumentType type = access().getDocumentTypeManager().getDocumentType("music");
    Document doc1 = new Document(type, new DocumentId("doc:music:1"));
    Document doc2 = new Document(type, new DocumentId("doc:music:2"));
    session.put(new DocumentPut(doc1));
    session.put(new DocumentPut(doc2));
    assertEquals(doc1, session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:2")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:2")));
    session.destroy();
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 9 with DocumentRemove

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

the class ApplicationTest method empty_container.

@Test
public void empty_container() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container())))) {
        try {
            app.process(new DocumentRemove(null));
            fail("expected exception");
        } catch (Exception ignore) {
        // no op
        }
        try {
            app.process(new Processing());
            fail("expected exception");
        } catch (Exception ignore) {
        // no op
        }
        try {
            app.search(new Query("?foo"));
            fail("expected exception");
        } catch (Exception ignore) {
        // no op
        }
    }
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) Query(com.yahoo.search.Query) ConnectException(java.net.ConnectException) IOException(java.io.IOException) Processing(com.yahoo.docproc.Processing) Test(org.junit.Test)

Example 10 with DocumentRemove

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

the class SimpleDocumentProcessorTestCase method requireThatProcessingMultipleOperationsWork.

@Test
public void requireThatProcessingMultipleOperationsWork() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentUpdate(type, "doc:this:is:an:update"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")));
    DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
    service.getExecutor().process(p);
    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 DocumentUpdate, is(true));
    assertThat(p.getDocumentOperations().get(2) instanceof DocumentRemove, is(true));
    assertThat(p.getDocumentOperations().get(2).getId().toString(), is("userdoc:foobar:1234:something"));
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

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