Search in sources :

Example 11 with DocumentUpdate

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());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 12 with DocumentUpdate

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());
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) Test(org.junit.Test)

Example 13 with DocumentUpdate

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;
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentType(com.yahoo.document.DocumentType) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader)

Example 14 with DocumentUpdate

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());
}
Also used : Random(java.util.Random) DocumentUpdate(com.yahoo.document.DocumentUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 15 with DocumentUpdate

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

Aggregations

DocumentUpdate (com.yahoo.document.DocumentUpdate)43 Test (org.junit.Test)24 FieldUpdate (com.yahoo.document.update.FieldUpdate)16 DocumentType (com.yahoo.document.DocumentType)15 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)12 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InputStream (java.io.InputStream)9 Document (com.yahoo.document.Document)8 DocumentOperation (com.yahoo.document.DocumentOperation)8 DocumentPut (com.yahoo.document.DocumentPut)7 DocumentRemove (com.yahoo.document.DocumentRemove)6 DocumentId (com.yahoo.document.DocumentId)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 ValueUpdate (com.yahoo.document.update.ValueUpdate)5 HashMap (java.util.HashMap)5