// There's no graph, so we expect an exception to be thrown
}
@Test
public void testDistGraphZach() throws Exception {
SgsTestNode node1 = null;
SgsTestNode node2 = null;
SgsTestNode node3 = null;
try {
// Create three app nodes
node1 = createNode();
node2 = createNode();
node3 = createNode();
// Send updates to each of the node's graph listeners
LPADriver driver1 = (LPADriver)
finderField.get(node1.getNodeMappingService());
LPADriver driver2 = (LPADriver)
finderField.get(node2.getNodeMappingService());
LPADriver driver3 = (LPADriver)
finderField.get(node3.getNodeMappingService());
DummyIdentity[] idents = new DummyIdentity[35];
// Create identities for zach karate club
// location of identities for the accesses below
// node1: 1,4,7,10,13,16,19,22,25,28,31,34
// node2: 2,5,8,11,14,17,20,23,26,29,32
// node3: 3,6,9,12,15,18,21,24,27,30,33
// Actual round robin policy might assign these differently...
NodeMappingService nms = node1.getNodeMappingService();
for (int i = 1; i < 35; i++) {
idents[i] = new DummyIdentity(String.valueOf(i));
nms.assignNode(this.getClass(), idents[i]);
}
// Node 1 uses.
AffinityGraphBuilder builder1 = driver1.getGraphBuilder();
AccessedObjectsDetailTest detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o1"));
detail.addAccess(new String("o2"));
detail.addAccess(new String("o3"));
detail.addAccess(new String("o5"));
detail.addAccess(new String("o8"));
detail.addAccess(new String("o11"));
detail.addAccess(new String("o12"));
detail.addAccess(new String("o16"));
detail.addAccess(new String("o18"));
detail.addAccess(new String("o20"));
detail.addAccess(new String("o32"));
detail.addAccess(new String("o84"));
builder1.updateGraph(idents[1], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o1"));
detail.addAccess(new String("o13"));
detail.addAccess(new String("o87"));
builder1.updateGraph(idents[4], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o2"));
detail.addAccess(new String("o4"));
detail.addAccess(new String("o15"));
builder1.updateGraph(idents[7], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o7"));
detail.addAccess(new String("o40"));
builder1.updateGraph(idents[10], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o12"));
detail.addAccess(new String("o13"));
builder1.updateGraph(idents[13], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o35"));
detail.addAccess(new String("o43"));
builder1.updateGraph(idents[16], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o36"));
detail.addAccess(new String("o44"));
builder1.updateGraph(idents[19], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o20"));
detail.addAccess(new String("o21"));
builder1.updateGraph(idents[22], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o23"));
detail.addAccess(new String("o26"));
builder1.updateGraph(idents[25], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o24"));
detail.addAccess(new String("o25"));
detail.addAccess(new String("o26"));
detail.addAccess(new String("o50"));
builder1.updateGraph(idents[28], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o30"));
detail.addAccess(new String("o31"));
builder1.updateGraph(idents[31], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o31"));
detail.addAccess(new String("o40"));
detail.addAccess(new String("o41"));
detail.addAccess(new String("o42"));
detail.addAccess(new String("o43"));
detail.addAccess(new String("o44"));
detail.addAccess(new String("o45"));
detail.addAccess(new String("o46"));
detail.addAccess(new String("o47"));
detail.addAccess(new String("o48"));
detail.addAccess(new String("o49"));
detail.addAccess(new String("o50"));
detail.addAccess(new String("o51"));
detail.addAccess(new String("o52"));
detail.addAccess(new String("o53"));
builder1.updateGraph(idents[34], detail);
// Node 2
AffinityGraphBuilder builder2 = driver2.getGraphBuilder();
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o1"));
detail.addAccess(new String("o17"));
detail.addAccess(new String("o19"));
detail.addAccess(new String("o21"));
detail.addAccess(new String("o30"));
detail.addAccess(new String("o85"));
builder2.updateGraph(idents[2], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o2"));
detail.addAccess(new String("o9"));
builder2.updateGraph(idents[5], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o1"));
builder2.updateGraph(idents[8], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o8"));
detail.addAccess(new String("o9"));
detail.addAccess(new String("o10"));
builder2.updateGraph(idents[11], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o84"));
detail.addAccess(new String("o85"));
detail.addAccess(new String("o86"));
detail.addAccess(new String("o87"));
detail.addAccess(new String("o41"));
builder2.updateGraph(idents[14], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o14"));
detail.addAccess(new String("o15"));
builder2.updateGraph(idents[17], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o18"));
detail.addAccess(new String("o19"));
detail.addAccess(new String("o45"));
builder2.updateGraph(idents[20], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o38"));
detail.addAccess(new String("o47"));
builder2.updateGraph(idents[23], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o22"));
detail.addAccess(new String("o23"));
builder2.updateGraph(idents[26], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o27"));
detail.addAccess(new String("o51"));
detail.addAccess(new String("o66"));
builder2.updateGraph(idents[29], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o23"));
detail.addAccess(new String("o66"));
detail.addAccess(new String("o32"));
detail.addAccess(new String("o39"));
detail.addAccess(new String("o53"));
builder2.updateGraph(idents[32], detail);
// Node 3
AffinityGraphBuilder builder3 = driver3.getGraphBuilder();
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o1"));
detail.addAccess(new String("o6"));
detail.addAccess(new String("o7"));
detail.addAccess(new String("o24"));
detail.addAccess(new String("o27"));
detail.addAccess(new String("o33"));
detail.addAccess(new String("o86"));
builder3.updateGraph(idents[3], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o3"));
detail.addAccess(new String("o4"));
detail.addAccess(new String("o10"));
detail.addAccess(new String("o14"));
builder3.updateGraph(idents[6], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o5"));
detail.addAccess(new String("o6"));
detail.addAccess(new String("o31"));
builder3.updateGraph(idents[9], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o11"));
builder3.updateGraph(idents[12], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o34"));
detail.addAccess(new String("o42"));
builder3.updateGraph(idents[15], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o16"));
detail.addAccess(new String("o17"));
builder3.updateGraph(idents[18], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o37"));
detail.addAccess(new String("o46"));
builder3.updateGraph(idents[21], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o22"));
detail.addAccess(new String("o25"));
detail.addAccess(new String("o28"));
detail.addAccess(new String("o48"));
builder3.updateGraph(idents[24], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o29"));
detail.addAccess(new String("o49"));
builder3.updateGraph(idents[27], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o28"));
detail.addAccess(new String("o29"));
detail.addAccess(new String("o52"));
builder3.updateGraph(idents[30], detail);
detail = new AccessedObjectsDetailTest();
detail.addAccess(new String("o28"));
detail.addAccess(new String("o31"));
detail.addAccess(new String("o33"));
detail.addAccess(new String("o34"));
detail.addAccess(new String("o35"));
detail.addAccess(new String("o36"));
detail.addAccess(new String("o37"));
detail.addAccess(new String("o38"));
detail.addAccess(new String("o39"));
builder3.updateGraph(idents[33], detail);
UndirectedGraph<LabelVertex, WeightedEdge> graphModel =
new ZachBuilder().getAffinityGraph();
System.out.println("MODEL GRAPH IS " + graphModel);
LPADriver driver = (LPADriver)
finderField.get(serverNode.getNodeMappingService());
GraphListener serverListener = driver.getGraphListener();
AffinityGraphBuilder builder = driver.getGraphBuilder();
// The graph can only be found on the server side. Let's make
// sure it looks like the expected Zachary graph.
// The core server graph listener builds a DistGraphBuilder,
// which (on the core node) creates the DistGraphBuilderServerImpl.
// We can find it if we look for the group finder.
AffinityGraphBuilder serverBuilder =
(AffinityGraphBuilder) builder.getAffinityGroupFinder();
UndirectedGraph<LabelVertex, WeightedEdge> graph =
serverBuilder.getAffinityGraph();
System.out.println("GRAPH IS " + graph);
Assert.assertEquals(34, graph.getVertexCount());
Assert.assertEquals(78, graph.getEdgeCount());
ProfileCollector col =
serverNode.getSystemRegistry().
getComponent(ProfileCollector.class);
AffinityGroupFinderMXBean bean = (AffinityGroupFinderMXBean)
col.getRegisteredMBean(AffinityGroupFinderMXBean.MXBEAN_NAME);
assertNotNull(bean);
bean.clear();
// Be sure the consumer is turned on
col.getConsumer(AffinityGroupFinderStats.CONS_NAME).
setProfileLevel(ProfileLevel.MAX);
double avgMod = 0.0;
double maxMod = 0.0;
double minMod = 1.0;
for (int i = 0; i < RUNS; i++) {
Set<AffinityGroup> groups =
Objects.uncheckedCast(
builder.getAffinityGroupFinder().findAffinityGroups());
double mod =
AffinityGroupGoodness.calcModularity(graphModel, groups);
avgMod = avgMod + mod;
maxMod = Math.max(maxMod, mod);
minMod = Math.min(minMod, mod);
}
System.out.printf("DIST (%d runs, %d threads): " +
"avg time : %4.2f ms, " +
" time range [%d - %d ms] " +
" avg iters : %4.2f, avg modularity: %.4f, " +
" modularity range [%.4f - %.4f] %n",
RUNS, numThreads,
bean.getAvgRunTime(),
bean.getMinRunTime(),
bean.getMaxRunTime(),
bean.getAvgIterations(),
avgMod/(double) RUNS,
minMod, maxMod);
} finally {
if (node1 != null) {
node1.shutdown(false);
}
if (node2 != null) {
node2.shutdown(false);
}
if (node3 != null) {
node3.shutdown(false);
}
}
}