Search in sources :

Example 1 with ModelView

use of org.btrplace.model.view.ModelView in project scheduler by btrplace.

the class SubstitutedVMEventTest method testApply.

@Test
public void testApply() {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addReadyVM(vms.get(0));
    map.addReadyVM(vms.get(2));
    ModelView v = mock(ModelView.class);
    mo.attach(v);
    Assert.assertTrue(s.apply(mo));
    verify(v).substituteVM(vms.get(0), vms.get(1));
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Example 2 with ModelView

use of org.btrplace.model.view.ModelView in project scheduler by btrplace.

the class DefaultModel method toString.

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append("Mapping:\n");
    b.append(getMapping());
    b.append("\nAttributes:");
    if (!getAttributes().getDefined().isEmpty()) {
        b.append("\n");
        b.append(getAttributes());
    } else {
        b.append(" -");
    }
    b.append("\nViews:");
    if (resources.isEmpty()) {
        b.append(" -");
    } else {
        b.append("\n");
        StringJoiner joiner = new StringJoiner("\n");
        for (Map.Entry<String, ModelView> entry : resources.entrySet()) {
            joiner.add(String.format("%s: %s", entry.getKey(), entry.getValue()));
        }
        b.append(joiner.toString());
    }
    return b.toString();
}
Also used : ModelView(org.btrplace.model.view.ModelView) Map(java.util.Map) HashMap(java.util.HashMap) StringJoiner(java.util.StringJoiner)

Example 3 with ModelView

use of org.btrplace.model.view.ModelView in project scheduler by btrplace.

the class DefaultModel method copy.

@Override
public Model copy() {
    DefaultModel m = new DefaultModel(elemBuilder.copy());
    MappingUtils.fill(cfg, m.cfg);
    for (ModelView rc : resources.values()) {
        m.attach(rc.copy());
    }
    m.setAttributes(this.getAttributes().copy());
    return m;
}
Also used : ModelView(org.btrplace.model.view.ModelView)

Example 4 with ModelView

use of org.btrplace.model.view.ModelView in project scheduler by btrplace.

the class DefaultModelTest method testDetachView.

@Test(dependsOnMethods = { "testAttachView", "testInstantiate" })
public void testDetachView() {
    Model i = new DefaultModel();
    ModelView v = mock(ModelView.class);
    when(v.getIdentifier()).thenReturn("cpu");
    i.attach(v);
    Assert.assertTrue(i.detach(v));
    Assert.assertTrue(i.getViews().isEmpty());
    Assert.assertNull(i.getView("cpu"));
    Assert.assertFalse(i.detach(v));
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Example 5 with ModelView

use of org.btrplace.model.view.ModelView in project scheduler by btrplace.

the class DefaultModelTest method testClearViews.

@Test(dependsOnMethods = { "testAttachView", "testInstantiate" })
public void testClearViews() {
    Model i = new DefaultModel();
    ModelView v1 = mock(ModelView.class);
    when(v1.getIdentifier()).thenReturn("cpu");
    ModelView v2 = mock(ModelView.class);
    when(v2.getIdentifier()).thenReturn("mem");
    i.attach(v1);
    i.attach(v2);
    i.clearViews();
    Assert.assertTrue(i.getViews().isEmpty());
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Aggregations

ModelView (org.btrplace.model.view.ModelView)11 Test (org.testng.annotations.Test)6 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringJoiner (java.util.StringJoiner)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1