tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [1/2] tinkerpop git commit: TINKERPOP-1504 Added the property key to events for new properties.
Date Wed, 15 Mar 2017 17:11:41 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/tp32 d7c2a221e -> 99ad76d0b


TINKERPOP-1504 Added the property key to events for new properties.

Newly added properties triggered "changed" events when using EventStrategy but the specific
key that was newly added was not available in the mutation listener. The listener would simply
report the new value only. After this change the listener now gets a DetachedVertexPropery/Property
with the newly added key and a null value set.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/06bf620c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/06bf620c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/06bf620c

Branch: refs/heads/tp32
Commit: 06bf620caf6fda6325512fde704e4b92329fa8fd
Parents: cde8b31
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Mar 15 10:40:09 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Mar 15 10:40:09 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   1 +
 .../step/sideEffect/AddPropertyStep.java        |  17 +-
 .../decoration/EventStrategyProcessTest.java    | 474 ++++++++++++++++++-
 3 files changed, 488 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/06bf620c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f4eaaa8..90b9f00 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.1.7 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed `EventStrategy` so that newly added properties trigger events with the name of the
key that was added.
 * Drop use of jitpack for the jbcrypt artifact - using the official one in Maven Central.
 
 [[release-3-1-6]]

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/06bf620c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
index 7c12c0e..3ccff52 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
@@ -36,6 +36,8 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
 
 import java.util.List;
 import java.util.Set;
@@ -91,11 +93,20 @@ public final class AddPropertyStep<S extends Element> extends SideEffectStep<S>
             final boolean newProperty = element instanceof Vertex ? currentProperty == VertexProperty.empty()
: currentProperty == Property.empty();
             final Event.ElementPropertyChangedEvent evt;
             if (element instanceof Vertex)
-                evt = new Event.VertexPropertyChangedEvent(DetachedFactory.detach((Vertex)
element, true), newProperty ? null : DetachedFactory.detach((VertexProperty) currentProperty,
true), value, vertexPropertyKeyValues);
+                evt = new Event.VertexPropertyChangedEvent(DetachedFactory.detach((Vertex)
element, true),
+                        newProperty ?
+                                new DetachedVertexProperty(null, key, null, null) :
+                                DetachedFactory.detach((VertexProperty) currentProperty,
true), value, vertexPropertyKeyValues);
             else if (element instanceof Edge)
-                evt = new Event.EdgePropertyChangedEvent(DetachedFactory.detach((Edge) element,
true), newProperty ? null : DetachedFactory.detach(currentProperty), value);
+                evt = new Event.EdgePropertyChangedEvent(DetachedFactory.detach((Edge) element,
true),
+                        newProperty ?
+                                new DetachedProperty(key, null) :
+                                DetachedFactory.detach(currentProperty), value);
             else if (element instanceof VertexProperty)
