use of org.btrplace.model.Model in project scheduler by btrplace.
the class MaxOnlineTest method testEquals.
public void testEquals() {
Model m = new DefaultModel();
Set<Node> s = new HashSet<>(Arrays.asList(m.newNode(), m.newNode()));
MaxOnline mo = new MaxOnline(s, 3);
Assert.assertEquals(mo, new MaxOnline(s, 3));
Assert.assertNotEquals(mo, new MaxOnline(s, 1));
Assert.assertNotEquals(mo, new MaxOnline(new HashSet<>(), 3));
Assert.assertNotEquals(new MaxOnline(s, 3, true), new MaxOnline(s, 3, false));
Assert.assertEquals(mo, new MaxOnline(s, 3));
Assert.assertNotEquals(new MaxOnline(s, 3, true).hashCode(), new MaxOnline(s, 3, false).hashCode());
Assert.assertEquals(new MaxOnline(s, 3, true), new MaxOnline(s, 3, false));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class NamingServiceTest method testEqualsAndHashCode.
@Test(dependsOnMethods = { "testRegisterAndGets" })
public void testEqualsAndHashCode() {
NamingService<VM> ns = NamingService.newVMNS();
Assert.assertEquals(ns, ns);
Model mo = new DefaultModel();
VM v = mo.newVM();
NamingService<VM> ns2 = NamingService.newVMNS();
Assert.assertEquals(ns, ns2);
Assert.assertEquals(ns.hashCode(), ns2.hashCode());
ns2.register(v, "vm0");
Assert.assertNotEquals(ns, ns2);
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class NetworkTest method defaultTest.
/**
* Test the instantiation and the creation of the objects using the default routing implementation.
*/
@Test
public void defaultTest() {
Model mo = new DefaultModel();
Network net = new Network();
Switch s = net.newSwitch(1000);
Node n1 = mo.newNode();
Node n2 = mo.newNode();
net.connect(2000, s, n1, n2);
Assert.assertNull(Network.get(mo));
mo.attach(net);
Assert.assertEquals(Network.get(mo), net);
Assert.assertTrue(net.getSwitches().size() == 1);
Assert.assertEquals(net.getSwitches().get(0), s);
Assert.assertTrue(s.getCapacity() == 1000);
Assert.assertTrue(net.getLinks().size() == 2);
Assert.assertTrue(net.getLinks().size() == 2);
for (Link l : net.getLinks()) {
Assert.assertTrue(l.getCapacity() == 2000);
Assert.assertTrue(l.getSwitch().equals(s) || l.getElement() instanceof Switch);
}
Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class NetworkTest method staticRoutingTest.
/**
* Test the static routing implementation.
*/
@Test
public void staticRoutingTest() {
Model mo = new DefaultModel();
Network net = new Network(new StaticRouting());
Switch s = net.newSwitch(1000);
Node n1 = mo.newNode();
Node n2 = mo.newNode();
net.connect(2000, s, n1, n2);
Map<Link, Boolean> route = new LinkedHashMap<>();
route.put(net.getConnectedLinks(n1).get(0), true);
route.put(net.getConnectedLinks(n2).get(0), false);
((StaticRouting) net.getRouting()).setStaticRoute(new StaticRouting.NodesMap(n1, n2), route);
mo.attach(net);
Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class ReconfigurationPlanChecker method check.
/**
* Check if a plan satisfies all the {@link SatConstraintChecker}.
*
* @param p the plan to check
* @throws SatConstraintViolationException if a violation is detected
*/
public void check(ReconfigurationPlan p) throws SatConstraintViolationException {
if (checkers.isEmpty()) {
return;
}
checkModel(p.getOrigin(), true);
if (!p.getActions().isEmpty()) {
PriorityQueue<Action> starts = new PriorityQueue<>(p.getActions().size(), STARTS_CMP);
PriorityQueue<Action> ends = new PriorityQueue<>(p.getActions().size(), ENDS_CMP);
starts.addAll(p.getActions());
ends.addAll(p.getActions());
// Starts the actions
int curMoment = starts.peek().getStart();
while (!starts.isEmpty() || !ends.isEmpty()) {
Action a = ends.peek();
while (a != null && a.getEnd() == curMoment) {
ends.remove();
startingEvent = false;
visitAndThrowOnViolation(a);
visitEvents(a, Action.Hook.POST);
a = ends.peek();
}
a = starts.peek();
while (a != null && a.getStart() == curMoment) {
starts.remove();
startingEvent = true;
visitEvents(a, Action.Hook.PRE);
visitAndThrowOnViolation(a);
a = starts.peek();
}
int nextEnd = Integer.MAX_VALUE;
if (!ends.isEmpty()) {
nextEnd = ends.peek().getEnd();
}
int nextStart = Integer.MAX_VALUE;
if (!starts.isEmpty()) {
nextStart = starts.peek().getStart();
}
curMoment = Math.min(nextEnd, nextStart);
}
}
Model mo = p.getResult();
if (mo == null) {
throw new InconsistentSolutionException(p.getOrigin(), p, "The resulting reconfiguration plan is not applyable");
}
checkModel(mo, false);
}
Aggregations