Search in sources :

Example 1 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    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) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) HashSet(java.util.HashSet)

Example 2 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest 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 3 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testTransactionSeriesOrder.

public void testTransactionSeriesOrder() {
    graph.addListener(graphChangedListener);
    graph.addListener(new ConsoleGraphChangedListener(graph));
    Vertex v1 = graph.addVertex(10);
    v1.setProperty("aaa", "bbb");
    v1.setProperty("ccc", "ddd");
    v1.removeProperty("aaa");
    Vertex v2 = graph.addVertex(20);
    Vertex v3 = graph.addVertex(30);
    Edge e1 = graph.addEdge(100, v1, v2, "friend");
    e1.setProperty("eee", "fff");
    e1.setProperty("ggg", "hhh");
    e1.setProperty("ggg", "hhhh");
    e1.removeProperty("eee");
    Edge e2 = graph.addEdge(101, v1, v2, "enemy");
    graph.removeEdge(e2);
    graph.removeVertex(v3);
    assertEquals(0, graphChangedListener.getOrder().size());
    ((EventTransactionalGraph) graph).commit();
    List<String> order = graphChangedListener.getOrder();
    assertEquals("v-added-10", order.get(0));
    assertEquals("v-property-changed-10-aaa:null->bbb", order.get(1));
    assertEquals("v-property-changed-10-ccc:null->ddd", order.get(2));
    assertEquals("v-property-removed-10-aaa:bbb", order.get(3));
    assertEquals("v-added-20", order.get(4));
    assertEquals("v-added-30", order.get(5));
    assertEquals("e-added-100", order.get(6));
    assertEquals("e-property-changed-100-eee:null->fff", order.get(7));
    assertEquals("e-property-changed-100-ggg:null->hhh", order.get(8));
    assertEquals("e-property-changed-100-ggg:hhh->hhhh", order.get(9));
    assertEquals("e-property-removed-100-eee:fff", order.get(10));
    assertEquals("e-added-101", order.get(11));
    assertEquals("e-removed-101", order.get(12));
    assertEquals("v-removed-30", order.get(13));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) Edge(com.tinkerpop.blueprints.Edge)

Example 4 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testEventedGraph.

public void testEventedGraph() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    assertTrue(graph.getVertices() instanceof EventVertexIterable);
    assertTrue(graph.getEdges() instanceof EventEdgeIterable);
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    graph.removeVertex(graph.getVertex(1));
    assertNull(graph.getVertex(1));
    graph.removeEdge(graph.getEdge(10));
    assertNull(graph.getEdge(10));
    graph.shutdown();
}
Also used : ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Example 5 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener 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)

Aggregations

ConsoleGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)9 Vertex (com.tinkerpop.blueprints.Vertex)5 Edge (com.tinkerpop.blueprints.Edge)3 GraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener)2 StubGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener)2 HashSet (java.util.HashSet)2