use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class OLAPTest method testShortestDistance.
@Test
public void testShortestDistance() throws Exception {
PropertyKey distance = mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
mgmt.makeEdgeLabel("connect").signature(distance).multiplicity(Multiplicity.MULTI).make();
finishSchema();
int maxDepth = 16;
int maxBranch = 5;
JanusGraphVertex vertex = tx.addVertex();
// Grow a star-shaped graph around vertex which will be the single-source for this shortest path computation
final int numV = growVertex(vertex, 0, maxDepth, maxBranch);
final int numE = numV - 1;
assertCount(numV, tx.query().vertices());
assertCount(numE, tx.query().edges());
log.debug("seed inE count: {}", vertex.query().direction(Direction.IN).edgeCount());
log.debug("seed outE count: {}", vertex.query().direction(Direction.OUT).edgeCount());
clopen();
final JanusGraphComputer computer = graph.compute();
computer.resultMode(JanusGraphComputer.ResultMode.NONE);
computer.workers(4);
computer.program(ShortestDistanceVertexProgram.build().seed((long) vertex.id()).maxDepth(maxDepth + 4).create(graph));
computer.mapReduce(ShortestDistanceMapReduce.build().create());
ComputerResult result = computer.submit().get();
Iterator<KeyValue<Long, Long>> distances = result.memory().get(ShortestDistanceMapReduce.DEFAULT_MEMORY_KEY);
int vertexCount = 0;
while (distances.hasNext()) {
final KeyValue<Long, Long> kv = distances.next();
final long dist = kv.getValue();
assertTrue(dist >= 0 && dist < Integer.MAX_VALUE, "Invalid distance: " + dist);
JanusGraphVertex v = getV(tx, kv.getKey());
assertEquals(v.<Integer>value("distance").intValue(), dist);
vertexCount++;
}
assertEquals(numV, vertexCount);
assertTrue(0 < vertexCount);
}
Aggregations