Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Graph


    public void doTestSuite(final TestSuite testSuite) throws Exception {
        for (Method method : testSuite.getClass().getDeclaredMethods()) {
            if (method.getName().startsWith("test")) {
                System.out.println("Testing " + method.getName() + "...");
                Graph graph = this.generateGraph();
                method.invoke(testSuite);
                graph.shutdown();
            }
        }
    }
View Full Code Here


    }

    public void testEncoding() throws Exception {
        final String doTest = System.getProperty("testRexsterGraph", "true");
        if (doTest.equals("true")) {
            final Graph g = graphTest.generateGraph();
            ((RexsterGraphTest) graphTest).resetGraph();

            final Vertex v = g.addVertex(null);
            v.setProperty("test", "déja-vu");

            Assert.assertEquals("déja-vu", g.getVertex(v.getId()).getProperty("test"));
        }
    }
View Full Code Here

    }

    public void testOuterParens() throws Exception {
        final String doTest = System.getProperty("testRexsterGraph", "true");
        if (doTest.equals("true")) {
            final Graph g = graphTest.generateGraph();
            ((RexsterGraphTest) graphTest).resetGraph();

            final Vertex v = g.addVertex(null);
            v.setProperty("test", "(sometext)");

            Assert.assertEquals("(sometext)", g.getVertex(v.getId()).getProperty("test"));
        }
    }
