Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.KeyIndexableGraph


        }
        graph.shutdown();
    }

    public void testNoConcurrentModificationException() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        if (graph.getFeatures().supportsEdgeKeyIndex) {
            graph.createKeyIndex("key", Edge.class);
            for (int i = 0; i < 25; i++) {
                graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("test")).setProperty("key", "value");
            }
            if (graph.getFeatures().supportsVertexIteration) assertEquals(count(graph.getVertices()), 50);
            if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 25);
            int counter = 0;
            for (final Edge edge : graph.getEdges("key", "value")) {
                graph.removeEdge(edge);
                counter++;
            }
            assertEquals(counter, 25);
            if (graph.getFeatures().supportsVertexIteration) assertEquals(count(graph.getVertices()), 50);
            if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 0);

        }
        graph.shutdown();
    }
View Full Code Here


        }
        graph.shutdown();
    }

    public void testKeyIndicesConsistentWithElementRemoval() throws Exception {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();

        graph.createKeyIndex("foo", Vertex.class);

        Vertex v1 = graph.addVertex(null);
        v1.setProperty("foo", "42");
        vertexCount(graph, 1);

        graph.removeVertex(v1);
        vertexCount(graph, 0);
        assertEquals(0, count(graph.getVertices("foo", "42")));

        graph.shutdown();
    }
View Full Code Here

        graph.shutdown();
    }

    public void testUpdateValuesInIndexKeys() throws Exception {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();

        graph.createKeyIndex("name", Vertex.class);
        if (graph instanceof TransactionalGraph)
            ((TransactionalGraph) graph).commit();

        Vertex v1 = graph.addVertex(null);
        v1.setProperty("name", "marko");
        assertEquals(v1.getProperty("name"), "marko");
        vertexCount(graph, 1);
        if (graph instanceof TransactionalGraph)
            ((TransactionalGraph) graph).commit();

        v1 = graph.getVertices("name", "marko").iterator().next();
        assertEquals(v1.getProperty("name"), "marko");
        v1.setProperty("name", "marko a. rodriguez");
        assertEquals(v1.getProperty("name"), "marko a. rodriguez");
        vertexCount(graph, 1);
        if (graph instanceof TransactionalGraph)
            ((TransactionalGraph) graph).commit();


        assertFalse(graph.getVertices("name", "marko").iterator().hasNext());
        v1 = graph.getVertices("name", "marko a. rodriguez").iterator().next();
        assertEquals(v1.getProperty("name"), "marko a. rodriguez");
        vertexCount(graph, 1);
        if (graph instanceof TransactionalGraph)
            ((TransactionalGraph) graph).commit();

        graph.shutdown();
    }
View Full Code Here

        printPerformance(graph.toString(), null, "testSparkseeVertexLabel", this.stopWatch());
        graph.shutdown();
    }

    public void testKeyIndex() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        ((SparkseeGraph) graph).typeScope.set(true);
        this.stopWatch();

        ((SparkseeGraph) graph).label.set("people");
        graph.createKeyIndex("name", Vertex.class);

        ((SparkseeGraph) graph).label.set("thing");
        graph.createKeyIndex("name", Vertex.class);

        assertTrue(graph.getIndexedKeys(Edge.class).isEmpty());
        assertTrue(graph.getIndexedKeys(Vertex.class).size() == 1);
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));

        ((SparkseeGraph) graph).label.set("people");
        Vertex v1 = graph.addVertex(null);
        v1.setProperty("name", "foo");
        Vertex v2 = graph.addVertex(null);
        v2.setProperty("name", "boo");

        ((SparkseeGraph) graph).label.set("thing");
        Vertex v10 = graph.addVertex(null);
        v10.setProperty("name", "foo");
        Vertex v20 = graph.addVertex(null);
        v20.setProperty("name", "boo");

        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v1));
        ((SparkseeGraph) graph).label.set("thing");
        assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v10));

        ArrayList<Vertex> result = new ArrayList<Vertex>(Arrays.asList(v1, v10));
        ((SparkseeGraph) graph).label.set(null); // all types!
        for (Vertex current : graph.getVertices("name", "foo")) {
            assertTrue(result.contains(current));
            result.remove(current);
        }
        assertTrue(result.size() == 0);

        result = new ArrayList<Vertex>(Arrays.asList(v1, v2));
        for (Vertex current : graph.getVertices(StringFactory.LABEL, "people")) {
            assertTrue(result.contains(current));
            result.remove(current);
        }
        assertTrue(result.size() == 0);

        // table scan
        v1.setProperty("age", 99);
        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.getVertices("age", 99).iterator().next().equals(v1));

        printPerformance(graph.toString(), null, "testKeyIndex", this.stopWatch());
        graph.shutdown();
    }
