use of org.btrplace.model.Model in project scheduler by btrplace.
the class OverbookTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
Node n0 = mo.newNode();
Node n1 = mo.newNode();
Model i = new DefaultModel();
Mapping cfg = i.getMapping();
cfg.addOnlineNode(n0);
cfg.addOnlineNode(n1);
ShareableResource rc = new ShareableResource("cpu");
rc.setCapacity(n0, 1);
rc.setCapacity(n1, 4);
rc.setConsumption(vms.get(0), 2);
rc.setConsumption(vms.get(1), 2);
rc.setConsumption(vms.get(2), 4);
cfg.addRunningVM(vms.get(0), n0);
cfg.addRunningVM(vms.get(1), n1);
cfg.addRunningVM(vms.get(2), n1);
cfg.addRunningVM(vms.get(3), n1);
i.attach(rc);
Overbook o = new Overbook(n1, "cpu", 2);
o.setContinuous(true);
ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
Assert.assertEquals(o.isSatisfied(p), true);
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class QuarantineTest method testQuarantines.
@Test
public void testQuarantines() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 5);
List<Quarantine> qs = Quarantine.newQuarantine(ns);
Assert.assertEquals(qs.size(), ns.size());
qs.stream().forEach((q) -> {
Assert.assertTrue(ns.containsAll(q.getInvolvedNodes()));
Assert.assertTrue(q.isContinuous());
});
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class QuarantineTest method testEqualsHashCode.
@Test
public void testEqualsHashCode() {
Model mo = new DefaultModel();
Node n = mo.newNode();
Quarantine q = new Quarantine(n);
Assert.assertTrue(q.equals(q));
Assert.assertTrue(q.equals(new Quarantine(n)));
Assert.assertEquals(q.hashCode(), new Quarantine(n).hashCode());
Assert.assertFalse(q.equals(new Quarantine(mo.newNode())));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class ResourceCapacityTest method testEqualsAndHashCode.
@Test(dependsOnMethods = { "testInstantiation" })
public void testEqualsAndHashCode() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
Set<Node> s = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
ResourceCapacity c = new ResourceCapacity(s, "foo", 3);
ResourceCapacity c2 = new ResourceCapacity(s, "foo", 3);
Assert.assertTrue(c.equals(c));
Assert.assertTrue(c.equals(c2));
Assert.assertEquals(c.hashCode(), c2.hashCode());
Assert.assertFalse(c.equals(new ResourceCapacity(s, "bar", 3)));
Assert.assertFalse(c.equals(new ResourceCapacity(s, "foo", 2)));
Assert.assertFalse(c.equals(new ResourceCapacity(new HashSet<>(), "foo", 3)));
Assert.assertNotEquals(new ResourceCapacity(s, "f", 3, true), new ResourceCapacity(s, "f", 3, false));
Assert.assertNotEquals(new ResourceCapacity(s, "f", 3, true).hashCode(), new ResourceCapacity(s, "f", 3, false).hashCode());
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class ResourceCapacityTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(2));
map.addReadyVM(vms.get(4));
ShareableResource rc = new ShareableResource("foo", 1, 1);
mo.attach(rc);
Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4, true);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(cc.isSatisfied(plan), true);
// 3/4
MigrateVM m = new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1);
m.addEvent(Action.Hook.POST, new AllocateEvent(vms.get(3), "foo", 2));
plan.add(m);
// 5/4
plan.add(new ShutdownVM(vms.get(2), ns.get(1), 1, 2));
// 4/4
plan.add(new BootVM(vms.get(4), ns.get(2), 2, 3));
// 4/4
plan.add(new Allocate(vms.get(1), ns.get(0), "foo", 2, 2, 3));
// 5/4
plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 3, 4));
System.out.println(plan);
Assert.assertEquals(cc.isSatisfied(plan), true);
}
Aggregations