use of com.yahoo.document.DocumentUpdate 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());
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method readClearField.
@Test
public final void readClearField() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"int1\": {" + " \"assign\": null }}" + " }"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentUpdate doc = (DocumentUpdate) r.readSingleDocument(DocumentParser.SupportedOperation.UPDATE, "id:unittest:smoke::whee");
FieldUpdate f = doc.getFieldUpdate("int1");
assertEquals(1, f.size());
assertTrue(f.getValueUpdate(0) instanceof ClearValueUpdate);
assertNull(f.getValueUpdate(0).getValue());
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method parseUpdate.
private DocumentUpdate parseUpdate(String json) throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes(json));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentUpdate update = new DocumentUpdate(docType, parseInfo.documentId);
new VespaJsonDocumentReader().readUpdate(parseInfo.fieldsBuffer, update);
return update;
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testUpdateWithConditionAndCreateInDifferentOrdering.
@Test
public final void testUpdateWithConditionAndCreateInDifferentOrdering() {
final int documentsCreated = 106;
List<String> parts = Arrays.asList("\"condition\":\"bla\"", "\"update\": \"id:unittest:testarray::whee\"", " \"fields\": { " + "\"actualarray\": { \"add\": [" + " \"person\",\"another person\"]}}", " \"create\":true");
final Random random = new Random(42);
StringBuilder documents = new StringBuilder("[");
for (int x = 0; x < documentsCreated; x++) {
Collections.shuffle(parts, random);
documents.append("{").append(Joiner.on(",").join(parts)).append("}");
if (x < documentsCreated - 1) {
documents.append(",");
}
}
documents.append("]");
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes(documents.toString()));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
for (int x = 0; x < documentsCreated; x++) {
DocumentUpdate update = (DocumentUpdate) r.next();
checkSimpleArrayAdd(update);
assertThat(update.getCreateIfNonExistent(), is(true));
assertThat(update.getCondition().getSelection(), is("bla"));
}
assertNull(r.next());
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.
@Test
public final void testCompleteFeedWithCreateAndCondition() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
smokeTestDoc(doc);
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
checkSimpleArrayAdd(update);
assertThat(update.getCreateIfNonExistent(), is(true));
assertThat(update.getCondition().getSelection(), is("bla"));
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
Aggregations