Search in sources :

Example 16 with KeyIndexableGraph

use of com.tinkerpop.blueprints.KeyIndexableGraph in project blueprints by tinkerpop.

the class SparkseeKeyIndexableGraphTestSuite method testNoConcurrentModificationException.

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();
}
Also used : KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 17 with KeyIndexableGraph

use of com.tinkerpop.blueprints.KeyIndexableGraph in project blueprints by tinkerpop.

the class SparkseeGraphSpecificTestSuite method testKeyIndex.

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));
    // all types!
    ((SparkseeGraph) graph).label.set(null);
    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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) ArrayList(java.util.ArrayList)

Example 18 with KeyIndexableGraph

use of com.tinkerpop.blueprints.KeyIndexableGraph in project blueprints by tinkerpop.

the class RexsterGraphTest method resetGraph.

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());
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) ArrayList(java.util.ArrayList) Index(com.tinkerpop.blueprints.Index)

Aggregations

KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)18 Vertex (com.tinkerpop.blueprints.Vertex)6 Edge (com.tinkerpop.blueprints.Edge)3 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)3 IdGraph (com.tinkerpop.blueprints.util.wrappers.id.IdGraph)3 Test (org.junit.Test)3 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)2 ArrayList (java.util.ArrayList)2 Graph (com.tinkerpop.blueprints.Graph)1 Index (com.tinkerpop.blueprints.Index)1 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)1 WrapperGraph (com.tinkerpop.blueprints.util.wrappers.WrapperGraph)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Sail (org.openrdf.sail.Sail)1 SailConnection (org.openrdf.sail.SailConnection)1 BaseSynchronizedGraph (org.pentaho.metaverse.api.model.BaseSynchronizedGraph)1