use of org.btrplace.model.VM in project scheduler by btrplace.
the class VMConsumptionComparatorTest method testSimpleResource.
@Test
public void testSimpleResource() {
ShareableResource rc = new ShareableResource("foo");
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
Random rnd = new Random();
for (VM id : vms) {
rc.setConsumption(id, rnd.nextInt(5));
}
VMConsumptionComparator c1 = new VMConsumptionComparator(rc, true);
Collections.sort(vms, c1);
for (int i = 0; i < vms.size() - 1; i++) {
Assert.assertTrue(rc.getConsumption(vms.get(i)) - rc.getConsumption(vms.get(i + 1)) <= 0);
}
// Descending order
c1 = new VMConsumptionComparator(rc, false);
Collections.sort(vms, c1);
for (int i = 0; i < vms.size() - 1; i++) {
Assert.assertTrue(rc.getConsumption(vms.get(i)) - rc.getConsumption(vms.get(i + 1)) >= 0);
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class VMConsumptionComparatorTest method testCombination.
/**
* Test when there is multiple resource to compare to
*/
@Test(dependsOnMethods = { "testSimpleResource" })
public void testCombination() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 7);
ShareableResource rc = new ShareableResource("foo");
for (int i = 0; i < 4; i++) {
rc.setConsumption(vms.get(i), i);
}
rc.setConsumption(vms.get(4), 2);
rc.setConsumption(vms.get(5), 2);
rc.setConsumption(vms.get(6), 3);
ShareableResource rc2 = new ShareableResource("bar");
for (int i = 0; i < 4; i++) {
rc2.setConsumption(vms.get(i), i / 2);
}
rc2.setConsumption(vms.get(4), 1);
rc2.setConsumption(vms.get(5), 3);
rc2.setConsumption(vms.get(6), 3);
VMConsumptionComparator c1 = new VMConsumptionComparator(rc, true);
c1.append(rc2, false);
Collections.sort(vms, c1);
for (int i = 0; i < vms.size() - 1; i++) {
VM id = vms.get(i);
Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1)));
if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) {
Assert.assertTrue(rc2.getConsumption(id) >= rc2.getConsumption(vms.get(i + 1)));
}
}
// The 2 criteria are ascending
c1 = new VMConsumptionComparator(rc, true);
c1.append(rc2, true);
Collections.sort(vms, c1);
for (int i = 0; i < vms.size() - 1; i++) {
VM id = vms.get(i);
Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1)));
if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) {
Assert.assertTrue(rc2.getConsumption(id) <= rc2.getConsumption(vms.get(i + 1)));
}
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class ActionTest method testEvents.
@Test
public void testEvents() {
Action a1 = new MockAction(new VM(1), 1, 3);
Event e = mock(Event.class);
a1.addEvent(Action.Hook.PRE, e);
Assert.assertEquals(1, a1.getEvents(Action.Hook.PRE).size());
a1.addEvent(Action.Hook.POST, e);
Assert.assertEquals(1, a1.getEvents(Action.Hook.POST).size());
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class ActionTest method testApply.
@Test
public void testApply() {
Model mo = new DefaultModel();
MockAction a1 = new MockAction(new VM(1), 1, 3);
Event e = mock(Event.class);
when(e.apply(mo)).thenReturn(true);
a1.addEvent(Action.Hook.PRE, e);
a1.addEvent(Action.Hook.POST, e);
a1.apply(mo);
verify(e, times(2)).apply(mo);
Assert.assertEquals(a1.count, 1);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class TimedBasedActionComparatorTest method testEqualityWithSimultaneousDisallowed.
@Test
public void testEqualityWithSimultaneousDisallowed() {
VM vm2 = mo.newVM();
Action a = new MockAction(vm, 0, 4);
Action b = new MockAction(vm2, 0, 4);
Assert.assertNotEquals(new TimedBasedActionComparator(false, true).compare(a, b), 0);
Assert.assertNotEquals(new TimedBasedActionComparator(true, true).compare(a, b), 0);
}
Aggregations