use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class ScriptBuilderTest method testMeReassignment.
@Test(expectedExceptions = { ScriptBuilderException.class })
public void testMeReassignment() throws ScriptBuilderException {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
b.build("namespace foo; VM[1..5] : tiny;\nVM[6..10] : small;\n $me = 7; ");
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testAcceptance.
@Test
public void testAcceptance() {
SatConstraint cstr = mock(SatConstraint.class);
AllowAllConstraintChecker<?> c = mock(AllowAllConstraintChecker.class, CALLS_REAL_METHODS);
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
when(cstr.getInvolvedNodes()).thenReturn(ns);
when(cstr.getInvolvedVMs()).thenReturn(vms);
MigrateVM m = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(m));
verify(c).startRunningVMPlacement(m);
c.end(m);
verify(c).endRunningVMPlacement(m);
BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(b));
verify(c).startRunningVMPlacement(b);
c.end(b);
verify(c).endRunningVMPlacement(b);
ResumeVM r = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(r));
verify(c).startRunningVMPlacement(r);
c.end(r);
verify(c).endRunningVMPlacement(r);
// do not use the mock as the constructor is important
// while earlier, the mock was needed for the verify()
c = new AllowAllConstraintChecker<>(cstr);
Set<VM> allVMs = new HashSet<>();
for (Node n : mo.getMapping().getOnlineNodes()) {
allVMs.addAll(mo.getMapping().getRunningVMs(n));
allVMs.addAll(mo.getMapping().getSleepingVMs(n));
}
allVMs.addAll(mo.getMapping().getReadyVMs());
c.track(allVMs);
SuspendVM s = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(s));
ShutdownVM s2 = new ShutdownVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(s2));
KillVM k = new KillVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(k));
ForgeVM f = new ForgeVM(vms.get(0), 0, 3);
Assert.assertTrue(c.start(f));
BootNode bn = new BootNode(ns.get(0), 0, 3);
Assert.assertTrue(c.start(bn));
ShutdownNode sn = new ShutdownNode(ns.get(0), 0, 3);
Assert.assertTrue(c.start(sn));
SubstitutedVMEvent ss = new SubstitutedVMEvent(vms.get(9), vms.get(2));
Assert.assertTrue(c.consume(ss));
Allocate a = new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5);
Assert.assertTrue(c.start(a));
AllocateEvent ae = new AllocateEvent(vms.get(0), "cpu", 3);
Assert.assertTrue(c.consume(ae));
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testInstantiation.
@Test
public void testInstantiation() {
SatConstraint cstr = mock(SatConstraint.class);
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
when(cstr.getInvolvedNodes()).thenReturn(ns);
when(cstr.getInvolvedVMs()).thenReturn(vms);
AllowAllConstraintChecker<SatConstraint> c = new AllowAllConstraintChecker<>(cstr);
Assert.assertEquals(c.getConstraint(), cstr);
Assert.assertEquals(c.getVMs(), vms);
Assert.assertEquals(c.getNodes(), ns);
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testAnyTracking.
@Test(dependsOnMethods = "testInstantiation")
public void testAnyTracking() {
SatConstraint cstr = mock(SatConstraint.class);
AllowAllConstraintChecker<SatConstraint> c = new AllowAllConstraintChecker<>(cstr);
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
when(cstr.getInvolvedVMs()).thenReturn(vms);
Set<VM> vs = new HashSet<>(Arrays.asList(vms.get(4), vms.get(6), vms.get(9)));
c.track(vs);
// VM1 (one of the involved vms) has to be removed to be substituted by vms.get(0)0
c.consume(new SubstitutedVMEvent(vms.get(6), vms.get(9)));
Assert.assertTrue(vs.contains(vms.get(9)));
Assert.assertFalse(vs.contains(vms.get(6)));
// VM5 is not involved, no removal
c.consume(new SubstitutedVMEvent(vms.get(6), vms.get(0)));
Assert.assertFalse(vs.contains(vms.get(6)));
Assert.assertFalse(vs.contains(vms.get(0)));
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class MaxOnlineTest method testInstantiation.
@Test
public void testInstantiation() {
Model mo = new DefaultModel();
Set<Node> s = new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode()));
MaxOnline o = new MaxOnline(s, 3);
Assert.assertNotNull(o.getChecker());
Assert.assertEquals(o.getInvolvedNodes(), s);
Assert.assertTrue(o.getInvolvedVMs().isEmpty());
Assert.assertNotNull(o.toString());
Assert.assertFalse(o.isContinuous());
Assert.assertTrue(o.setContinuous(true));
Assert.assertTrue(o.isContinuous());
Assert.assertTrue(o.setContinuous(false));
Assert.assertTrue(o.equals(new MaxOnline(s, 3)));
Assert.assertEquals(o.hashCode(), new MaxOnline(s, 3, false).hashCode());
Assert.assertFalse(o.equals(new MaxOnline(s, 4)));
Assert.assertFalse(o.equals(new MaxOnline(Collections.singleton(mo.newNode()), 3)));
Assert.assertFalse(o.equals(new MaxOnline(s, 3, true)));
}
Aggregations