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