use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testTemplateReassignment.
@Test(expectedExceptions = { ScriptBuilderException.class })
public void testTemplateReassignment() throws ScriptBuilderException {
Model mo = new DefaultModel();
VM v = mo.newVM();
VM v2 = mo.newVM();
mo.getMapping().addReadyVM(v);
mo.getMapping().addReadyVM(v2);
mo.getAttributes().put(v, "template", "t1");
mo.getAttributes().put(v2, "template", "tiny");
NamingService<Node> nsNodes = NamingService.newNodeNS();
NamingService<VM> nsVMs = NamingService.newVMNS();
mo.attach(nsNodes);
mo.attach(nsVMs);
nsVMs.register(v, "foo.VM1");
nsVMs.register(v2, "foo.VM2");
ScriptBuilder b = new ScriptBuilder(100, mo);
b.setTemplateFactory(new DefaultTemplateFactory(nsNodes, nsVMs, mo));
b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("tiny"));
b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("t1"));
ErrorReporter r;
try {
Script scr = b.build("namespace foo; VM[1,2] : tiny;");
System.out.println(scr.getVMs());
} catch (ScriptBuilderException ex) {
System.out.println(ex);
r = ex.getErrorReporter();
Assert.assertEquals(r.getErrors().size(), 1);
throw ex;
}
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testNumberComputation.
public void testNumberComputation() {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
try {
Script v = b.build(new File(RC_ROOT + "number.btrp"));
BtrpNumber x = (BtrpNumber) v.getImportable("$x");
BtrpNumber y = (BtrpNumber) v.getImportable("$y");
BtrpNumber z = (BtrpNumber) v.getImportable("$z");
BtrpNumber a = (BtrpNumber) v.getImportable("$a");
BtrpNumber c2 = (BtrpNumber) v.getImportable("$c");
BtrpNumber toto = (BtrpNumber) v.getImportable("$toto");
BtrpNumber titi = (BtrpNumber) v.getImportable("$titi");
BtrpNumber foo = (BtrpNumber) v.getImportable("$foo");
BtrpNumber bar = (BtrpNumber) v.getImportable("$bar");
BtrpNumber bi = (BtrpNumber) v.getImportable("$bi");
BtrpNumber f1 = (BtrpNumber) v.getImportable("$f1");
BtrpNumber f2 = (BtrpNumber) v.getImportable("$f2");
BtrpNumber f3 = (BtrpNumber) v.getImportable("$f3");
// System.err.println(v);
Assert.assertTrue(x.isInteger());
Assert.assertEquals(x.getIntValue(), 2);
Assert.assertTrue(y.isInteger());
Assert.assertEquals(y.getIntValue(), 8);
Assert.assertTrue(z.isInteger());
Assert.assertEquals(z.getIntValue(), 26);
Assert.assertTrue(a.isInteger());
Assert.assertEquals(a.getIntValue(), 2);
Assert.assertTrue(c2.isInteger());
Assert.assertEquals(c2.getIntValue(), 1);
Assert.assertFalse(f1.isInteger());
Assert.assertEquals(f1.getDoubleValue(), 0.7);
Assert.assertFalse(f2.isInteger());
Assert.assertEquals(f2.getDoubleValue(), 3.0);
Assert.assertFalse(f3.isInteger());
Assert.assertEquals(f3.getDoubleValue(), 892, 5);
BtrpNumber baz = (BtrpNumber) v.getImportable("$baz");
Assert.assertEquals(baz, BtrpNumber.TRUE);
BtrpNumber biz = (BtrpNumber) v.getImportable("$biz");
Assert.assertEquals(biz, BtrpNumber.TRUE);
Assert.assertEquals(toto, BtrpNumber.FALSE);
Assert.assertEquals(titi, BtrpNumber.TRUE);
Assert.assertEquals(foo, BtrpNumber.TRUE);
Assert.assertEquals(bar, BtrpNumber.TRUE);
Assert.assertEquals(bi, BtrpNumber.FALSE);
} catch (ScriptBuilderException x) {
Assert.fail(x.getMessage(), x);
}
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testVariablesInElementRange.
public void testVariablesInElementRange() throws ScriptBuilderException {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Script v = b.build(new File(RC_ROOT + "range.btrp"));
BtrpSet s = (BtrpSet) v.getImportable("$foo");
System.out.println(s);
Assert.assertEquals(s.size(), 9);
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testSetManipulationWithErrors.
@Test(expectedExceptions = { ScriptBuilderException.class })
public void testSetManipulationWithErrors() throws ScriptBuilderException {
try {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
b.build("namespace test.template;\n" + "VM[1..20] : tinyVMs<migratable,volatile>;\n" + "$x = VM[1..10] + VM15;\n" + "$y = VM[1..10] + @N[1..20,57];\n" + "$z = VM[1..10] + 7;\n" + "$a = VM[1..10] - {VM[1..10]};\n" + "$b = VM[1..10] / @N1;\n" + "$c = VM[1..10] / @N[1,3];\n" + "$d = VM[1..10] * VM[21,22];\n" + "$e = VM[22,23] / 2;\n");
} catch (ScriptBuilderException x) {
System.out.println(x);
Assert.assertEquals(x.getErrorReporter().getErrors().size(), 8);
throw x;
}
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testResolution.
@Test
public void testResolution() throws Exception {
Model mo = new DefaultModel();
ScriptBuilder b = new ScriptBuilder(mo);
NamingService<Node> nsNodes = b.getNamingServiceNodes();
NamingService<VM> nsVMs = b.getNamingServiceVMs();
for (int i = 1; i < 10; i++) {
if (i <= 5) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
nsNodes.register(n, "@N" + i);
}
VM v = mo.newVM();
nsVMs.register(v, "ns.VM" + i);
mo.getMapping().addReadyVM(v);
}
// TemplateFactory tpf = new DefaultTemplateFactory(b.getNamingService(), true);
// b.setTemplateFactory(tpf);
Script scr = b.build("namespace ns;\n" + "VM[1..10] : tiny;\n" + "@N[1..5]: default;\n" + "$vms = VM[1..10];\n" + "running($vms);\n" + ">>split($vms / 2);\n");
Assert.assertEquals(mo.getMapping().getNbNodes(), 5);
Assert.assertEquals(mo.getMapping().getNbVMs(), 10);
ChocoScheduler ra = new DefaultChocoScheduler();
ReconfigurationPlan p = ra.solve(mo, scr.getConstraints());
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 10);
}
Aggregations