use of org.btrplace.model.DefaultModel 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.DefaultModel 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.DefaultModel 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.DefaultModel in project scheduler by btrplace.
the class DiscreteViolationExceptionTest method test.
@Test
public void test() {
SatConstraint c = Mockito.mock(SatConstraint.class);
Model m = new DefaultModel();
DiscreteViolationException ex = new DiscreteViolationException(c, m);
Assert.assertEquals(ex.getModel(), m);
Assert.assertEquals(ex.getConstraint(), c);
Assert.assertFalse(ex.toString().contains("null"));
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class KilledSplitterTest method simpleTest.
@Test
public void simpleTest() {
KilledSplitter splitter = new KilledSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
VM v = m0.newVM(1);
m0.getMapping().addReadyVM(v);
m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
TIntIntHashMap index = Instances.makeVMIndex(instances);
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
// Only VMs in m0
Killed single = new Killed(v);
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Aggregations