Search in sources :

Example 1 with TestCase

use of org.btrplace.safeplace.testing.TestCase 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;
}
Also used : TestCase(org.btrplace.safeplace.testing.TestCase) Constant(org.btrplace.safeplace.spec.term.Constant) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList)

Example 2 with TestCase

use of org.btrplace.safeplace.testing.TestCase in project scheduler by btrplace.

the class Replay method get.

@Override
public TestCase get() {
    try {
        String json = in.readLine();
        if (json == null) {
            return null;
        }
        TestCase tc = TestCase.fromJSON(constraints, json);
        if (restriction.size() == 1) {
            if (restriction.contains(Restriction.CONTINUOUS) && !tc.impl().setContinuous(true)) {
                throw new IllegalArgumentException("Cannot be CONTINUOUS");
            } else if (!tc.impl().setContinuous(false)) {
                throw new IllegalArgumentException("Cannot be DISCRETE");
            }
        }
        return tc;
    } catch (IOException | ParseException | JSONConverterException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : TestCase(org.btrplace.safeplace.testing.TestCase) IOException(java.io.IOException) ParseException(net.minidev.json.parser.ParseException) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 3 with TestCase

use of org.btrplace.safeplace.testing.TestCase 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;
}
Also used : TestCaseResult(org.btrplace.safeplace.testing.TestCaseResult) Constraint(org.btrplace.safeplace.spec.Constraint) TestCase(org.btrplace.safeplace.testing.TestCase)

Aggregations

TestCase (org.btrplace.safeplace.testing.TestCase)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParseException (net.minidev.json.parser.ParseException)1 JSONConverterException (org.btrplace.json.JSONConverterException)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 Constraint (org.btrplace.safeplace.spec.Constraint)1 Constant (org.btrplace.safeplace.spec.term.Constant)1 TestCaseResult (org.btrplace.safeplace.testing.TestCaseResult)1