-                evt = new Event.VertexPropertyPropertyChangedEvent(DetachedFactory.detach((VertexProperty)
element, true), newProperty ? null : DetachedFactory.detach(currentProperty), value);
+                evt = new Event.VertexPropertyPropertyChangedEvent(DetachedFactory.detach((VertexProperty)
element, true),
+                        newProperty ?
+                                new DetachedProperty(key, null):
+                                DetachedFactory.detach(currentProperty), value);
             else
                 throw new IllegalStateException(String.format("The incoming object cannot
be processed by change eventing in %s:  %s", AddPropertyStep.class.getName(), element));
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/06bf620c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
index 3effae5..76ae31c 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
@@ -34,6 +34,7 @@ import org.junit.Test;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -529,11 +530,482 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
         assertEquals(2, listener2.addVertexEventRecorded());
     }
 
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+    public void shouldDetachPropertyOfVertexPropertyWhenRemoved() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("xxx","blah");
+        final Property p = vp.property("to-drop", "dah");
+        vp.property("not-dropped", "yay!");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyPropertyRemoved(final VertexProperty element, final
Property property) {
+                assertEquals(vp.label(), element.label());
+                assertEquals(vp.value(), element.value());
+                assertEquals(p.value(), property.value());
+                assertEquals(p.key(), property.key());
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).properties("xxx").properties("to-drop").drop().iterate());
+
+        assertEquals(1, IteratorUtils.count(v.properties()));
+        assertEquals(1, IteratorUtils.count(v.properties().next().properties()));
+        assertEquals("yay!", vp.value("not-dropped"));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+    public void shouldDetachPropertyOfVertexPropertyWhenChanged() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("xxx","blah");
+        final Property p = vp.property("to-change", "dah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyPropertyChanged(final VertexProperty element, final
Property oldValue, final Object setValue) {
+                assertEquals(vp.label(), element.label());
+                assertEquals(vp.value(), element.value());
+                assertEquals(p.value(), oldValue.value());
+                assertEquals(p.key(), oldValue.key());
+                assertEquals("bah", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).properties("xxx").property("to-change","bah").iterate());
+
+        assertEquals(1, IteratorUtils.count(v.properties()));
+        assertEquals(1, IteratorUtils.count(v.properties().next().properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+    public void shouldDetachPropertyOfVertexPropertyWhenNew() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("xxx","blah");
+        final Property p = vp.property("to-change", "dah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyPropertyChanged(final VertexProperty element, final
Property oldValue, final Object setValue) {
+                assertEquals(vp.label(), element.label());
+                assertEquals(vp.value(), element.value());
+                assertEquals(null, oldValue.value());
+                assertEquals("new", oldValue.key());
+                assertEquals("yay!", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).properties("xxx").property("new","yay!").iterate());
+
+        assertEquals(1, IteratorUtils.count(v.properties()));
+        assertEquals(2, IteratorUtils.count(v.properties().next().properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldDetachPropertyOfEdgeWhenRemoved() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("self", v, "not-dropped", "yay!");
+        final Property p = e.property("to-drop", "dah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void edgePropertyRemoved(final Edge element, final Property property)
{
+                assertEquals(e.label(), element.label());
+                assertEquals(e.inVertex().id(), element.inVertex().id());
+                assertEquals(e.outVertex().id(), element.outVertex().id());
+                assertEquals(p.value(), property.value());
+                assertEquals(p.key(), property.key());
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.E(e).properties("to-drop").drop().iterate());
+
+        assertEquals(1, IteratorUtils.count(e.properties()));
+        assertEquals("yay!", e.value("not-dropped"));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldDetachPropertyOfEdgeWhenChanged() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("self", v);
+        final Property p = e.property("to-change", "no!");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void edgePropertyChanged(final Edge element, final Property oldValue,
final Object setValue) {
+                assertEquals(e.label(), element.label());
+                assertEquals(e.inVertex().id(), element.inVertex().id());
+                assertEquals(e.outVertex().id(), element.outVertex().id());
+                assertEquals(p.value(), oldValue.value());
+                assertEquals(p.key(), oldValue.key());
+                assertEquals("yay!", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.E(e).property("to-change","yay!").iterate());
+
+        assertEquals(1, IteratorUtils.count(e.properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldDetachPropertyOfEdgeWhenNew() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("self", v);
+        final Property p = e.property("to-change", "no!");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void edgePropertyChanged(final Edge element, final Property oldValue,
final Object setValue) {
+                assertEquals(e.label(), element.label());
+                assertEquals(e.inVertex().id(), element.inVertex().id());
+                assertEquals(e.outVertex().id(), element.outVertex().id());
+                assertEquals(null, oldValue.value());
+                assertEquals("new", oldValue.key());
+                assertEquals("yay!", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.E(e).property("new","yay!").iterate());
+
+        assertEquals(2, IteratorUtils.count(e.properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldDetachEdgeWhenRemoved() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("self", v, "dropped", "yay!");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void edgeRemoved(final Edge element) {
+                assertEquals(e.label(), element.label());
+                assertEquals(e.inVertex().id(), element.inVertex().id());
+                assertEquals(e.outVertex().id(), element.outVertex().id());
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.E(e).drop().iterate());
+
+        assertVertexEdgeCounts(graph, 1, 0);
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldDetachEdgeWhenAdded() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void edgeAdded(final Edge element) {
+                assertEquals("self", element.label());
+                assertEquals(v.id(), element.inVertex().id());
+                assertEquals(v.id(), element.outVertex().id());
+                assertEquals("there", element.value("here"));
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).as("a").addE("self").property("here", "there").from("a").to("a").iterate());
+
+        assertVertexEdgeCounts(graph, 1, 1);
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachVertexPropertyWhenRemoved() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("to-remove","blah");
+        final VertexProperty vpToKeep = v.property("to-keep","dah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyRemoved(final VertexProperty element) {
+                assertEquals(vp.label(), element.label());
+                assertEquals(vp.value(), element.value());
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).properties("to-remove").drop().iterate());
+
+        assertEquals(1, IteratorUtils.count(v.properties()));
+        assertEquals(vpToKeep.value(), v.value("to-keep"));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachVertexPropertyWhenChanged() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        v.property("to-change", "blah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyChanged(final Vertex element, final Property oldValue,
final Object setValue, final Object... vertexPropertyKeyValues) {
+                assertEquals(v.label(), element.label());
+                assertEquals(v.id(), element.id());
+                assertEquals("to-change", oldValue.key());
+                assertEquals("blah", oldValue.value());
+                assertEquals("dah", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).property(VertexProperty.Cardinality.single, "to-change",
"dah").iterate());
+
+        assertEquals(1, IteratorUtils.count(v.properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachVertexPropertyWhenNew() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+        v.property("old","blah");
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexPropertyChanged(final Vertex element, final Property oldValue,
final Object setValue, final Object... vertexPropertyKeyValues) {
+                assertEquals(v.label(), element.label());
+                assertEquals(v.id(), element.id());
+                assertEquals("new", oldValue.key());
+                assertEquals(null, oldValue.value());
+                assertEquals("dah", setValue);
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).property(VertexProperty.Cardinality.single, "new",
"dah").iterate());
+
+        assertEquals(2, IteratorUtils.count(v.properties()));
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachVertexWhenRemoved() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+        final Vertex v = graph.addVertex();
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexRemoved(final Vertex element) {
+                assertEquals(v.id(), element.id());
+                assertEquals(v.label(), element.label());
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.V(v).drop().iterate());
+
+        assertVertexEdgeCounts(graph, 0, 0);
+        assertThat(triggered.get(), is(true));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachVertexWhenAdded() {
+        final AtomicBoolean triggered = new AtomicBoolean(false);
+
+        final MutationListener listener = new AbstractMutationListener() {
+            @Override
+            public void vertexAdded(final Vertex element) {
+                assertEquals("thing", element.label());
+                assertEquals("there", element.value("here"));
+                triggered.set(true);
+            }
+        };
+        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
+
+        if (graph.features().graph().supportsTransactions())
+            builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
+
+        final EventStrategy eventStrategy = builder.create();
+        final GraphTraversalSource gts = create(eventStrategy);
+
+        tryCommit(graph, g -> gts.addV("thing").property("here", "there").iterate());
+
+        assertVertexEdgeCounts(graph, 1, 0);
+        assertThat(triggered.get(), is(true));
+    }
+
     private GraphTraversalSource create(final EventStrategy strategy) {
         return graphProvider.traversal(graph, strategy);
     }
 
-    public static class StubMutationListener implements MutationListener {
+    static abstract class AbstractMutationListener implements MutationListener {
+        @Override
+        public void vertexAdded(final Vertex vertex) {
+
+        }
+
+        @Override
+        public void vertexRemoved(final Vertex vertex) {
+
+        }
+
+        @Override
+        public void vertexPropertyChanged(final Vertex element, final Property oldValue,
final Object setValue, final Object... vertexPropertyKeyValues) {
+
+        }
+
+        @Override
+        public void vertexPropertyRemoved(final VertexProperty vertexProperty) {
+
+        }
+
+        @Override
+        public void edgeAdded(final Edge edge) {
+
+        }
+
+        @Override
+        public void edgeRemoved(final Edge edge) {
+
+        }
+
+        @Override
+        public void edgePropertyChanged(final Edge element, final Property oldValue, final
Object setValue) {
+
+        }
+
+        @Override
+        public void edgePropertyRemoved(final Edge element, final Property property) {
+
+        }
+
+        @Override
+        public void vertexPropertyPropertyChanged(final VertexProperty element, final Property
oldValue, final Object setValue) {
+
+        }
+
+        @Override
+        public void vertexPropertyPropertyRemoved(final VertexProperty element, final Property
property) {
+
+        }
+    }
+
+    static class StubMutationListener implements MutationListener {
         private final AtomicLong addEdgeEvent = new AtomicLong(0);
         private final AtomicLong addVertexEvent = new AtomicLong(0);
         private final AtomicLong vertexRemovedEvent = new AtomicLong(0);


Mime
View raw message