use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.
the class ApplicationPackageXmlFilesValidator method validateRouting.
private void validateRouting(SchemaValidator validator, Tuple2<File, String> directory) throws IOException {
File dir = directory.first;
if (!dir.isDirectory())
return;
String directoryName = directory.second;
for (File f : dir.listFiles(xmlFilter)) {
if (f.isDirectory())
validateRouting(validator, new Tuple2<>(f, directoryName + File.separator + f.getName()));
else
validator.validate(f, directoryName + File.separator + f.getName());
}
}
use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.
the class Feeder method newRemoveMessage.
private Tuple2<String, Message> newRemoveMessage(Operation op, String operationId) {
DocumentRemove remove = new DocumentRemove(op.getRemove());
remove.setCondition(op.getCondition());
Message msg = new RemoveDocumentMessage(remove);
String id = (operationId == null) ? remove.getId().toString() : operationId;
return new Tuple2<>(id, msg);
}
use of com.yahoo.collections.Tuple2 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.collections.Tuple2 in project vespa by vespa-engine.
the class LoadTester method readDefs.
private Map<ConfigDefinitionKey, Tuple2<String, String[]>> readDefs(String defPath) throws IOException {
Map<ConfigDefinitionKey, Tuple2<String, String[]>> ret = new HashMap<>();
if (defPath == null)
return ret;
File defDir = new File(defPath);
if (!defDir.isDirectory()) {
System.out.println("# Given def file dir is not a directory: " + defDir.getPath() + " , will not send def contents in requests.");
return ret;
}
final File[] files = defDir.listFiles();
if (files == null) {
System.out.println("# Given def file dir has no files: " + defDir.getPath() + " , will not send def contents in requests.");
return ret;
}
for (File f : files) {
String name = f.getName();
if (!name.endsWith(".def"))
continue;
String[] splitted = name.split("\\.");
if (splitted.length < 2)
continue;
String nam = splitted[splitted.length - 2];
String contents = IOUtils.readFile(f);
ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromDefContent(nam, Utf8.toBytes(contents));
ret.put(key, new Tuple2<>(ConfigUtils.getDefMd5(Arrays.asList(contents.split("\n"))), contents.split("\n")));
}
System.out.println("# Read " + ret.size() + " def files from " + defDir.getPath());
return ret;
}
use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.
the class Feeder method newErrorMessage.
private Tuple2<String, Message> newErrorMessage(String operationId, Exception e) {
Message m = new FeedErrorMessage(operationId);
Tuple2<String, Message> msg = new Tuple2<>(operationId, m);
Hop hop = new Hop();
hop.addDirective(new ErrorDirective(Exceptions.toMessageString(e)));
Route route = new Route();
route.addHop(hop);
m.setRoute(route);
return msg;
}
Aggregations