View Full Code Here

            }
        }
    }

    protected void resetGraph() {
        final KeyIndexableGraph graph = (KeyIndexableGraph) this.generateGraph();
        final IndexableGraph idxGraph = (IndexableGraph) graph;

        // since we don't have graph.clear() anymore we manually reset the graph.
        Iterator<Vertex> vertexItty = graph.getVertices().iterator();
        List<Vertex> verticesToRemove = new ArrayList<Vertex>();
        while (vertexItty.hasNext()) {
            verticesToRemove.add(vertexItty.next());
        }

        for (Vertex vertexToRemove : verticesToRemove) {
            graph.removeVertex(vertexToRemove);
        }

        for (String key : graph.getIndexedKeys(Vertex.class)) {
            graph.dropKeyIndex(key, Vertex.class);
        }

        for (String key : graph.getIndexedKeys(Edge.class)) {
            graph.dropKeyIndex(key, Edge.class);
        }

        for (Index idx : idxGraph.getIndices()) {
            idxGraph.dropIndex(idx.getIndexName());
        }
View Full Code Here

    public SparkseeKeyIndexableGraphTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testGetIndexedKeysCannotAcceptNullArgumentForClass() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        try {
            graph.getIndexedKeys(null);
        } catch (IllegalArgumentException iae) {
            return;
        } finally {
            graph.shutdown();
        }

        fail();
    }
View Full Code Here

        fail();
    }

    public void testCreateKeyIndexCannotAcceptNullArgumentForClass() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        try {
            graph.createKeyIndex("test", null);
        } catch (IllegalArgumentException iae) {
            return;
        } finally {
            graph.shutdown();
        }

        fail();
    }
View Full Code Here

        fail();
    }

    public void testRemoveKeyIndexCannotAcceptNullArgumentForClass() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        try {
            graph.dropKeyIndex("test", null);
        } catch (IllegalArgumentException iae) {
            return;
        } finally {
            graph.shutdown();
        }

        fail();
    }
View Full Code Here

        fail();
    }

    public void testAutoIndexKeyManagementWithPersistence() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        if (graph.getFeatures().supportsVertexKeyIndex) {
            assertEquals(graph.getIndexedKeys(Vertex.class).size(), 0);
            this.stopWatch();
            graph.createKeyIndex("name", Vertex.class);
            graph.createKeyIndex("location", Vertex.class);
            printPerformance(graph.toString(), 2, "automatic index keys added", this.stopWatch());
            assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
            assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
            assertTrue(graph.getIndexedKeys(Vertex.class).contains("location"));
        }
        if (graph.getFeatures().supportsEdgeKeyIndex) {
            assertEquals(graph.getIndexedKeys(Edge.class).size(), 0);
            this.stopWatch();
            graph.createKeyIndex("weight", Edge.class);
            graph.createKeyIndex("since", Edge.class);
            printPerformance(graph.toString(), 2, "automatic index keys added", this.stopWatch());
            assertEquals(graph.getIndexedKeys(Edge.class).size(), 2);
            assertTrue(graph.getIndexedKeys(Edge.class).contains("weight"));
            assertTrue(graph.getIndexedKeys(Edge.class).contains("since"));
        }
        graph.shutdown();

        if (graph.getFeatures().isPersistent) {
            graph = (KeyIndexableGraph) graphTest.generateGraph();
            if (graph.getFeatures().supportsVertexKeyIndex) {
                assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
                assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
                assertTrue(graph.getIndexedKeys(Vertex.class).contains("location"));
            }
            if (graph.getFeatures().supportsEdgeKeyIndex) {
                assertEquals(graph.getIndexedKeys(Edge.class).size(), 2);
                assertTrue(graph.getIndexedKeys(Edge.class).contains("weight"));
                assertTrue(graph.getIndexedKeys(Edge.class).contains("since"));
            }
            graph.shutdown();
        }
    }
View Full Code Here

//        }
//        graph.shutdown();
//    }

    public void testGettingVerticesAndEdgesWithKeyValue() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        if (graph.getFeatures().supportsVertexIteration && graph.getFeatures().supportsVertexKeyIndex) {
            graph.createKeyIndex("name", Vertex.class);
            assertEquals(graph.getIndexedKeys(Vertex.class).size(), 1);
            assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
            Vertex v1 = graph.addVertex(null);
            v1.setProperty("name", "marko");
            v1.setProperty("location", "everywhere");
            Vertex v2 = graph.addVertex(null);
            v2.setProperty("name", "stephen");
            v2.setProperty("location", "everywhere");

            assertEquals(count(graph.getVertices("location", "everywhere")), 2);
            assertEquals(count(graph.getVertices("name", "marko")), 1);
            assertEquals(count(graph.getVertices("name", "stephen")), 1);
            assertEquals(graph.getVertices("name", "marko").iterator().next(), v1);
            assertEquals(graph.getVertices("name", "stephen").iterator().next(), v2);
        }

        if (graph.getFeatures().supportsEdgeIteration && graph.getFeatures().supportsEdgeKeyIndex) {
            graph.createKeyIndex("place", Edge.class);
            assertEquals(graph.getIndexedKeys(Edge.class).size(), 1);
            assertTrue(graph.getIndexedKeys(Edge.class).contains("place"));

            Edge e1 = graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("knows"));
            e1.setProperty("name", "marko");
            e1.setProperty("place", "everywhere");
            Edge e2 = graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("knows"));
            e2.setProperty("name", "stephen");
            e2.setProperty("place", "everywhere");

            assertEquals(count(graph.getEdges("place", "everywhere")), 2);
            assertEquals(count(graph.getEdges("name", "marko")), 1);
            assertEquals(count(graph.getEdges("name", "stephen")), 1);
            assertEquals(graph.getEdges("name", "marko").iterator().next(), e1);
            assertEquals(graph.getEdges("name", "stephen").iterator().next(), e2);
        }
        graph.shutdown();
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.KeyIndexableGraph

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.