use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testViewAddition.
@Test
public void testViewAddition() throws SchedulerException {
Model mo = new DefaultModel();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
MockCView view = new MockCView();
Assert.assertTrue(rp.addView(view));
Assert.assertEquals(rp.getView(view.getIdentifier()), view);
Assert.assertFalse(rp.addView(view));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testManageableVMs.
@Test
public void testManageableVMs() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Set<VM> runnings = new HashSet<>(map.getRunningVMs());
runnings.add(vm6);
runnings.add(vm5);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), runnings, map.getSleepingVMs(), Collections.emptySet()).setManageableVMs(map.getRunningVMs(n1)).build();
/*
vm1: running -> running
vm2: running-> running
vm3: running -> running
vm4: sleeping -> sleeping
vm5: ready -> running
vm6: ready -> running
* manageable_runnings: vm1, vm2
* manageable: vm1, vm2, vm5, vm6 (with ids: vm#0, vm#1, vm#4, vm#5)
*/
Set<VM> manageable = rp.getManageableVMs();
Assert.assertEquals(manageable.size(), 4, manageable.toString());
Assert.assertTrue(manageable.containsAll(Arrays.asList(vm6, vm5, vm1, vm2)));
// Check the action model that has been used for each of the VM.
for (VM vm : map.getAllVMs()) {
Assert.assertEquals(manageable.contains(vm), rp.getVMAction(vm).isManaged());
}
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMToShutdown.
@Test
public void testVMToShutdown() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addOnlineNode(n1);
m.addRunningVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.singleton(vm1), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ShutdownVM.class, a.getClass());
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMStaySleeping.
@Test
public void testVMStaySleeping() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addSleepingVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(StayAwayVM.class, a.getClass());
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class AmongTest method testEqualsHashCode.
@Test(dependsOnMethods = { "testInstantiation" })
public void testEqualsHashCode() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
Collection<Node> s2 = Collections.singletonList(ns.get(2));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
Among a = new Among(vg, pGrps);
Assert.assertTrue(a.equals(a));
Assert.assertTrue(a.equals(new Among(new HashSet<>(vg), pGrps)));
Assert.assertEquals(a.hashCode(), new Among(new HashSet<>(vg), pGrps).hashCode());
Assert.assertFalse(a.equals(new Among(new HashSet<>(), pGrps)));
Assert.assertFalse(a.equals(new Among(new HashSet<>(vg), Collections.emptyList())));
Among a2 = new Among(new HashSet<>(vg), Collections.emptyList());
a2.setContinuous(true);
Assert.assertFalse(a.equals(a2));
}
Aggregations