Search in sources :

Example 11 with VM

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);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Random(java.util.Random) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 12 with VM

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)));
        }
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 13 with VM

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());
}
Also used : Action(org.btrplace.plan.event.Action) VM(org.btrplace.model.VM) Event(org.btrplace.plan.event.Event) Test(org.testng.annotations.Test)

Example 14 with VM

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Event(org.btrplace.plan.event.Event) Test(org.testng.annotations.Test)

Example 15 with VM

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);
}
Also used : Action(org.btrplace.plan.event.Action) VM(org.btrplace.model.VM) Test(org.testng.annotations.Test)

Aggregations

VM (org.btrplace.model.VM)192 Node (org.btrplace.model.Node)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)91 Mapping (org.btrplace.model.Mapping)64 HashSet (java.util.HashSet)58 ArrayList (java.util.ArrayList)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)39 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)35 IntVar (org.chocosolver.solver.variables.IntVar)35 ShareableResource (org.btrplace.model.view.ShareableResource)32 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)27 MigrateVM (org.btrplace.plan.event.MigrateVM)25 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)17 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)17 Slice (org.btrplace.scheduler.choco.Slice)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)16