Search in sources :

Example 71 with Vertex

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

the class PartitionGraphTest method testSpecificBehavior.

public void testSpecificBehavior() {
    TinkerGraph rawGraph = new TinkerGraph();
    PartitionIndexableGraph graph = new PartitionIndexableGraph(rawGraph, "_writeGraph", "a");
    assertEquals(graph.getReadPartitions().size(), 1);
    assertTrue(graph.getReadPartitions().contains("a"));
    assertEquals(graph.getWritePartition(), "a");
    Vertex marko = graph.addVertex(null);
    Vertex rawMarko = ((PartitionVertex) marko).getBaseVertex();
    assertEquals(marko.getPropertyKeys().size(), 0);
    assertEquals(rawMarko.getPropertyKeys().size(), 1);
    assertNull(marko.getProperty("_writeGraph"));
    assertEquals(rawMarko.getProperty("_writeGraph"), "a");
    assertEquals(((PartitionVertex) marko).getPartition(), "a");
    assertEquals(count(graph.getVertices()), 1);
    assertEquals(graph.getVertices().iterator().next(), marko);
    assertEquals(count(graph.getEdges()), 0);
    graph.setWritePartition("b");
    assertEquals(graph.getReadPartitions().size(), 1);
    assertTrue(graph.getReadPartitions().contains("a"));
    assertEquals(graph.getWritePartition(), "b");
    Vertex peter = graph.addVertex(null);
    Vertex rawPeter = ((PartitionVertex) peter).getBaseVertex();
    assertEquals(peter.getPropertyKeys().size(), 0);
    assertEquals(rawPeter.getPropertyKeys().size(), 1);
    assertNull(peter.getProperty("_writeGraph"));
    assertEquals(rawPeter.getProperty("_writeGraph"), "b");
    assertEquals(((PartitionVertex) peter).getPartition(), "b");
    assertEquals(count(graph.getVertices()), 1);
    assertEquals(graph.getVertices().iterator().next(), marko);
    assertEquals(count(graph.getEdges()), 0);
    graph.removeReadPartition("a");
    assertEquals(graph.getReadPartitions().size(), 0);
    assertEquals(graph.getWritePartition(), "b");
    assertEquals(count(graph.getVertices()), 0);
    assertEquals(count(graph.getEdges()), 0);
    graph.addReadPartition("b");
    assertEquals(graph.getReadPartitions().size(), 1);
    assertTrue(graph.getReadPartitions().contains("b"));
    assertEquals(graph.getWritePartition(), "b");
    assertEquals(count(graph.getVertices()), 1);
    assertEquals(graph.getVertices().iterator().next(), peter);
    assertEquals(count(graph.getEdges()), 0);
    graph.addReadPartition("a");
    assertEquals(graph.getReadPartitions().size(), 2);
    assertTrue(graph.getReadPartitions().contains("a"));
    assertTrue(graph.getReadPartitions().contains("b"));
    assertEquals(graph.getWritePartition(), "b");
    assertEquals(count(graph.getVertices()), 2);
    assertEquals(count(graph.getEdges()), 0);
    graph.setWritePartition("c");
    assertEquals(graph.getReadPartitions().size(), 2);
    assertTrue(graph.getReadPartitions().contains("a"));
    assertTrue(graph.getReadPartitions().contains("b"));
    assertEquals(graph.getWritePartition(), "c");
    Edge knows = graph.addEdge(null, marko, peter, "knows");
    Edge rawKnows = ((PartitionEdge) knows).getBaseEdge();
    assertEquals(count(graph.getVertices()), 2);
    assertEquals(count(graph.getEdges()), 0);
    graph.addReadPartition("c");
    assertEquals(count(graph.getVertices()), 2);
    assertEquals(count(graph.getEdges()), 1);
    assertEquals(knows.getPropertyKeys().size(), 0);
    assertEquals(rawKnows.getPropertyKeys().size(), 1);
    assertNull(knows.getProperty("_writeGraph"));
    assertEquals(rawKnows.getProperty("_writeGraph"), "c");
    assertEquals(((PartitionEdge) knows).getPartition(), "c");
    assertEquals(graph.getEdges().iterator().next(), knows);
    graph.removeReadPartition("a");
    graph.removeReadPartition("b");
    assertEquals(graph.getReadPartitions().size(), 1);
    assertTrue(graph.getReadPartitions().contains("c"));
    assertEquals(graph.getWritePartition(), "c");
    assertEquals(count(graph.getVertices()), 0);
    assertEquals(count(graph.getEdges()), 1);
    assertNull(knows.getVertex(Direction.IN));
    assertNull(knows.getVertex(Direction.OUT));
    // testing indices
    /*marko.setProperty("name", "marko");
        peter.setProperty("name", "peter");
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 0);
        graph.addReadPartition("a");
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 1);
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 0);
        assertEquals(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko").next(), marko);
        graph.removeReadPartition("a");
        graph.addReadPartition("b");
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 1);
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 0);
        assertEquals(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter").next(), peter);
        graph.addReadPartition("a");
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 1);
        assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 1);

        assertEquals(count(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows")), 1);
        assertEquals(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows").next(), knows);
        graph.removeReadPartition("c");
        assertEquals(count(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows")), 0);
        */
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 72 with Vertex

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

the class PartitionGraphTest method testVerticesSeparatedByEdgeInDifferentPartition.

public void testVerticesSeparatedByEdgeInDifferentPartition() {
    TinkerGraph rawGraph = new TinkerGraph();
    PartitionIndexableGraph graph = new PartitionIndexableGraph(rawGraph, "_writeGraph", "p1");
    Vertex inp1 = graph.addVertex("inp1");
    graph.setWritePartition("p2");
    Vertex inp2 = graph.addVertex("inp2");
    inp2.setProperty("key", "value");
    graph.setWritePartition("p3");
    graph.addEdge("inp3", inp1, inp2, "links");
    assertNull(graph.getVertex("inp2"));
    graph.addReadPartition("p2");
    graph.addReadPartition("p3");
    assertNotNull(graph.getVertex("inp1"));
    assertNotNull(graph.getVertex("inp2"));
    assertTrue(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().hasNext());
    graph.removeReadPartition("p2");
    assertTrue(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().hasNext());
    // the vertex at the end of this traversal is in the p2 partition which was removed above.  it should return
    // null, throw exception, something....
    assertNull(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().next().getVertex(Direction.IN));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Example 73 with Vertex

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

the class ReadOnlyGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    assertEquals(graph.getVertex(1), graph.getVertex(1));
    Set<Vertex> set = new HashSet<Vertex>();
    set.add(graph.getVertex(2));
    set.add(graph.getVertex(2));
    assertEquals(set.size(), 1);
    assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
    assertEquals(graph.getEdge(8), graph.getEdge(8));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Graph(com.tinkerpop.blueprints.Graph) HashSet(java.util.HashSet)

Example 74 with Vertex

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

the class GraphSONUtilityTest method jsonFromElementVertexListPropertyNoKeysNoTypes.

@Test
public void jsonFromElementVertexListPropertyNoKeysNoTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    List<Object> list = new ArrayList<Object>();
    list.add("this");
    list.add("that");
    list.add("other");
    list.add(true);
    v.setProperty("keyList", list);
    JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
    Assert.assertNotNull(json);
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
    Assert.assertTrue(json.has("keyList"));
    JSONArray listAsJSON = json.optJSONArray("keyList");
    Assert.assertNotNull(listAsJSON);
    Assert.assertEquals(4, listAsJSON.length());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 75 with Vertex

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

the class GraphSONUtilityTest method jsonFromElementVertexCatArrayPropertyNoKeysNoTypes.

@Test
public void jsonFromElementVertexCatArrayPropertyNoKeysNoTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    List<Cat> cats = new ArrayList<Cat>();
    cats.add(new Cat("smithers"));
    cats.add(new Cat("mcallister"));
    v.setProperty("cats", cats);
    JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
    Assert.assertNotNull(json);
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
    Assert.assertTrue(json.has("cats"));
    JSONArray catListAsJson = json.optJSONArray("cats");
    Assert.assertNotNull(catListAsJson);
    Assert.assertEquals(2, catListAsJson.length());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11