Search in sources :

Example 1 with Gather

use of org.btrplace.model.constraint.Gather in project scheduler by btrplace.

the class GatherSplitterTest method simpleTest.

@Test
public void simpleTest() {
    GatherSplitter splitter = new GatherSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    m0.getMapping().addReadyVM(m0.newVM(1));
    Node n1 = m0.newNode();
    m0.getMapping().addOnlineNode(n1);
    m0.getMapping().addRunningVM(m0.newVM(2), n1);
    Model m1 = new DefaultModel();
    Node n2 = m1.newNode();
    Node n3 = m1.newNode();
    m1.getMapping().addOnlineNode(n2);
    m1.getMapping().addOnlineNode(n3);
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), n2);
    m1.getMapping().addRunningVM(m1.newVM(5), n3);
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
    // Only VMs in m0
    Gather single = new Gather(m0.getMapping().getAllVMs());
    Assert.assertTrue(splitter.split(single, null, instances, vmIndex, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
    // All the VMs, test the unfeasibility
    Gather among = new Gather(all, false);
    Assert.assertFalse(splitter.split(among, null, instances, vmIndex, new TIntIntHashMap()));
}
Also used : ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Gather(org.btrplace.model.constraint.Gather) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Gather

use of org.btrplace.model.constraint.Gather in project scheduler by btrplace.

the class GatherConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new GatherConverter());
    Gather d = new Gather(Arrays.asList(mo.newVM(), mo.newVM()), false);
    Gather c = new Gather(Arrays.asList(mo.newVM(), mo.newVM()), true);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Gather(org.btrplace.model.constraint.Gather) Test(org.testng.annotations.Test)

Example 3 with Gather

use of org.btrplace.model.constraint.Gather in project scheduler by btrplace.

the class ScriptTest method testConstraints.

public void testConstraints() {
    Script v = new Script();
    Model mo = new DefaultModel();
    VM vm2 = mo.newVM();
    v.addConstraint(new Gather(Collections.singleton(vm2)));
    v.addConstraint(new RunningCapacity(Collections.singleton(mo.newNode()), 5));
    Assert.assertEquals(v.getConstraints().size(), 2);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Gather(org.btrplace.model.constraint.Gather)

Example 4 with Gather

use of org.btrplace.model.constraint.Gather in project scheduler by btrplace.

the class GatherBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodGathers")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Gather x = (Gather) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Gather(org.btrplace.model.constraint.Gather) Test(org.testng.annotations.Test)

Aggregations

Gather (org.btrplace.model.constraint.Gather)4 DefaultModel (org.btrplace.model.DefaultModel)3 Test (org.testng.annotations.Test)3 Model (org.btrplace.model.Model)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 VM (org.btrplace.model.VM)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 RunningCapacity (org.btrplace.model.constraint.RunningCapacity)1