Package com.tinkerpop.blueprints.impls.neo4j2

Source Code of com.tinkerpop.blueprints.impls.neo4j2.Neo4j2GraphTest

package com.tinkerpop.blueprints.impls.neo4j2;

import com.tinkerpop.blueprints.EdgeTestSuite;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.GraphQueryTestSuite;
import com.tinkerpop.blueprints.GraphTestSuite;
import com.tinkerpop.blueprints.IndexTestSuite;
import com.tinkerpop.blueprints.IndexableGraphTestSuite;
import com.tinkerpop.blueprints.KeyIndexableGraphTestSuite;
import com.tinkerpop.blueprints.TestSuite;
import com.tinkerpop.blueprints.TransactionalGraphTestSuite;
import com.tinkerpop.blueprints.VertexQueryTestSuite;
import com.tinkerpop.blueprints.VertexTestSuite;
import com.tinkerpop.blueprints.impls.GraphTest;
import com.tinkerpop.blueprints.util.io.gml.GMLReaderTestSuite;
import com.tinkerpop.blueprints.util.io.graphml.GraphMLReaderTestSuite;
import com.tinkerpop.blueprints.util.io.graphson.GraphSONReaderTestSuite;

import java.io.File;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class Neo4j2GraphTest extends GraphTest {

    /*public void testNeo4jBenchmarkTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new Neo4j2BenchmarkTestSuite(this));
        printTestPerformance("Neo4j2BenchmarkTestSuite", this.stopWatch());
    }*/

    public void testVertexTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new VertexTestSuite(this));
        printTestPerformance("VertexTestSuite", this.stopWatch());
    }

    public void testEdgeTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new EdgeTestSuite(this));
        printTestPerformance("EdgeTestSuite", this.stopWatch());
    }

    public void testGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphTestSuite(this));
        printTestPerformance("GraphTestSuite", this.stopWatch());
    }

    public void testVertexQueryTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new VertexQueryTestSuite(this));
        printTestPerformance("VertexQueryTestSuite", this.stopWatch());
    }

    public void testGraphQueryTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphQueryTestSuite(this));
        printTestPerformance("GraphQueryTestSuite", this.stopWatch());
    }

    public void testKeyIndexableGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new KeyIndexableGraphTestSuite(this));
        printTestPerformance("KeyIndexableGraphTestSuite", this.stopWatch());
    }

    public void testIndexableGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new IndexableGraphTestSuite(this));
        printTestPerformance("IndexableGraphTestSuite", this.stopWatch());
    }

    public void testIndexTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new IndexTestSuite(this));
        printTestPerformance("IndexTestSuite", this.stopWatch());
    }

    public void testTransactionalGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new TransactionalGraphTestSuite(this));
        printTestPerformance("TransactionalGraphTestSuite", this.stopWatch());
    }

    public void testGraphMLReaderTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphMLReaderTestSuite(this));
        printTestPerformance("GraphMLReaderTestSuite", this.stopWatch());
    }

    public void testGraphSONReaderTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphSONReaderTestSuite(this));
        printTestPerformance("GraphSONReaderTestSuite", this.stopWatch());
    }

    public void testGMLReaderTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GMLReaderTestSuite(this));
        printTestPerformance("GMLReaderTestSuite", this.stopWatch());
    }

    public void testNeo4jGraphSpecificTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new Neo4j2GraphSpecificTestSuite(this));
        printTestPerformance("Neo4j2GraphSpecificTestSuite", this.stopWatch());
    }

    public Graph generateGraph() {
        return generateGraph("graph");
    }

    public Graph generateGraph(final String graphDirectoryName) {
        final String directory = getWorkingDirectory();
        Neo4j2Graph graph = new Neo4j2Graph(directory + "/" + graphDirectoryName);
        graph.setCheckElementsInTransaction(true);

        // for clean shutdown later
        testGraph.set(graph);

        return graph;
    }

    private final static ThreadLocal<Graph> testGraph = new ThreadLocal<Graph>();

    public void doTestSuite(final TestSuite testSuite) throws Exception {
        String directory = this.getWorkingDirectory();
        deleteDirectory(new File(directory));
        int total = 0;
        Map<Method, Exception> failures = new LinkedHashMap<Method, Exception>();
        for (Method method : testSuite.getClass().getDeclaredMethods()) {
            if (method.getName().startsWith("test")) {
                System.out.println("Testing " + method.getName() + "...");
                try {
                    total++;
                    method.invoke(testSuite);
                } catch (Exception e) {
                    // report all errors not just the first
                    failures.put(method, e);
                    System.out.println("Error during " + method.getName() + " " + e.getMessage());
                    e.printStackTrace();
                } finally {
                    // clean shutdown w/o leaking resources even in case of AssertionErrors
                    if (testGraph.get() != null) {
                        testGraph.get().shutdown();
                    }
                    deleteDirectory(new File(directory));
                }
            }
        }
        // fail the suite
        if (!failures.isEmpty()) {
            throw new AssertionError(testSuite.getName() + " failed, total " + total + " failures: " + failures.size() + "\n" +
                    failures.keySet());
        }
    }

    private String getWorkingDirectory() {
        return this.computeTestDataRoot().getAbsolutePath();
    }
}
TOP

Related Classes of com.tinkerpop.blueprints.impls.neo4j2.Neo4j2GraphTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.