use of org.janusgraph.core.Transaction in project janusgraph by JanusGraph.
the class OLAPTest method degreeCountingDistance.
@Test
public void degreeCountingDistance() throws Exception {
int numV = 100;
int numE = generateRandomGraph(numV);
clopen();
// TODO does this iteration over JanusGraphComputer.ResultMode values imply that DegreeVariation's ResultGraph/Persist should also change?
for (JanusGraphComputer.ResultMode mode : JanusGraphComputer.ResultMode.values()) {
final JanusGraphComputer computer = graph.compute();
computer.resultMode(mode);
computer.workers(1);
computer.program(new DegreeCounter(2));
ComputerResult result = computer.submit().get();
System.out.println("Execution time (ms) [" + numV + "|" + numE + "]: " + result.memory().getRuntime());
assertEquals(2, result.memory().getIteration());
Transaction gview = null;
switch(mode) {
case LOCALTX:
gview = (Transaction) result.graph();
break;
case PERSIST:
newTx();
gview = tx;
break;
case NONE:
break;
default:
throw new AssertionError(mode);
}
if (gview == null)
continue;
for (JanusGraphVertex v : gview.query().vertices()) {
long degree2 = ((Integer) v.value(DegreeCounter.DEGREE)).longValue();
long actualDegree2 = 0;
for (JanusGraphVertex w : v.query().direction(Direction.OUT).vertices()) {
actualDegree2 += Iterables.size(w.query().direction(Direction.OUT).vertices());
}
assertEquals(actualDegree2, degree2);
}
if (mode == JanusGraphComputer.ResultMode.LOCALTX) {
assertTrue(gview instanceof JanusGraphTransaction);
((JanusGraphTransaction) gview).rollback();
}
}
}
Aggregations