use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.
the class TestSafePlace method launcher.
// @Test
public void launcher() throws Exception {
SpecScanner specScanner = new SpecScanner();
List<Constraint> l = specScanner.scan();
TestScanner sc = new TestScanner(l);
List<TestCampaign> campaigns = sc.test(TestSafePlace.class);
// List<TestCampaign> campaigns = sc.testGroups("_resourceCapacity");
if (campaigns.isEmpty()) {
Assert.fail("Nothing to test");
}
campaigns.forEach(tc -> {
// .setVerbosity(1);
tc.schedulerParams().doRepair(false);
tc.onDefect(DefectHooks.ignore);
tc.limits().clear().tests(1000);
System.out.println(tc.go());
});
}
use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.
the class TestCase method fromJSON.
public static TestCase fromJSON(List<Constraint> cstrs, String c) throws ParseException, JSONConverterException {
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
JSONObject o = (JSONObject) p.parse(new StringReader(c));
String cId = o.getAsString("constraint");
Optional<Constraint> opt = cstrs.stream().filter(x -> x.id().equals(cId)).findFirst();
if (!opt.isPresent()) {
throw new IllegalArgumentException("Unknown constraint '" + cId + "'");
}
Constraint cstr = opt.get();
InstanceConverter ic = new InstanceConverter();
ic.getConstraintsConverter().register(new ScheduleConverter());
ReconfigurationPlanConverter rc = new ReconfigurationPlanConverter();
Instance i = ic.fromJSON(o.getAsString("instance"));
ReconfigurationPlan plan = rc.fromJSON(o.getAsString("plan"));
TestCase tc = new TestCase(i, plan, cstr);
List<Constant> l = new ArrayList<>();
for (Object x : (JSONArray) o.get("args")) {
l.add(Constant.fromJSON((JSONObject) x));
}
tc.args(l);
if (cstr.isSatConstraint()) {
tc.impl(cstr.instantiate(l.stream().map(x -> x.eval(null)).collect(Collectors.toList())));
}
if (tc.impl() != null) {
tc.impl().setContinuous((Boolean) o.get("continuous"));
}
return tc;
}
use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.
the class Validator method test.
@Override
public boolean test(TestCase o) {
duration = -System.currentTimeMillis();
try {
for (Constraint c : cstrs) {
TestCase tc = purge(o, c);
TestCaseResult res = tester.test(tc);
if (res.result() != Result.SUCCESS) {
return false;
}
}
} finally {
duration += System.currentTimeMillis();
}
return true;
}
use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.
the class DSN method specLength.
// @Test
public void specLength() throws Exception {
SpecScanner sc = new SpecScanner();
List<Constraint> l = sc.scan();
System.out.println(l.stream().map(Constraint::pretty).collect(Collectors.joining("\n")));
Path path = Paths.get(root, "inv.csv");
String out = l.stream().map(c -> Integer.toString(c.proposition().toString().length())).collect(Collectors.joining("\n"));
Files.write(path, out.getBytes());
List<Integer> funcs = new ArrayList<>();
List<Path> paths = Files.list(Paths.get("safeplace/src/main/java/org/btrplace/safeplace/spec/term/func")).filter(Files::isRegularFile).collect(Collectors.toList());
for (Path p : paths) {
try (InputStream in = Files.newInputStream(p)) {
CompilationUnit cu = JavaParser.parse(in);
new FunctionVisitor(funcs).visit(cu, null);
}
}
path = Paths.get(root, "func.csv");
out = funcs.stream().map(c -> Integer.toString(c)).collect(Collectors.joining("\n"));
Files.write(path, out.getBytes());
}
use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.
the class TestScannerTest method newScanner.
public TestScanner newScanner() throws Exception {
SpecScanner specScanner = new SpecScanner();
List<Constraint> l = specScanner.scan();
return new TestScanner(l);
}
Aggregations