use of org.btrplace.model.VM in project scheduler by btrplace.
the class LinearToAResourceDurationTest method testSimple.
@Test
public void testSimple() {
ShareableResource rc = new ShareableResource("foo", 0, 0);
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
mo.attach(rc);
rc.setConsumption(vm1, 3);
LinearToAResourceActionDuration<VM> d = new LinearToAResourceActionDuration<>("foo", 3);
System.out.println(d.toString());
Assert.assertEquals(d.getCoefficient(), 3.0);
Assert.assertEquals(d.getOffset(), 0.0);
Assert.assertEquals(d.getResourceId(), "foo");
Assert.assertEquals(d.evaluate(mo, vm1), 9);
Assert.assertEquals(d.evaluate(mo, vm2), 0);
d = new LinearToAResourceActionDuration<>("foo", 3, 4);
Assert.assertEquals(d.evaluate(mo, vm1), 13);
Assert.assertEquals(d.evaluate(mo, vm3), 4);
d = new LinearToAResourceActionDuration<>("bar", 3, 4);
Assert.assertEquals(d.evaluate(mo, vm3), -1);
d.setCoefficient(5);
d.setOffset(12);
d.setResourceId("bar");
Assert.assertEquals(d.getCoefficient(), 5.0);
Assert.assertEquals(d.getOffset(), 12.0);
Assert.assertEquals(d.getResourceId(), "bar");
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class ScriptTest method testConstraints.
public void testConstraints() {
Script v = new Script();
Model mo = new DefaultModel();
VM vm2 = mo.newVM();
v.addConstraint(new Gather(Collections.singleton(vm2)));
v.addConstraint(new RunningCapacity(Collections.singleton(mo.newNode()), 5));
Assert.assertEquals(v.getConstraints().size(), 2);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class BanBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodBans")
public void testGoodSignatures(String str, int nbVMs, int nbNodes, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..10] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint s : cstrs) {
Assert.assertTrue(s instanceof Ban);
Assert.assertEquals(s.getInvolvedVMs().size(), 1);
Assert.assertTrue(vms.addAll(s.getInvolvedVMs()));
Assert.assertEquals(s.getInvolvedNodes().size(), nbNodes);
Assert.assertEquals(s.isContinuous(), c);
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class FenceBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodFences")
public void testGoodSignatures(String str, int nbVMs, int nbNodes, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n @N[1..20] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Fence);
Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class PreserveBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodPreserves")
public void testGoodSignatures(String str, int nbVMs, String rcId, int a) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Preserve);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), false);
Assert.assertEquals(((Preserve) x).getResource(), rcId);
Assert.assertEquals(((Preserve) x).getAmount(), a);
}
}
Aggregations