/** * A VM try to come into the quarantine zone. * * @throws org.btrplace.scheduler.SchedulerException */ @Test public void testWithNoSolution1() throws SchedulerException { Model mo = new DefaultModel(); VM vm1 = mo.newVM(); VM vm2 = mo.newVM(); VM vm3 = mo.newVM(); VM vm4 = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); Node n3 = mo.newNode(); Mapping map = new MappingFiller(mo.getMapping()) .on(n1, n2, n3) .run(n1, vm1) .run(n2, vm2, vm3) .run(n3, vm4) .get(); Quarantine q = new Quarantine(n1); List<SatConstraint> cstrs = new ArrayList<>(); cstrs.add(q); cstrs.add(new Fence(vm4, Collections.singleton(n1))); ChocoScheduler cra = new DefaultChocoScheduler(); ReconfigurationPlan p = cra.solve(mo, cstrs); Assert.assertNull(p); }
@Test public void simpleTest() { OverbookSplitter splitter = new OverbookSplitter(); List<Instance> instances = new ArrayList<>(); Model m0 = new DefaultModel(); Node n = m0.newNode(0); m0.getMapping().addOnlineNode(n); m0.getMapping().addOnlineNode(m0.newNode(1)); Model m1 = new DefaultModel(); m1.getMapping().addOnlineNode(m1.newNode(2)); m1.getMapping().addOnlineNode(m1.newNode(3)); instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR())); instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR())); Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes()); all.addAll(m1.getMapping().getAllNodes()); TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances); // Only nodes in m0 Overbook oSimple = new Overbook(n, "cpu", 2); Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex)); Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple)); Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple)); }
@Test public void testEqualsHashCode() { Model mo = new DefaultModel(); Node n = mo.newNode(); Quarantine q = new Quarantine(n); Assert.assertTrue(q.equals(q)); Assert.assertTrue(q.equals(new Quarantine(n))); Assert.assertEquals(q.hashCode(), new Quarantine(n).hashCode()); Assert.assertFalse(q.equals(new Quarantine(mo.newNode()))); }
@Test public void testViables() throws JSONConverterException { Model mo = new DefaultModel(); OverbookConverter conv = new OverbookConverter(); Overbook d = new Overbook(mo.newNode(), "foo", 1.4); Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d); System.out.println(conv.toJSONString(d)); }
@Test public void testWithSatisfiedModel() throws SchedulerException { Model mo = new DefaultModel(); VM vm1 = mo.newVM(); VM vm2 = mo.newVM(); VM vm3 = mo.newVM(); VM vm4 = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); Node n3 = mo.newNode(); Mapping map = new MappingFiller(mo.getMapping()) .on(n1, n2, n3) .run(n1, vm1) .run(n2, vm2, vm3) .run(n3, vm4) .get(); Quarantine q = new Quarantine(n2); ChocoScheduler cra = new DefaultChocoScheduler(); ReconfigurationPlan p = cra.solve(mo, Collections.<SatConstraint>singleton(q)); Assert.assertNotNull(p); }
@Test public void testInstantiation() { Model mo = new DefaultModel(); Node n = mo.newNode(); Quarantine q = new Quarantine(n); Assert.assertNotNull(q.getChecker()); Assert.assertTrue(q.getInvolvedVMs().isEmpty()); Assert.assertEquals(q.getInvolvedNodes().iterator().next(), n); Assert.assertTrue(q.isContinuous()); Assert.assertFalse(q.setContinuous(false)); Assert.assertTrue(q.setContinuous(true)); Assert.assertFalse(q.toString().contains("null")); // Assert.assertEquals(q.isSatisfied(new DefaultModel()), SatConstraint.Sat.UNDEFINED); System.out.println(q); }
/** * Unit tests for {@link AmongSplitter}. * * @author Fabien Hermenier */ public class AmongSplitterTest { public static final AmongSplitter splitter = new AmongSplitter(); public static final Model mo = new DefaultModel(); public static final VM vm1 = mo.newVM(); public static final VM vm2 = mo.newVM(); public static final VM vm3 = mo.newVM(); public static final VM vm4 = mo.newVM(); public static final VM vm5 = mo.newVM(); public static final Node n1 = mo.newNode(); public static final Node n2 = mo.newNode(); public static final Node n3 = mo.newNode(); public static final Node n4 = mo.newNode(); public static final Node n5 = mo.newNode(); public static final Mapping map = new MappingFiller(mo.getMapping()) .on(n1, n2, n3, n4) .run(n1, vm1, vm2) .run(n2, vm3) .run(n3, vm4) .run(n4, vm5) .get(); @Test public void testSplittable() throws SchedulerException { List<VM> vms = Arrays.asList(vm1, vm2, vm3); Collection<Collection<Node>> parts = new ArrayList<>(); parts.add(Arrays.asList(n1, n2)); parts.add(Arrays.asList(n3)); parts.add(Arrays.asList(n4)); Among single = new Among(vms, parts); /* N1 v1 v2 N2 v3 --- N3 v4 -- N4 v5 */ FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts); partitionner.setPartitions(parts); List<Instance> instances = partitionner.split( new DefaultParameters(), new Instance(mo, Collections.<SatConstraint>emptyList(), new MinMTTR())); TIntIntHashMap vmIndex = Instances.makeVMIndex(instances); TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances); splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex); Among a = (Among) instances.get(0).getSatConstraints().iterator().next(); Assert.assertEquals(a.getGroupsOfNodes().size(), 1); Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2)); for (Instance i : instances) { System.out.println(i.getSatConstraints()); } } }