Repository navigation
TINKERPOP-3294: AddPropertyStep does not capture the old property for EventStrategy when cardinality is not specified #3715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.8-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ | |
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| /** | ||
| * @author Stephen Mallette (http://stephen.genoprime.com) | ||
|
|
@@ -1051,6 +1052,39 @@ public void vertexPropertyChanged(final Vertex element, final VertexProperty old | |
| assertThat(triggered.get(), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) | ||
| public void shouldCaptureOldVertexPropertyWhenChangedWithDefaultCardinality() { | ||
| assumeTrue(graph.features().vertex().getCardinality("to-change") == VertexProperty.Cardinality.single); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix also changes behavior when the graph’s default cardinality is set, but this test only runs for default single cardinality. Please add a second test for default set and ensure it executes with TinkerGraph by configuring |
||
|
|
||
| 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 VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { | ||
| 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); | ||
|
|
||
| gts.V(v).property("to-change", "dah").iterate(); | ||
| tryCommit(graph); | ||
|
|
||
| assertEquals(1, IteratorUtils.count(g.V(v).properties())); | ||
| assertThat(triggered.get(), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) | ||
| public void shouldDetachVertexPropertyWhenNew() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 3.7, this cardinality is used only for event capture. The actual write below still calls
vertex.property(key, value)when cardinality is omitted, and providers may implement that differently from getCardinality(key), which is documented as potentially only a hint. This could cause the event to report a replacement when the provider actually appended, or miss a replacement when it wrote as single. I fully agree with your fix on 3.8-dev though.Do you need this fix on 3.7.x or can we just apply it to 3.8.x?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I missed that. I've patched it on my side in a fork for now, so applying it to 3.8.x only is fine, and I'll pick it up there later. I've retargeted this PR to 3.8-dev.