/** Test spread({vm1}, {vm2}). must fail: 2 params */ @Test(expectedExceptions = {ConstraintBuilderException.class}) public void testWithBadParamsNumber() throws ConstraintBuilderException { ContinuousSpreadBuilder mb = new ContinuousSpreadBuilder(); List<VJobElement> params = new LinkedList<VJobElement>(); ExplodedSet<DefaultVirtualMachine> s1 = new ExplodedSet<DefaultVirtualMachine>(); s1.add(new DefaultVirtualMachine("vm1", 1, 1, 1)); ExplodedSet<DefaultVirtualMachine> s2 = new ExplodedSet<DefaultVirtualMachine>(); s2.add(new DefaultVirtualMachine("vm2", 1, 1, 1)); params.add(s1); params.add(s2); mb.buildConstraint(params); }
/** Test cSpread({vm1,vm2,vm3}) */ public void testValid() { ContinuousSpreadBuilder mb = new ContinuousSpreadBuilder(); List<VJobElement> params = new LinkedList<VJobElement>(); ExplodedSet<DefaultVirtualMachine> s1 = new ExplodedSet<DefaultVirtualMachine>(); s1.add(new DefaultVirtualMachine("vm1", 1, 1, 1)); s1.add(new DefaultVirtualMachine("vm2", 1, 1, 1)); s1.add(new DefaultVirtualMachine("vm3", 1, 1, 1)); params.add(s1); try { ContinuousSpread sc = mb.buildConstraint(params); Assert.assertEquals(sc.getAllVirtualMachines().size(), 3); Assert.assertEquals(sc.getVirtualMachines(), s1); } catch (ConstraintBuilderException e) { Assert.fail(e.getMessage(), e); } }
/** Test oneOf in presence of a fence constraint */ public void testFenceOneOf() { Configuration cfg = new SimpleConfiguration(); // Some nodes ExplodedSet<Node>[] parts = new ExplodedSet[2]; for (int i = 0; i < parts.length; i++) { parts[i] = new ExplodedSet<Node>("$P" + (i + 1)); for (int j = 0; j < 5; j++) { Node n = new SimpleNode("N" + (10 * i + j + 1), 10, 10, 10); parts[i].add(n); cfg.addOnline(n); } } // Some VMs ExplodedSet<VirtualMachine> app = new ExplodedSet<VirtualMachine>("$A"); ExplodedSet<VirtualMachine> sub = new ExplodedSet<VirtualMachine>("$A/2"); for (int i = 0; i < 10; i++) { VirtualMachine vm = new SimpleVirtualMachine("VM" + (i + 1), 1, 1, 1); cfg.addWaiting(vm); if (i < 5) { sub.add(vm); } app.add(vm); } PlanPartitioner part = new OtherPartitioning(cfg); ExplodedMultiSet<Node> m = new ExplodedMultiSet<Node>(); m.add(parts[0]); m.add(parts[1]); OneOf of = new OneOf(app, m); Fence f = new Fence(app, parts[0]); try { part.part(f); part.part(of); } catch (PartitioningException e) { Assert.fail(e.getMessage(), e); } part.getResultingPartitions(); }