use of org.btrplace.model.Node 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.Node 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);
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class OnlineTest method testOnlines.
@Test
public void testOnlines() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 5);
List<Online> c = Online.newOnline(ns);
Assert.assertEquals(ns.size(), c.size());
c.stream().forEach((q) -> {
Assert.assertTrue(ns.containsAll(q.getInvolvedNodes()));
Assert.assertFalse(q.isContinuous());
});
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class OnlineTest method testIsSatisfied.
@Test
public void testIsSatisfied() {
Model i = new DefaultModel();
List<Node> ns = Util.newNodes(i, 3);
Mapping c = i.getMapping();
c.addOnlineNode(ns.get(0));
Online o = new Online(ns.get(0));
Assert.assertEquals(o.isSatisfied(i), true);
c.addOfflineNode(ns.get(1));
Assert.assertEquals(new Online(ns.get(1)).isSatisfied(i), false);
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class OnlineTest method testEquals.
@Test
public void testEquals() {
Model mo = new DefaultModel();
Node n = mo.newNode();
Online s = new Online(n);
Assert.assertTrue(s.equals(s));
Assert.assertTrue(new Online(n).equals(s));
Assert.assertEquals(new Online(n).hashCode(), s.hashCode());
Assert.assertFalse(new Online(mo.newNode()).equals(s));
}
Aggregations