View Full Code Here

        super(graphTest);
    }

    public void testNeo4jRaw() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            GraphDatabaseService neo4j = ((Neo4j2Graph) graph).getRawGraph();
            int counter = 0;
            this.stopWatch();
            for (final Node node : neo4j.getAllNodes()) {
                counter++;
                for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
                    counter++;
                    final Node node2 = relationship.getEndNode();
                    counter++;
                    for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
                        counter++;
                        final Node node3 = relationship2.getEndNode();
                        counter++;
                        for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
                            counter++;
                            relationship3.getEndNode();
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }

    public void testNeo4jGraph() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            this.stopWatch();
            int counter = 0;
            for (final Vertex vertex : graph.getVertices()) {
                counter++;
                for (final Edge edge : vertex.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                    counter++;
                    final Vertex vertex2 = edge.getVertex(com.tinkerpop.blueprints.Direction.IN);
                    counter++;
                    for (final Edge edge2 : vertex2.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                        counter++;
                        final Vertex vertex3 = edge2.getVertex(com.tinkerpop.blueprints.Direction.IN);
                        counter++;
                        for (final Edge edge3 : vertex3.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                            counter++;
                            edge3.getVertex(com.tinkerpop.blueprints.Direction.OUT);
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(graph.toString(), counter, "Neo4j2Graph elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4j2Graph", 1, "Neo4j2Graph experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

        super(graphTest);
    }

    public void testNeo4jRaw() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            GraphDatabaseService neo4j = ((Neo4jGraph) graph).getRawGraph();
            int counter = 0;
            this.stopWatch();
            for (final Node node : neo4j.getAllNodes()) {
                counter++;
                for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
                    counter++;
                    final Node node2 = relationship.getEndNode();
                    counter++;
                    for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
                        counter++;
                        final Node node3 = relationship2.getEndNode();
                        counter++;
                        for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
                            counter++;
                            relationship3.getEndNode();
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }

    public void testNeo4jGraph() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            this.stopWatch();
            int counter = 0;
            for (final Vertex vertex : graph.getVertices()) {
                counter++;
                for (final Edge edge : vertex.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                    counter++;
                    final Vertex vertex2 = edge.getVertex(com.tinkerpop.blueprints.Direction.IN);
                    counter++;
                    for (final Edge edge2 : vertex2.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                        counter++;
                        final Vertex vertex3 = edge2.getVertex(com.tinkerpop.blueprints.Direction.IN);
                        counter++;
                        for (final Edge edge3 : vertex3.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                            counter++;
                            edge3.getVertex(com.tinkerpop.blueprints.Direction.OUT);
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(graph.toString(), counter, "Neo4jGraph elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jGraph", 1, "Neo4jGraph experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

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

    public void testAddVertex() {
        Graph graph = new TinkerGraph();
        Vertex vertex = GraphHelper.addVertex(graph, null, "name", "marko", "age", 31);
        assertEquals(vertex.getProperty("name"), "marko");
        assertEquals(vertex.getProperty("age"), 31);
        assertEquals(vertex.getPropertyKeys().size(), 2);
        assertEquals(count(graph.getVertices()), 1);

        try {
            vertex = GraphHelper.addVertex(graph, null, "name", "marko", "age");
            assertTrue(false);
        } catch (Exception e) {
            assertFalse(false);
            assertEquals(count(graph.getVertices()), 1);
        }
    }
View Full Code Here

            assertEquals(count(graph.getVertices()), 1);
        }
    }

    public void testAddEdge() {
        Graph graph = new TinkerGraph();
        Edge edge = GraphHelper.addEdge(graph, null, graph.addVertex(null), graph.addVertex(null), "knows", "weight", 10.0f);
        assertEquals(edge.getProperty("weight"), 10.0f);
        assertEquals(edge.getLabel(), "knows");
        assertEquals(edge.getPropertyKeys().size(), 1);
        assertEquals(count(graph.getVertices()), 2);
        assertEquals(count(graph.getEdges()), 1);

        try {
            edge = GraphHelper.addEdge(graph, null, graph.addVertex(null), graph.addVertex(null), "knows", "weight");
            assertTrue(false);
        } catch (Exception e) {
            assertFalse(false);
            assertEquals(count(graph.getVertices()), 4);
            assertEquals(count(graph.getEdges()), 1);
        }
    }
View Full Code Here

            assertEquals(count(graph.getEdges()), 1);
        }
    }

    public void testCopyGraph() {
        Graph g = TinkerGraphFactory.createTinkerGraph();
        Graph h = new TinkerGraph();

        GraphHelper.copyGraph(g, h);
        assertEquals(count(h.getVertices()), 6);
        assertEquals(count(h.getEdges()), 6);
        assertEquals(count(h.getVertex("1").getEdges(Direction.OUT)), 3);
        assertEquals(count(h.getVertex("1").getEdges(Direction.IN)), 0);
        Vertex marko = h.getVertex("1");
        assertEquals(marko.getProperty("name"), "marko");
        assertEquals(marko.getProperty("age"), 29);
        int counter = 0;
        for (Edge e : h.getVertex("1").getEdges(Direction.OUT)) {
            if (e.getVertex(Direction.IN).getId().equals("2")) {
                assertEquals(e.getProperty("weight"), 0.5f);
                assertEquals(e.getLabel(), "knows");
                assertEquals(e.getId(), "7");
                counter++;
            } else if (e.getVertex(Direction.IN).getId().equals("3")) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                assertEquals(e.getLabel(), "created");
                assertEquals(e.getId(), "9");
                counter++;
            } else if (e.getVertex(Direction.IN).getId().equals("4")) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                assertEquals(e.getLabel(), "knows");
                assertEquals(e.getId(), "8");
                counter++;
            }
        }

        assertEquals(count(h.getVertex("4").getEdges(Direction.OUT)), 2);
        assertEquals(count(h.getVertex("4").getEdges(Direction.IN)), 1);
        Vertex josh = h.getVertex("4");
        assertEquals(josh.getProperty("name"), "josh");
        assertEquals(josh.getProperty("age"), 32);
        for (Edge e : h.getVertex("4").getEdges(Direction.OUT)) {
            if (e.getVertex(Direction.IN).getId().equals("3")) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                assertEquals(e.getLabel(), "created");
                assertEquals(e.getId(), "11");
                counter++;
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Graph

Copyright © 2018 www.massapicom. 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.