Search in sources :

Example 31 with DocumentUpdate

use of com.yahoo.document.DocumentUpdate 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)

Example 32 with DocumentUpdate

use of com.yahoo.document.DocumentUpdate 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());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 33 with DocumentUpdate

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

the class JsonReaderTestCase method testStructUpdate.

@Test
public final void testStructUpdate() throws IOException {
    DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}");
    assertEquals(1, put.getFieldUpdates().size());
    FieldUpdate fu = put.getFieldUpdate(0);
    assertEquals(1, fu.getValueUpdates().size());
    ValueUpdate vu = fu.getValueUpdate(0);
    assertTrue(vu instanceof AssignValueUpdate);
    AssignValueUpdate avu = (AssignValueUpdate) vu;
    assertTrue(avu.getValue() instanceof Struct);
    Struct s = (Struct) avu.getValue();
    assertEquals(2, s.getFieldCount());
    assertEquals(new StringFieldValue("person"), s.getFieldValue(s.getField("sandra")));
    GrowableByteBuffer buf = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
    put.serialize(serializer);
    assertEquals(107, buf.position());
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentSerializer(com.yahoo.document.serialization.DocumentSerializer) FieldUpdate(com.yahoo.document.update.FieldUpdate) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 34 with DocumentUpdate

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

the class JsonReaderTestCase method createAssignUpdateWithTensor.

private DocumentUpdate createAssignUpdateWithTensor(String inputTensor, String tensorFieldName) {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[ { \"update\": \"" + TENSOR_DOC_ID + "\", \"fields\": { \"" + tensorFieldName + "\": {" + "\"assign\": " + (inputTensor != null ? inputTensor : "null") + " } } } ]"));
    JsonReader reader = new JsonReader(types, rawDoc, parserFactory);
    return (DocumentUpdate) reader.next();
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 35 with DocumentUpdate

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

the class JsonReaderTestCase method testUpdateArray.

@Test
public final void testUpdateArray() throws IOException {
    DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}");
    checkSimpleArrayAdd(doc);
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) 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