Search in sources :

Example 1 with Transaction

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();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Transaction(org.janusgraph.core.Transaction) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphComputer(org.janusgraph.core.JanusGraphComputer) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ComputerResult (org.apache.tinkerpop.gremlin.process.computer.ComputerResult)1 JanusGraphComputer (org.janusgraph.core.JanusGraphComputer)1 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 Transaction (org.janusgraph.core.Transaction)1 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)1 Test (org.junit.jupiter.api.Test)1