use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testGetPartitions.
@Test(dependsOnMethods = "testNewVMSet")
public void testGetPartitions() {
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(new VM(i));
index.put(i, i % 2);
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
// check each partition contains element having the same partition key.
List<ElementSubSet<VM>> ss = s.getPartitions();
for (ElementSubSet<VM> sub : ss) {
Iterator<VM> ite = sub.iterator();
int partKey = index.get(ite.next().id());
while (ite.hasNext()) {
Assert.assertEquals(index.get(ite.next().id()), partKey);
}
}
Assert.assertEquals(s.size(), 10);
Assert.assertEquals(ss.size(), 2);
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testNewVMSet.
@Test
public void testNewVMSet() {
List<VM> l = new ArrayList<>();
TIntIntHashMap m = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(new VM(i));
m.put(i, i % 2);
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, m);
for (VM v : s.getValues()) {
Assert.assertTrue(v.id() >= 0 && v.id() < 10);
}
Assert.assertEquals(s.size(), l.size());
Assert.assertEquals(s.getRespectiveIndex(), m);
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testGetSubSet.
@Test
public void testGetSubSet() {
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 12; i++) {
l.add(new VM(i));
index.put(i, i % 3);
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
for (int i : new int[] { 0, 1, 2 }) {
Set<VM> ss = s.getSubSet(i);
Assert.assertEquals(ss.size(), 4);
for (VM v : ss) {
Assert.assertEquals(index.get(v.id()), i);
}
}
// Unknown set
Assert.assertTrue(s.getSubSet(-1).isEmpty());
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class AmongSplitterTest method testSplittable.
@Test
public void testSplittable() throws SchedulerException {
List<VM> vms = Arrays.asList(vm1, vm2, vm3);
Collection<Collection<Node>> parts = new ArrayList<>();
parts.add(Arrays.asList(n1, n2));
parts.add(Collections.singletonList(n3));
parts.add(Collections.singletonList(n4));
Among single = new Among(vms, parts);
/*
N1 v1 v2
N2 v3
---
N3 v4
--
N4 v5
*/
FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts);
partitionner.setPartitions(parts);
List<Instance> instances = partitionner.split(new DefaultParameters(), new Instance(mo, Collections.emptyList(), new MinMTTR()));
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex);
Among a = (Among) instances.get(0).getSatConstraints().iterator().next();
Assert.assertEquals(a.getGroupsOfNodes().size(), 1);
Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2));
for (Instance i : instances) {
System.out.println(i.getSatConstraints());
}
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class GatherSplitterTest method simpleTest.
@Test
public void simpleTest() {
GatherSplitter splitter = new GatherSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
m0.getMapping().addReadyVM(m0.newVM(1));
Node n1 = m0.newNode();
m0.getMapping().addOnlineNode(n1);
m0.getMapping().addRunningVM(m0.newVM(2), n1);
Model m1 = new DefaultModel();
Node n2 = m1.newNode();
Node n3 = m1.newNode();
m1.getMapping().addOnlineNode(n2);
m1.getMapping().addOnlineNode(n3);
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), n2);
m1.getMapping().addRunningVM(m1.newVM(5), n3);
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
// Only VMs in m0
Gather single = new Gather(m0.getMapping().getAllVMs());
Assert.assertTrue(splitter.split(single, null, instances, vmIndex, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
// All the VMs, test the unfeasibility
Gather among = new Gather(all, false);
Assert.assertFalse(splitter.split(among, null, instances, vmIndex, new TIntIntHashMap()));
}
Aggregations