Search in sources :

Example 21 with DefaultModel

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);
    }
}
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 22 with DefaultModel

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)));
        }
    }
}
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 23 with DefaultModel

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);
}
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 24 with DefaultModel

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

Example 25 with DefaultModel

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Killed(org.btrplace.model.constraint.Killed) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

DefaultModel (org.btrplace.model.DefaultModel)201 Test (org.testng.annotations.Test)177 Model (org.btrplace.model.Model)157 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)91 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 Mapping (org.btrplace.model.Mapping)39 ArrayList (java.util.ArrayList)26 ShareableResource (org.btrplace.model.view.ShareableResource)24 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)22 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MigrateVM (org.btrplace.plan.event.MigrateVM)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)16 KillVM (org.btrplace.scheduler.choco.transition.KillVM)16