Search in sources :

Example 1 with EventStrategy

use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.

the class TestDropStep method shouldReferenceVertexWhenRemoved.

@Test
public void shouldReferenceVertexWhenRemoved() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final Vertex v = this.sqlgGraph.addVertex();
    final String label = v.label();
    final Object id = v.id();
    final MutationListener listener = new AbstractMutationListener() {

        @Override
        public void vertexRemoved(final Vertex element) {
            Assert.assertThat(element, IsInstanceOf.instanceOf(ReferenceVertex.class));
            Assert.assertEquals(id, element.id());
            Assert.assertEquals(label, element.label());
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(ReferenceFactory.class);
    if (this.sqlgGraph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));
    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = this.sqlgGraph.traversal().withStrategies(eventStrategy);
    gts.V(v).drop().iterate();
    this.sqlgGraph.tx().commit();
    AbstractGremlinTest.assertVertexEdgeCounts(this.sqlgGraph, 0, 0);
    Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReferenceVertex(org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex) MutationListener(org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener) ReferenceVertex(org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex) EventStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test) AbstractGremlinTest(org.apache.tinkerpop.gremlin.AbstractGremlinTest)

Example 2 with EventStrategy

use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.

the class TestDropStep method before.

@Before
public void before() throws Exception {
    super.before();
    configuration.setProperty("implement.foreign.keys", this.fkOn);
    this.removedVertices.clear();
    if (this.mutatingCallback) {
        // Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
        final MutationListener listener = new AbstractMutationListener() {

            @Override
            public void vertexRemoved(final Vertex vertex) {
                removedVertices.add(vertex);
            }

            @Override
            public void edgeRemoved(final Edge edge) {
                removedEdges.add(edge);
            }
        };
        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
        eventStrategy = builder.create();
        this.dropTraversal = this.sqlgGraph.traversal();
        if (this.mutatingCallback) {
            this.dropTraversal = this.dropTraversal.withStrategies(this.eventStrategy);
        }
    } else {
        this.dropTraversal = this.sqlgGraph.traversal();
    }
}
Also used : ReferenceVertex(org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex) MutationListener(org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener) EventStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy) Before(org.junit.Before)

Example 3 with EventStrategy

use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.

the class TestDropStepBarrier method dropProperty.

@Test
public void dropProperty() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final MutationListener listener = new AbstractMutationListener() {

        @Override
        public void vertexPropertyRemoved(final VertexProperty element) {
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
    final EventStrategy eventStrategy = builder.create();
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties().drop().iterate();
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(triggered.get());
    Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutationListener(org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener) EventStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 4 with EventStrategy

use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.

the class TestDropStepBarrier method before.

@Before
public void before() throws Exception {
    super.before();
    configuration.setProperty("implement.foreign.keys", this.fkOn);
    configuration.setProperty("implement.foreign.keys", this.fkOn);
    this.removedVertices.clear();
    if (this.mutatingCallback) {
        // Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
        final MutationListener listener = new AbstractMutationListener() {

            @Override
            public void vertexRemoved(final Vertex vertex) {
                removedVertices.add(vertex);
            }

            @Override
            public void edgeRemoved(final Edge edge) {
                removedEdges.add(edge);
            }

            @Override
            public void edgePropertyRemoved(final Edge element, final Property property) {
                removedEdgeProperties.add(property);
            }

            @Override
            public void vertexPropertyRemoved(final VertexProperty property) {
                removedVertexProperties.add(property);
            }
        };
        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
        eventStrategy = builder.create();
        this.dropTraversal = this.sqlgGraph.traversal();
        if (this.mutatingCallback) {
            this.dropTraversal = this.dropTraversal.withStrategies(this.eventStrategy);
        }
    } else {
        this.dropTraversal = this.sqlgGraph.traversal();
    }
}
Also used : MutationListener(org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener) EventStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy) Before(org.junit.Before)

Example 5 with EventStrategy

use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.

the class TestTinkerPopEvent method shouldDetachVertexPropertyWhenRemoved.

@Test
public void shouldDetachVertexPropertyWhenRemoved() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final Vertex v = this.sqlgGraph.addVertex();
    final VertexProperty vp = v.property("to-remove", "blah");
    final String label = vp.label();
    final Object value = vp.value();
    final VertexProperty vpToKeep = v.property("to-keep", "dah");
    final MutationListener listener = new AbstractMutationListener() {

        @Override
        public void vertexPropertyRemoved(final VertexProperty element) {
            Assert.assertEquals(label, element.label());
            Assert.assertEquals(value, element.value());
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
    if (this.sqlgGraph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));
    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = create(eventStrategy);
    gts.V(v).properties("to-remove").drop().iterate();
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(1, IteratorUtils.count(v.properties()));
    Assert.assertEquals(vpToKeep.value(), v.value("to-keep"));
    Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutationListener(org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener) EventStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

EventStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy)7 MutationListener (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Before (org.junit.Before)3 Test (org.junit.Test)3 BaseTest (org.umlg.sqlg.test.BaseTest)3 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 ReferenceVertex (org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex)2 Preconditions (com.google.common.base.Preconditions)1 java.util (java.util)1 MultiValuedMap (org.apache.commons.collections4.MultiValuedMap)1 HashSetValuedHashMap (org.apache.commons.collections4.multimap.HashSetValuedHashMap)1 Pair (org.apache.commons.lang3.tuple.Pair)1 AbstractGremlinTest (org.apache.tinkerpop.gremlin.AbstractGremlinTest)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)1 Mutating (org.apache.tinkerpop.gremlin.process.traversal.step.Mutating)1 CallbackRegistry (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.CallbackRegistry)1 Event (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.Event)1 ListCallbackRegistry (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.ListCallbackRegistry)1