use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.
the class FailingDocumentProcessingTestCase method assertProcessingWorks.
protected void assertProcessingWorks(DocprocService service) {
// Create documents
DocumentType type = new DocumentType("test");
type.addField("test", DataType.STRING);
DocumentPut put1 = new DocumentPut(type, new DocumentId("doc:failing:test:1"));
DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:failing:test:2"));
DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:failing:test:3"));
// Process them
service.process(put1);
service.process(put2);
service.process(put3);
while (service.doWork()) {
}
// Verify
assertEquals(new StringFieldValue("done 3"), put1.getDocument().getFieldValue("test"));
// Due to exception in 2
assertEquals(new StringFieldValue("done 2"), put2.getDocument().getFieldValue("test"));
assertEquals(new StringFieldValue("done 3"), put3.getDocument().getFieldValue("test"));
}
use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.
the class FailingPermanentlyDocumentProcessingTestCase method assertProcessingWorks.
protected void assertProcessingWorks(DocprocService service) {
// Create documents
DocumentType type = new DocumentType("test");
type.addField("test", DataType.STRING);
DocumentPut put1 = new DocumentPut(type, new DocumentId("doc:permanentfailure:test:1"));
DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:permanentfailure:test:2"));
DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:permanentfailure:test:3"));
// Process them
service.process(put1);
service.process(put2);
service.process(put3);
while (service.doWork()) {
}
// Verify
assertEquals(new StringFieldValue("done 3"), put1.getDocument().getFieldValue("test"));
// Due to PERMANENT_FAILURE in 2
assertEquals(new StringFieldValue("done 2"), put2.getDocument().getFieldValue("test"));
// service is disabled now
assertNull(put3.getDocument().getFieldValue("test"));
assertFalse(service.isInService());
service.setInService(true);
while (service.doWork()) {
}
assertEquals(new StringFieldValue("done 3"), put3.getDocument().getFieldValue("test"));
assertTrue(service.isInService());
}
use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testMap.
@Test
public final void testMap() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testmap::whee\"," + " \"fields\": { \"actualmap\": {" + " \"nalle\": \"kalle\", \"tralle\": \"skalle\"}}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue(doc.getField("actualmap"));
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
assertEquals(2, m.size());
assertEquals(new StringFieldValue("kalle"), m.get(new StringFieldValue("nalle")));
assertEquals(new StringFieldValue("skalle"), m.get(new StringFieldValue("tralle")));
}
use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testMapStringToArrayOfInt.
@Test
public final void testMapStringToArrayOfInt() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": { \"bamse\": [1, 2, 3] }}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue("actualMapStringToArrayOfInt");
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
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.datatypes.StringFieldValue 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));
}
Aggregations