Exemplo n.º 1
0
  @Test
  public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 5);
    List<Node> ns = Util.newNodes(mo, 5);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(1));
    map.addReadyVM(vms.get(2));
    map.addRunningVM(vms.get(3), ns.get(2));

    Quarantine q = new Quarantine(ns.get(0));

    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(q.isSatisfied(plan), true);
    plan.add(new ShutdownVM(vms.get(1), ns.get(1), 1, 2));
    Assert.assertEquals(q.isSatisfied(plan), true);

    plan.add(new BootVM(vms.get(2), ns.get(0), 0, 1));
    Assert.assertEquals(q.isSatisfied(plan), false);

    plan = new DefaultReconfigurationPlan(mo);
    plan.add(new BootVM(vms.get(2), ns.get(2), 0, 1));
    Assert.assertEquals(new Quarantine(ns.get(1)).isSatisfied(plan), true);
    plan.add(new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1));
    Assert.assertEquals(new Quarantine(ns.get(1)).isSatisfied(plan), false);

    plan = new DefaultReconfigurationPlan(mo);
    plan.add(new MigrateVM(vms.get(1), ns.get(1), ns.get(0), 0, 1));
    Assert.assertEquals(q.isSatisfied(plan), false);
  }
Exemplo n.º 2
0
 @Test
 public void testQuarantines() {
   Model mo = new DefaultModel();
   List<Node> ns = Util.newNodes(mo, 5);
   List<Quarantine> qs = Quarantine.newQuarantine(ns);
   Assert.assertEquals(qs.size(), ns.size());
   qs.stream()
       .forEach(
           (q) -> {
             Assert.assertTrue(ns.containsAll(q.getInvolvedNodes()));
             Assert.assertTrue(q.isContinuous());
           });
 }
Exemplo n.º 3
0
/**
 * Unit tests for {@link AllocateEvent}.
 *
 * @author Fabien Hermenier
 */
public class AllocateEventTest {

  static Model mo = new DefaultModel();
  static List<Node> ns = Util.newNodes(mo, 10);
  static List<VM> vms = Util.newVMs(mo, 10);
  static AllocateEvent a = new AllocateEvent(vms.get(0), "foo", 3);

  @Test
  public void testBasics() {
    AllocateEvent na = new AllocateEvent(vms.get(0), "foo", 3);
    Assert.assertEquals(vms.get(0), na.getVM());
    Assert.assertEquals("foo", na.getResourceId());
    Assert.assertEquals(3, na.getAmount());
    Assert.assertFalse(na.toString().contains("null"));
  }

  @Test
  public void testEqualsHashCode() {
    AllocateEvent na = new AllocateEvent(vms.get(0), "foo", 3);
    AllocateEvent na2 = new AllocateEvent(vms.get(0), "foo", 3);
    Assert.assertFalse(na.equals(new Object()));
    Assert.assertTrue(na.equals(na));
    Assert.assertTrue(na.equals(na2));
    Assert.assertTrue(na2.equals(na));
    Assert.assertEquals(na.hashCode(), na2.hashCode());
    Assert.assertFalse(na.equals(new AllocateEvent(vms.get(1), "foo", 3)));
    Assert.assertFalse(na.equals(new AllocateEvent(vms.get(0), "bar", 3)));
    Assert.assertFalse(na.equals(new AllocateEvent(vms.get(0), "foo", 5)));
  }

  @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)));
  }

  @Test
  public void testVisit() {
    ActionVisitor visitor = mock(ActionVisitor.class);
    a.visit(visitor);
    verify(visitor).visit(a);
  }
}