use of org.btrplace.model.VM 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.VM 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.VM in project scheduler by btrplace.
the class NamingServiceTest method testResolution.
@Test(dependsOnMethods = { "testRegisterAndGets" })
public void testResolution() {
NamingService<VM> ns = NamingService.newVMNS();
Assert.assertEquals(ns.getElementIdentifier(), VM.TYPE);
Model mo = new DefaultModel();
VM v = mo.newVM();
ns.register(v, "vm0");
Assert.assertEquals(ns.resolve(v), "vm0");
Assert.assertEquals(ns.resolve("vm0"), v);
Assert.assertNull(ns.resolve("vm1"));
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class NamingServiceTest method testSubstitution.
@Test(dependsOnMethods = { "testRegisterAndGets" })
public void testSubstitution() {
NamingService<VM> ns = NamingService.newVMNS();
Model mo = new DefaultModel();
VM v = mo.newVM();
ns.register(v, "vm0");
VM v2 = mo.newVM();
ns.substituteVM(v, v2);
Assert.assertNull(ns.resolve(v));
Assert.assertEquals(ns.resolve(v2), "vm0");
Assert.assertEquals(ns.resolve("vm0"), v2);
NamingService<Node> ns2 = NamingService.newNodeNS();
ns2.register(mo.newNode(), "n0");
Assert.assertTrue(ns2.substituteVM(mo.newVM(), mo.newVM()));
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class NamingServiceTest method testGetViews.
@Test
public void testGetViews() {
Model mo = new DefaultModel();
Assert.assertNull(NamingService.getVMNames(mo));
Assert.assertNull(NamingService.getNodeNames(mo));
NamingService<VM> vmNs = NamingService.newVMNS();
NamingService<Node> nodeNs = NamingService.newNodeNS();
mo.attach(vmNs);
mo.attach(nodeNs);
Assert.assertEquals(NamingService.getNodeNames(mo), nodeNs);
Assert.assertEquals(NamingService.getVMNames(mo), vmNs);
}
Aggregations