use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DurationFromOptionalAttributeTest method test.
@Test
public void test() {
Model mo = new DefaultModel();
Attributes attrs = mo.getAttributes();
ActionDurationEvaluator<VM> parent = new ConstantActionDuration<>(15);
VM vm1 = mo.newVM();
ActionDurationFromOptionalAttribute<VM> dev = new ActionDurationFromOptionalAttribute<>("boot", parent);
Assert.assertEquals(parent, dev.getParent());
Assert.assertEquals("boot", dev.getAttributeKey());
Assert.assertEquals(15, dev.evaluate(mo, vm1));
attrs.put(vm1, "boot", 7);
Assert.assertEquals(7, dev.evaluate(mo, vm1));
parent = new ConstantActionDuration<>(2);
dev.setParent(parent);
attrs.clear();
Assert.assertEquals(2, dev.evaluate(mo, vm1));
Assert.assertEquals(parent, dev.getParent());
Assert.assertFalse(dev.toString().contains("null"));
}
use of org.btrplace.model.DefaultModel 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.DefaultModel in project scheduler by btrplace.
the class ScriptTest method testNodeAddition.
public void testNodeAddition() {
Script v = new Script();
Model mo = new DefaultModel();
BtrpElement n1 = new BtrpElement(BtrpOperand.Type.NODE, "@N1", mo.newNode());
BtrpElement n2 = new BtrpElement(BtrpOperand.Type.NODE, "@N2", mo.newNode());
v.add(n1);
v.add(n2);
Assert.assertEquals(v.getNodes().size(), 2);
Assert.assertTrue(v.getNodes().contains(n1.getElement()) && v.getNodes().contains(n2.getElement()));
}
use of org.btrplace.model.DefaultModel 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.DefaultModel in project scheduler by btrplace.
the class ScriptTest method testVMsAddition.
public void testVMsAddition() {
Script v = new Script();
Model mo = new DefaultModel();
BtrpElement vm1 = new BtrpElement(BtrpOperand.Type.VM, "VM1", mo.newVM());
BtrpElement vm2 = new BtrpElement(BtrpOperand.Type.VM, "VM2", mo.newVM());
BtrpElement vm3 = new BtrpElement(BtrpOperand.Type.VM, "VM3", mo.newVM());
v.add(vm1);
v.add(Arrays.asList(vm2, vm3));
Assert.assertEquals(v.getVMs().size(), 3);
Assert.assertTrue(v.getVMs().contains(vm1.getElement()) && v.getVMs().contains(vm2.getElement()) && v.getVMs().contains(vm3.getElement()));
}
Aggregations