Search in sources :

Example 81 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class ScriptTest method testExported.

public void testExported() {
    Script v = new Script();
    v.setFullyQualifiedName("testScript");
    Model mo = new DefaultModel();
    BtrpOperand o1 = new BtrpElement(BtrpOperand.Type.VM, "vm1", mo.newVM());
    v.addExportable("$s", o1, Collections.singleton("*"));
    // No restrictions, so every can access the exported variable
    Assert.assertEquals(v.getImportable("$s"), o1);
    Assert.assertTrue(v.canImport("$s", "foo"));
    Assert.assertTrue(v.canImport("$s", "bar.toto"));
    // Explicit no restriction
    BtrpOperand o2 = new BtrpElement(BtrpOperand.Type.VM, "vm2", mo.newVM());
    v.addExportable("$x", o2, Collections.singleton("*"));
    Assert.assertEquals(v.getImportable("$x"), o2);
    Assert.assertTrue(v.canImport("$x", "foo"));
    Assert.assertTrue(v.canImport("$x", "bar.toto"));
    // Unknown export
    Assert.assertFalse(v.canImport("$z", "foo"));
    Assert.assertFalse(v.canImport("$z", "bar.toto"));
    Set<String> valid = new HashSet<>();
    valid.add("foo");
    valid.add("foo.*");
    valid.add("bar");
    BtrpOperand o3 = new BtrpElement(BtrpOperand.Type.VM, "vm2", mo.newVM());
    v.addExportable("$y", o3, valid);
    Assert.assertNull(v.getImportable("$y"));
    Assert.assertEquals(v.getImportable("$y", "foo"), o3);
    Assert.assertNull(v.getImportable("$y", "zog"));
    Assert.assertEquals(v.getImportable("$y", "foo.bar.fii"), o3);
    Assert.assertEquals(v.getImportable("$y", "bar"), o3);
    Assert.assertEquals(v.getExported().size(), 3);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BtrpElement(org.btrplace.btrpsl.element.BtrpElement) HashSet(java.util.HashSet)

Example 82 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class AmongBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodAmongs")
public void testGoodSignatures(String str, int nbVMs, int nbNs1, int nbNs2, 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(), 1);
    Among x = (Among) cstrs.iterator().next();
    Assert.assertEquals(x.getGroupsOfNodes().iterator().next().size(), nbNs1);
    Assert.assertEquals(x.getInvolvedNodes().size(), nbNs1 + nbNs2);
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Among(org.btrplace.model.constraint.Among) Test(org.testng.annotations.Test)

Example 83 with DefaultModel

use of org.btrplace.model.DefaultModel 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);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Ban(org.btrplace.model.constraint.Ban) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 84 with DefaultModel

use of org.btrplace.model.DefaultModel 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);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 85 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class GatherBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodGathers")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Gather x = (Gather) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Gather(org.btrplace.model.constraint.Gather) Test(org.testng.annotations.Test)

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