Search in sources :

Example 76 with DefaultModel

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"));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Attributes(org.btrplace.model.Attributes) Test(org.testng.annotations.Test)

Example 77 with DefaultModel

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");
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 78 with DefaultModel

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()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BtrpElement(org.btrplace.btrpsl.element.BtrpElement)

Example 79 with DefaultModel

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Gather(org.btrplace.model.constraint.Gather)

Example 80 with DefaultModel

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()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BtrpElement(org.btrplace.btrpsl.element.BtrpElement)

Aggregations

DefaultModel (org.btrplace.model.DefaultModel)201 Test (org.testng.annotations.Test)177 Model (org.btrplace.model.Model)157 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)91 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 Mapping (org.btrplace.model.Mapping)39 ArrayList (java.util.ArrayList)26 ShareableResource (org.btrplace.model.view.ShareableResource)24 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)22 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MigrateVM (org.btrplace.plan.event.MigrateVM)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)16 KillVM (org.btrplace.scheduler.choco.transition.KillVM)16