Package com.tinkerpop.gremlin

Examples of com.tinkerpop.gremlin.GraphProvider


     */
    @Test
    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
    public void shouldEvaluateConnectivityPatterns() {
        final GraphProvider graphProvider = GraphManager.get();
        final Graph graph = this.g;

        final Vertex a;
        final Vertex b;
        final Vertex c;
        final Vertex d;
        if (graph.features().vertex().supportsUserSuppliedIds()) {
            a = graph.addVertex(T.id, graphProvider.convertId("1"));
            b = graph.addVertex(T.id, graphProvider.convertId("2"));
            c = graph.addVertex(T.id, graphProvider.convertId("3"));
            d = graph.addVertex(T.id, graphProvider.convertId("4"));
        } else {
            a = graph.addVertex();
            b = graph.addVertex();
            c = graph.addVertex();
            d = graph.addVertex();
        }

        tryCommit(graph, assertVertexEdgeCounts(4, 0));

        final Edge e = a.addEdge(graphProvider.convertLabel("knows"), b);
        final Edge f = b.addEdge(graphProvider.convertLabel("knows"), c);
        final Edge g = c.addEdge(graphProvider.convertLabel("knows"), d);
        final Edge h = d.addEdge(graphProvider.convertLabel("knows"), a);

        tryCommit(graph, assertVertexEdgeCounts(4, 4));

        for (Vertex v : graph.V().toList()) {
            assertEquals(new Long(1), v.outE().count().next());
            assertEquals(new Long(1), v.inE().count().next());
        }

        for (Edge x : graph.E().toList()) {
            assertEquals(graphProvider.convertLabel("knows"), x.label());
        }

        if (graph.features().vertex().supportsUserSuppliedIds()) {
            final Vertex va = graph.v(graphProvider.convertId("1"));
            final Vertex vb = graph.v(graphProvider.convertId("2"));
            final Vertex vc = graph.v(graphProvider.convertId("3"));
            final Vertex vd = graph.v(graphProvider.convertId("4"));

            assertEquals(a, va);
            assertEquals(b, vb);
            assertEquals(c, vc);
            assertEquals(d, vd);

            assertEquals(new Long(1), va.inE().count().next());
            assertEquals(new Long(1), va.outE().count().next());
            assertEquals(new Long(1), vb.inE().count().next());
            assertEquals(new Long(1), vb.outE().count().next());
            assertEquals(new Long(1), vc.inE().count().next());
            assertEquals(new Long(1), vc.outE().count().next());
            assertEquals(new Long(1), vd.inE().count().next());
            assertEquals(new Long(1), vd.outE().count().next());

            final Edge i = a.addEdge(graphProvider.convertLabel("hates"), b);

            assertEquals(new Long(1), va.inE().count().next());
            assertEquals(new Long(2), va.outE().count().next());
            assertEquals(new Long(2), vb.inE().count().next());
            assertEquals(new Long(1), vb.outE().count().next());
            assertEquals(new Long(1), vc.inE().count().next());
            assertEquals(new Long(1), vc.outE().count().next());
            assertEquals(new Long(1), vd.inE().count().next());
            assertEquals(new Long(1), vd.outE().count().next());

            for (Edge x : a.outE().toList()) {
                assertTrue(x.label().equals(graphProvider.convertId("knows")) || x.label().equals(graphProvider.convertId("hates")));
            }

            assertEquals(graphProvider.convertId("hates"), i.label());
            assertEquals(graphProvider.convertId("2"), i.inV().id().next().toString());
            assertEquals(graphProvider.convertId("1"), i.outV().id().next().toString());
        }

        final Set<Object> vertexIds = new HashSet<>();
        vertexIds.add(a.id());
        vertexIds.add(a.id());
View Full Code Here


    @Test
    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
    public void shouldTraverseInOutFromVertexWithSingleEdgeLabelFilter() {
        final GraphProvider graphProvider = GraphManager.get();
        final Graph graph = g;

        final Vertex a = graph.addVertex();
        final Vertex b = graph.addVertex();
        final Vertex c = graph.addVertex();

        final String labelFriend = graphProvider.convertLabel("friend");
        final String labelHate = graphProvider.convertLabel("hate");

        final Edge aFriendB = a.addEdge(labelFriend, b);
        final Edge aFriendC = a.addEdge(labelFriend, c);
        final Edge aHateC = a.addEdge(labelHate, c);
        final Edge cHateA = c.addEdge(labelHate, a);
View Full Code Here

    @Test
    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
    public void shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter() {
        final GraphProvider graphProvider = GraphManager.get();
        final Graph graph = g;
        final Vertex a = graph.addVertex();
        final Vertex b = graph.addVertex();
        final Vertex c = graph.addVertex();

        final String labelFriend = graphProvider.convertLabel("friend");
        final String labelHate = graphProvider.convertLabel("hate");

        final Edge aFriendB = a.addEdge(labelFriend, b);
        final Edge aFriendC = a.addEdge(labelFriend, c);
        final Edge aHateC = a.addEdge(labelHate, c);
        final Edge cHateA = c.addEdge(labelHate, a);
        final Edge cHateB = c.addEdge(labelHate, b);

        List<Edge> results = a.outE(labelFriend, labelHate).toList();
        assertEquals(3, results.size());
        assertTrue(results.contains(aFriendB));
        assertTrue(results.contains(aFriendC));
        assertTrue(results.contains(aHateC));

        results = a.inE(labelFriend, labelHate).toList();
        assertEquals(1, results.size());
        assertTrue(results.contains(cHateA));

        results = b.inE(labelFriend, labelHate).toList();
        assertEquals(2, results.size());
        assertTrue(results.contains(aFriendB));
        assertTrue(results.contains(cHateB));

        results = b.inE(graphProvider.convertLabel("blah1"), graphProvider.convertLabel("blah2")).toList();
        assertEquals(0, results.size());
    }
View Full Code Here

    @Test
    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
    public void shouldTestTreeConnectivity() {
        final GraphProvider graphProvider = GraphManager.get();
        final Graph graph = g;

        int branchSize = 11;
        final Vertex start = graph.addVertex();
        for (int i = 0; i < branchSize; i++) {
            final Vertex a = graph.addVertex();
            start.addEdge(graphProvider.convertLabel("test1"), a);
            for (int j = 0; j < branchSize; j++) {
                final Vertex b = graph.addVertex();
                a.addEdge(graphProvider.convertLabel("test2"), b);
                for (int k = 0; k < branchSize; k++) {
                    final Vertex c = graph.addVertex();
                    b.addEdge(graphProvider.convertLabel("test3"), c);
                }
            }
        }

        assertEquals(new Long(0), start.inE().count().next());
        assertEquals(new Long(branchSize), start.outE().count().next());
        for (Edge e : start.outE().toList()) {
            assertEquals(graphProvider.convertId("test1"), e.label());
            assertEquals(new Long(branchSize), e.inV().out().count().next());
            assertEquals(new Long(1), e.inV().inE().count().next());
            for (Edge f : e.inV().outE().toList()) {
                assertEquals(graphProvider.convertId("test2"), f.label());
                assertEquals(new Long(branchSize), f.inV().out().count().next());
                assertEquals(new Long(1), f.inV().in().count().next());
                for (Edge g : f.inV().outE().toList()) {
                    assertEquals(graphProvider.convertId("test3"), g.label());
                    assertEquals(new Long(0), g.inV().out().count().next());
                    assertEquals(new Long(1), g.inV().in().count().next());
                }
            }
        }
View Full Code Here

    @Test
    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
    @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_PERSISTENCE)
    public void shouldPersistDataOnClose() throws Exception {
        final GraphProvider graphProvider = GraphManager.get();
        final Graph graph = g;

        final Vertex v = graph.addVertex();
        final Vertex u = graph.addVertex();
        if (graph.features().edge().properties().supportsStringValues()) {
            v.property("name", "marko");
            u.property("name", "pavel");
        }

        final Edge e = v.addEdge(graphProvider.convertLabel("collaborator"), u);
        if (graph.features().edge().properties().supportsStringValues())
            e.property("location", "internet");

        tryCommit(graph, assertVertexEdgeCounts(2, 1));
        graph.close();

        final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), name.getMethodName());
        assertVertexEdgeCounts(2, 1).accept(reopenedGraph);

        if (graph.features().vertex().properties().supportsStringValues()) {
            for (Vertex vertex : reopenedGraph.V().toList()) {
                assertTrue(vertex.property("name").value().equals("marko") || vertex.property("name").value().equals("pavel"));
            }
        }

        for (Edge edge : reopenedGraph.E().toList()) {
            assertEquals(graphProvider.convertId("collaborator"), edge.label());
            if (graph.features().edge().properties().supportsStringValues())
                assertEquals("internet", edge.property("location").value());
        }

        graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName()));
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.gremlin.GraphProvider

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.