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());
}
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);
}
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();
}
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
}
}
}
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"));
}
Aggregations