@Test
  public void testSimple() {
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    Model mo = new DefaultModel();

    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    mo.attach(rc);
    rc.setConsumption(vm1, 3);
    LinearToAResourceActionDuration<VM> d = new LinearToAResourceActionDuration<>("foo", 3);
    Assert.assertEquals(d.getCoefficient(), 3.0);
    Assert.assertEquals(d.getOffset(), 0.0);
    Assert.assertEquals(d.getResourceId(), "foo");
    Assert.assertEquals(d.evaluate(mo, vm1), 9);
    Assert.assertEquals(d.evaluate(mo, vm2), 0);

    d = new LinearToAResourceActionDuration<>("foo", 3, 4);
    Assert.assertEquals(d.evaluate(mo, vm1), 13);
    Assert.assertEquals(d.evaluate(mo, vm3), 4);

    d = new LinearToAResourceActionDuration<>("bar", 3, 4);
    Assert.assertEquals(d.evaluate(mo, vm3), -1);

    d.setCoefficient(5);
    d.setOffset(12);
    d.setResourceId("bar");
    Assert.assertEquals(d.getCoefficient(), 5.0);
    Assert.assertEquals(d.getOffset(), 12.0);
    Assert.assertEquals(d.getResourceId(), "bar");
  }
示例#2
0
 @Test
 public void testApply() {
   AllocateEvent na = new AllocateEvent(vms.get(0), "foo", 3);
   Model mo = new DefaultModel();
   Mapping map = mo.getMapping();
   map.addOnlineNode(ns.get(0));
   map.addRunningVM(vms.get(0), ns.get(0));
   Assert.assertFalse(na.apply(mo));
   ShareableResource rc = new ShareableResource("foo");
   mo.attach(rc);
   Assert.assertTrue(na.apply(mo));
   Assert.assertEquals(3, rc.getConsumption(vms.get(0)));
 }