// These match the ones from the partial toy builder
Identity id1 = new DummyIdentity("1");
Identity id2 = new DummyIdentity("2");
Identity id3 = new DummyIdentity("3");
Identity id4 = new DummyIdentity("4");
LabelPropagation lp1 =
new LabelPropagation(new PartialToyBuilder(PartialToyBuilder.NODE1),
wdog, PartialToyBuilder.NODE1, props);
LabelPropagation lp2 =
new LabelPropagation(new PartialToyBuilder(PartialToyBuilder.NODE2),
wdog, PartialToyBuilder.NODE2, props);
LabelPropagation lp3 =
new LabelPropagation(new PartialToyBuilder(PartialToyBuilder.NODE3),
wdog, PartialToyBuilder.NODE3, props);
lp1.prepareAlgorithm(1);
lp2.prepareAlgorithm(1);
lp3.prepareAlgorithm(1);
int count = 0;
while (server.readyToBeginCount() < 3) {
Thread.sleep(5);
if (++count > MAX_SLEEP_COUNT) {
fail("Too much time sleeping");
}
}
Set<Object> objIds = new HashSet<Object>();
objIds.add("obj1");
objIds.add("obj2");
Map<Object, Map<Integer, List<Long>>> labelMap =
lp1.getRemoteLabels(objIds);
assertEquals(2, labelMap.size());
assertTrue(labelMap.keySet().equals(objIds));
Map<Integer, List<Long>> obj1Map = labelMap.get("obj1");
assertEquals(2, obj1Map.size());
for (Integer label : obj1Map.keySet()) {
assertTrue(label.equals(1) || label.equals(2));
}
// Check returned weights
List<Long> oneWeightList = obj1Map.get(1);
assertEquals(1, oneWeightList.size());
for (Long weight : oneWeightList) {
assertEquals(2, weight.intValue());
}
List<Long> twoWeightList = obj1Map.get(2);
assertEquals(1, twoWeightList.size());
for (Long weight : twoWeightList) {
assertEquals(2, weight.intValue());
}
Map<Integer, List<Long>> obj2Map = labelMap.get("obj2");
assertEquals(1, obj2Map.size());
for (Integer label : obj2Map.keySet()) {
assertTrue(label.equals(2));
}
twoWeightList = obj2Map.get(2);
assertEquals(1, twoWeightList.size());
for (Long weight : twoWeightList) {
assertEquals(1, weight.intValue());
}
// Call the private implementation to update the remote label
// maps, and check it. We do this, rather than running an iteration,
// because we don't want the labels to change.
Method updateRemoteLabelsMethod =
UtilReflection.getMethod(LabelPropagation.class,
"updateRemoteLabels");
updateRemoteLabelsMethod.invoke(lp1);
updateRemoteLabelsMethod.invoke(lp2);
updateRemoteLabelsMethod.invoke(lp3);
// node 1
ConcurrentMap<Identity, Map<Integer, Long>> rlm =
lp1.getRemoteLabelMap();
assertEquals(2, rlm.size());
for (Identity id : rlm.keySet()) {
assertTrue (id.equals(id1) || id.equals(id2));
}
Map<Integer, Long> labelWeight = rlm.get(id1);
assertEquals(1, labelWeight.size());
Long weight = labelWeight.get(3);
assertTrue(weight != null);
assertEquals(1, weight.intValue());
labelWeight = rlm.get(id2);
assertEquals(2, labelWeight.size());
weight = labelWeight.get(3);
assertTrue(weight != null);
assertEquals(1, weight.intValue());
weight = labelWeight.get(4);
assertTrue(weight != null);
assertEquals(1, weight.intValue());
// node 2
rlm = lp2.getRemoteLabelMap();
assertEquals(1, rlm.size());
for (Identity id : rlm.keySet()) {
assertEquals(id3, id);
}
labelWeight = rlm.get(id3);
assertEquals(2, labelWeight.size());
weight = labelWeight.get(1);
assertTrue(weight != null);
assertEquals(1, weight.intValue());
weight = labelWeight.get(2);
assertTrue(weight != null);
assertEquals(1, weight.intValue());
// node 3
rlm = lp3.getRemoteLabelMap();
assertEquals(1, rlm.size());
for (Identity id : rlm.keySet()) {
assertEquals(id4, id);
}
labelWeight = rlm.get(id4);