use of com.yahoo.document.DocumentUpdate 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.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testUpdateWeighted.
@Test
public final void testUpdateWeighted() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"add\": {" + " \"person\": 37," + " \"another person\": 41}}}}");
Map<String, Integer> weights = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualset");
for (ValueUpdate<?> v : x.getValueUpdates()) {
AddValueUpdate adder = (AddValueUpdate) v;
final String s = ((StringFieldValue) adder.getValue()).getString();
weights.put(s, adder.getWeight());
}
assertEquals(2, weights.size());
final String o = "person";
final String o2 = "another person";
assertTrue(weights.containsKey(o));
assertTrue(weights.containsKey(o2));
assertEquals(Integer.valueOf(37), weights.get(o));
assertEquals(Integer.valueOf(41), weights.get(o2));
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testArithmeticOperators.
@SuppressWarnings({ "cast", "unchecked", "rawtypes" })
@Test
public final void testArithmeticOperators() throws IOException {
Tuple2[] operations = new Tuple2[] { new Tuple2<String, Operator>(UPDATE_DECREMENT, ArithmeticValueUpdate.Operator.SUB), new Tuple2<String, Operator>(UPDATE_DIVIDE, ArithmeticValueUpdate.Operator.DIV), new Tuple2<String, Operator>(UPDATE_INCREMENT, ArithmeticValueUpdate.Operator.ADD), new Tuple2<String, Operator>(UPDATE_MULTIPLY, ArithmeticValueUpdate.Operator.MUL) };
for (Tuple2<String, Operator> operator : operations) {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"match\": {" + " \"element\": \"person\"," + " \"" + (String) operator.first + "\": 13}}}}");
Map<String, Tuple2<Number, Operator>> matches = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualset");
for (ValueUpdate v : x.getValueUpdates()) {
MapValueUpdate adder = (MapValueUpdate) v;
final String key = ((StringFieldValue) adder.getValue()).getString();
Operator op = ((ArithmeticValueUpdate) adder.getUpdate()).getOperator();
Number n = ((ArithmeticValueUpdate) adder.getUpdate()).getOperand();
matches.put(key, new Tuple2<>(n, op));
}
assertEquals(1, matches.size());
final String o = "person";
assertSame(operator.second, matches.get(o).second);
assertEquals(Double.valueOf(13), matches.get(o).first);
}
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testOldAssignToArray.
@Test
public final void testOldAssignToArray() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": {" + " \"assign\": [" + "{ \"key\": \"bamse\", \"value\": [1, 2, 3] }" + "]}}}");
FieldUpdate f = doc.getFieldUpdate("actualMapStringToArrayOfInt");
assertEquals(1, f.size());
AssignValueUpdate assign = (AssignValueUpdate) f.getValueUpdate(0);
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) assign.getValue();
Array<?> a = (Array<?>) m.get(new StringFieldValue("bamse"));
assertEquals(3, a.size());
assertEquals(new IntegerFieldValue(1), a.get(0));
assertEquals(new IntegerFieldValue(2), a.get(1));
assertEquals(new IntegerFieldValue(3), a.get(2));
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method readSingleDocumentUpdate.
@Test
public final void readSingleDocumentUpdate() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": {" + " \"assign\": \"orOther\" }}" + " }"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentUpdate doc = (DocumentUpdate) r.readSingleDocument(DocumentParser.SupportedOperation.UPDATE, "id:unittest:smoke::whee");
FieldUpdate f = doc.getFieldUpdate("something");
assertEquals(1, f.size());
assertTrue(f.getValueUpdate(0) instanceof AssignValueUpdate);
}
Aggregations