Search in sources :

Example 1 with FixedSizePartitioning

use of org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning in project scheduler by btrplace.

the class MaxOnlineSplitterTest method testSplit.

@Test
public void testSplit() throws SchedulerException {
    MaxOnlineSplitter splitter = new MaxOnlineSplitter();
    Model mo = new DefaultModel();
    Node[] ns = new Node[10];
    for (int i = 0; i < ns.length; i++) {
        Node n = mo.newNode();
        mo.getMapping().addOnlineNode(n);
        ns[i] = n;
    }
    FixedNodeSetsPartitioning cut = new FixedSizePartitioning(5);
    Instance origin = new Instance(mo, Collections.emptyList(), new MinMTTR());
    List<Instance> instances = cut.split(new DefaultParameters(), origin);
    TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    MaxOnline m1 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[2], ns[3], ns[4])), 3);
    // This one is valid as m1 stay in the first partition
    Assert.assertTrue(splitter.split(m1, origin, instances, vmIndex, nodeIndex));
    boolean found = false;
    for (Instance i : instances) {
        if (i.getSatConstraints().contains(m1)) {
            if (found) {
                Assert.fail(m1 + " is already in a partition");
            }
            found = true;
        }
    }
    // Invalid, the constraint is over 2 partitions
    MaxOnline m2 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[5])), 3);
    Assert.assertFalse(splitter.split(m2, origin, instances, vmIndex, nodeIndex));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) MinMTTR(org.btrplace.model.constraint.MinMTTR) FixedNodeSetsPartitioning(org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MaxOnline(org.btrplace.model.constraint.MaxOnline) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) FixedSizePartitioning(org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Aggregations

TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 DefaultModel (org.btrplace.model.DefaultModel)1 Instance (org.btrplace.model.Instance)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 MaxOnline (org.btrplace.model.constraint.MaxOnline)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)1 FixedNodeSetsPartitioning (org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning)1 FixedSizePartitioning (org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning)1 Test (org.testng.annotations.Test)1