Search in sources :

Example 1 with DefaultModel

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

the class SchedulerExceptionTest method testBasic.

@Test
public void testBasic() {
    Model mo = new DefaultModel();
    SchedulerException ex = new SchedulerException(mo, "foo");
    Assert.assertEquals(ex.getModel(), mo);
    Assert.assertEquals(ex.getMessage(), "foo");
    SchedulerException ex2 = new SchedulerException(mo, "foo", ex);
    Assert.assertEquals(ex2.getModel(), mo);
    Assert.assertEquals(ex2.getMessage(), "foo");
    Assert.assertEquals(ex2.getCause(), ex);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 2 with DefaultModel

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

the class ScriptBuilderTest method testStringSupport.

public void testStringSupport() throws ScriptBuilderException {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Script v = b.build("namespace foo; VM[1..10] : tiny;\n$arr = {\"foo\",\"bar\", \"baz\"};$arr2 = $arr + {\"git\"}; $out = \"come \" + \"out \" + 5 + \" \" + VM1; export $arr2,$out to *;");
    BtrpString out = (BtrpString) v.getImportable("$out");
    BtrpSet arr2 = (BtrpSet) v.getImportable("$arr2");
    Assert.assertEquals(out.toString(), "come out 5 foo.VM1");
    Assert.assertEquals(arr2.size(), 4);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpString(org.btrplace.btrpsl.element.BtrpString) BtrpSet(org.btrplace.btrpsl.element.BtrpSet)

Example 3 with DefaultModel

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

the class ScriptBuilderTest method testTemplateWithOptions.

@Test
public void testTemplateWithOptions() throws ScriptBuilderException {
    Model mo = new DefaultModel();
    ScriptBuilder b = new ScriptBuilder(mo);
    Script v = b.build("namespace test.template;\nVM[1..3] : tinyVMs<migratable,start=\"7.5\",stop=12>;");
    Assert.assertEquals(v.getVMs().size(), 3);
    for (VM el : v.getVMs()) {
        // 3 + 1 (the template)
        Assert.assertEquals(mo.getAttributes().getKeys(el).size(), 4);
        Assert.assertEquals(mo.getAttributes().get(el, "migratable", false), true);
        Assert.assertEquals(mo.getAttributes().get(el, "start", -1.5), 7.5);
        Assert.assertEquals(mo.getAttributes().get(el, "stop", -1), 12);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Example 4 with DefaultModel

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

the class ScriptBuilderTest method testSetManipulation.

public void testSetManipulation() throws ScriptBuilderException {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Script v = b.build(new File(RC_ROOT + "setManip.btrp"));
    BtrpSet t1 = (BtrpSet) v.getImportable("$T1");
    BtrpSet t2 = (BtrpSet) v.getImportable("$T2");
    BtrpSet t3 = (BtrpSet) v.getImportable("$T3");
    BtrpNumber x = (BtrpNumber) v.getImportable("$x");
    BtrpNumber res = (BtrpNumber) v.getImportable("$res");
    BtrpNumber res2 = (BtrpNumber) v.getImportable("$res2");
    BtrpNumber res3 = (BtrpNumber) v.getImportable("$res3");
    BtrpNumber y = (BtrpNumber) v.getImportable("$y");
    Assert.assertEquals(t1.size() + t2.size() + t3.size(), 100);
    Assert.assertEquals(x.getIntValue(), 12);
    Assert.assertEquals(y.getIntValue(), 3);
    BtrpSet C = (BtrpSet) v.getImportable("$C");
    Assert.assertEquals(C.size(), 90);
    BtrpSet a = (BtrpSet) v.getImportable("$a");
    Assert.assertEquals(res, BtrpNumber.TRUE);
    Assert.assertEquals(res2, BtrpNumber.TRUE);
    Assert.assertEquals(res3, BtrpNumber.TRUE);
    Assert.assertEquals(a.degree(), 2);
    Assert.assertEquals(a.size(), 4);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) File(java.io.File)

Example 5 with DefaultModel

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

the class ScriptBuilderTest method testIfStatement.

public void testIfStatement() {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    try {
        Script v = b.build(new File(RC_ROOT + "ifStatement.btrp"));
        BtrpNumber first = (BtrpNumber) v.getImportable("$first");
        BtrpNumber second = (BtrpNumber) v.getImportable("$second");
        BtrpNumber third = (BtrpNumber) v.getImportable("$third");
        Assert.assertNotNull(first);
        Assert.assertNotNull(second);
        Assert.assertEquals(first, BtrpNumber.TRUE);
        Assert.assertEquals(second, BtrpNumber.TRUE);
        Assert.assertEquals(third.getIntValue(), 5);
    } catch (ScriptBuilderException x) {
        Assert.fail(x.getMessage(), x);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) File(java.io.File)

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