Search in sources :

Example 66 with Edge

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

the class EventGraphTest method testEventedElement.

public void testEventedElement() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    for (Vertex vertex : graph.getVertices()) {
        assertTrue(vertex instanceof EventVertex);
        vertex.setProperty("name", "noname");
        assertEquals("noname", vertex.getProperty("name"));
        assertTrue(vertex.getEdges(Direction.OUT) instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN) instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.OUT, "knows") instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN, "created") instanceof EventEdgeIterable);
    }
    for (Edge edge : graph.getEdges()) {
        assertTrue(edge instanceof EventEdge);
        edge.removeProperty("weight");
        assertNull(edge.getProperty("weight"));
        assertTrue(edge.getVertex(Direction.OUT) instanceof EventVertex);
        assertTrue(edge.getVertex(Direction.IN) instanceof EventVertex);
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) Edge(com.tinkerpop.blueprints.Edge)

Example 67 with Edge

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

the class EventGraphTest method testFireEdgePropertyRemoved.

public void testFireEdgePropertyRemoved() {
    graph.addListener(graphChangedListener);
    Edge edge = createEdge();
    edge.setProperty("weight", System.currentTimeMillis());
    edge.removeProperty("weight");
    assertEquals(1, graphChangedListener.edgePropertyRemovedEventRecorded());
}
Also used : Edge(com.tinkerpop.blueprints.Edge)

Example 68 with Edge

use of com.tinkerpop.blueprints.Edge 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 69 with Edge

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

the class EdgeHelperTest method testRelabelEdges.

public void testRelabelEdges() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    EdgeHelper.relabelEdges(graph, Arrays.asList(graph.getEdge(7)), "use_to_know");
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    int counter = 0;
    int counter2 = 0;
    Edge temp = null;
    for (Edge edge : graph.getVertex(1).getEdges(Direction.OUT)) {
        if (edge.getLabel().equals("use_to_know")) {
            counter++;
            assertEquals(edge.getProperty("weight"), 0.5f);
            temp = edge;
        }
        counter2++;
    }
    assertEquals(counter, 1);
    assertEquals(counter2, 3);
    counter = 0;
    counter2 = 0;
    for (Edge edge : graph.getVertex(2).getEdges(Direction.IN)) {
        if (edge.getLabel().equals("use_to_know")) {
            counter++;
            assertEquals(edge.getProperty("weight"), 0.5f);
            assertEquals(edge, temp);
        }
        counter2++;
    }
    assertEquals(counter, 1);
    assertEquals(counter2, 1);
}
Also used : Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 70 with Edge

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

the class GraphHelperTest method testCopyGraph.

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++;
        } else if (e.getVertex(Direction.IN).getId().equals("5")) {
            assertEquals(Math.round((Float) e.getProperty("weight")), 1);
            assertEquals(e.getLabel(), "created");
            assertEquals(e.getId(), "10");
            counter++;
        }
    }
    assertEquals(counter, 5);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6