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()));
}
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));
}
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);
}
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);
}
Aggregations