use of org.btrplace.safeplace.spec.term.Constant 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.term.Constant in project scheduler by btrplace.
the class DefaultFuzzer method get.
@Override
public TestCase get() {
ReconfigurationPlan p;
fuzzingDuration = -System.currentTimeMillis();
lastValidationDuration = 0;
iterations = 0;
TestCase tc;
do {
lastValidationDuration += predicates.lastDuration();
p = fuzzer.get();
tc = new TestCase(InstanceConverter.toInstance(p), p, cstr);
iterations++;
if (iterations > 10000) {
// We abandon the fuzzing stage. Too hard to get a validation.
return null;
}
} while (!predicates.test(tc));
lastValidationDuration += predicates.lastDuration();
List<Constant> specArgs = new ArrayList<>();
for (UserVar<?> v : cstr.args()) {
Domain<?> d = domain(v, p.getOrigin());
Object o = v.pick(d);
specArgs.add(new Constant(o, v.type()));
}
tc.args(specArgs);
if (cstr.isSatConstraint()) {
SatConstraint impl = cstr.instantiate(specArgs.stream().map(c -> c.eval(null)).collect(Collectors.toList()));
tc.instance().getSatConstraints().add(impl);
fuzzRestriction(impl);
tc.impl(impl);
}
fuzzingDuration += System.currentTimeMillis();
store(tc);
return tc;
}
use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.
the class PlusTest method testBadCollections.
@Test(expectedExceptions = { RuntimeException.class })
public void testBadCollections() throws RuntimeException {
Constant v1 = new Constant(new HashSet<>(Arrays.asList(1, 2)), new SetType(IntType.getInstance()));
Constant v2 = new Constant(new HashSet<>(Collections.singletonList(VMStateType.getInstance().parse("running"))), new SetType(VMStateType.getInstance()));
@SuppressWarnings("unused") SetPlus bad = new SetPlus(v1, v2);
}
Aggregations