-
Notifications
You must be signed in to change notification settings - Fork 495
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
Fix var tests dev #2650
Fix var tests dev #2650
Changes from all commits
a737717
9b7c3c0
4dad982
96d3439
e048108
71096fe
fea4aa9
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 |
---|---|---|
|
@@ -129,40 +129,59 @@ public void testTimeStampTrigger() throws Exception { | |
}); | ||
} | ||
|
||
// TODO NC:Why is this failing? | ||
@Ignore | ||
@Test | ||
public void testTxId() throws Exception { | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo','UNWIND $createdNodes AS n SET n.txId = $transactionId, n.txTime = $commitTime',{phase:'after'})"); | ||
public void testTxIdAfterAsync() throws Exception { | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo','UNWIND $createdNodes AS n SET n.txId = $transactionId, n.txTime = $commitTime',{phase:'afterAsync'})"); | ||
db.executeTransactionally("CREATE (f:Bar)"); | ||
TestUtil.testCall(db, "MATCH (f:Bar) RETURN f", (row) -> { | ||
org.neo4j.test.assertion.Assert.assertEventually(() -> | ||
db.executeTransactionally("MATCH (n:Bar) RETURN n", Map.of(), | ||
result -> { | ||
final Node node = result.<Node>columnAs("n").next(); | ||
return (long) node.getProperty("txId", -1L) > -1L | ||
&& (long) node.getProperty("txTime") > start; | ||
Comment on lines
+140
to
+141
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. What's the difference between checking this and that the properties are not null (and have been assigned)? 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. If I understand correctly, in this case I left the previous assertions on lines 154 and 155:
I just changed the test from "after" to "afterAsync" (by adding I think that verifying only the existence of 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. But the node was created without properties in the first place, so if they are present, that should be enough to know the trigger was fired, isn't it? Anyway, this is not a biggie |
||
}) | ||
, (value) -> value, 30L, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testTxId() { | ||
db.executeTransactionally("CREATE (f:Another)"); | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo','UNWIND $createdNodes AS n \n" + | ||
"MATCH (a:Another) WITH a, n\n" + | ||
"SET a.txId = $transactionId, a.txTime = $commitTime',{phase:'after'})"); | ||
db.executeTransactionally("CREATE (f:Bar)"); | ||
TestUtil.testCall(db, "MATCH (f:Another) RETURN f", (row) -> { | ||
assertEquals(true, (Long) ((Node) row.get("f")).getProperty("txId") > -1L); | ||
assertEquals(true, (Long) ((Node) row.get("f")).getProperty("txTime") > start); | ||
}); | ||
db.executeTransactionally("MATCH (n:Another) DELETE n"); | ||
} | ||
|
||
@Test | ||
public void testMetaDataBefore() { | ||
testMetaData("before"); | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo','UNWIND $createdNodes AS n SET n.label = labels(n)[0], n += $metaData', {phase: 'before'})"); | ||
testMetaData("MATCH (n:Bar) RETURN n"); | ||
} | ||
|
||
// TODO NC:Why is this failing? | ||
@Ignore | ||
@Test | ||
public void testMetaDataAfter() { | ||
testMetaData("after"); | ||
db.executeTransactionally("CREATE (n:Another)"); | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo', 'UNWIND $createdNodes AS n MATCH (a:Another) SET a.label = labels(n)[0], a += $metaData', {phase: 'after'})"); | ||
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. How come we can modify the node here adding things if it is phase after? 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. As above, because the node |
||
testMetaData("MATCH (n:Another) RETURN n"); | ||
db.executeTransactionally("MATCH (n:Another) DELETE n"); | ||
} | ||
|
||
private void testMetaData(String phase) { | ||
db.executeTransactionally("CALL apoc.trigger.add('txinfo','UNWIND $createdNodes AS n SET n += $metaData',{phase:$phase})", Collections.singletonMap("phase", phase)); | ||
private void testMetaData(String matchQuery) { | ||
try (Transaction tx = db.beginTx()) { | ||
KernelTransaction ktx = ((TransactionImpl)tx).kernelTransaction(); | ||
ktx.setMetaData(Collections.singletonMap("txMeta", "hello")); | ||
tx.execute("CREATE (f:Bar)"); | ||
tx.commit(); | ||
} | ||
TestUtil.testCall(db, "MATCH (f:Bar) RETURN f", (row) -> { | ||
assertEquals("hello", ((Node) row.get("f")).getProperty("txMeta") ); | ||
TestUtil.testCall(db, matchQuery, (row) -> { | ||
final Node node = (Node) row.get("n"); | ||
assertEquals("Bar", node.getProperty("label")); | ||
assertEquals("hello", node.getProperty("txMeta")); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,17 @@ You can use these helper functions to extract nodes or relationships by label/re | |
| apoc.trigger.propertiesByKey($assignedNodeProperties,'key') | function to filter propertyEntries by property-key, to be used within a trigger statement with $assignedNode/RelationshipProperties and $removedNode/RelationshipProperties. Returns [{old,[new],key,node,relationship}] | ||
|=== | ||
|
||
[WARNING] | ||
==== | ||
Unlike Neo4j up to 4, with Neo4j 5 it's not possible to modify an entity created in phase: "after". | ||
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. The wording of this can be improved. I think here we mean we cannot modify the same node the trigger gets its information from? Cause otherwise I cannot explain this: https://github.com/neo4j-contrib/neo4j-apoc-procedures/pull/2650/files#r835190507 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. Yes, maybe I should write this clearer. I mean entities "just" created (present in 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. I'm happy to approve provided we amend the wording (can be in another PR if we are in a rush to merge this one) |
||
For example this query will throw an Exception with message `can't acquire ExclusiveLock...`: | ||
``` | ||
CALL apoc.trigger.add('name','UNWIND $createdNodes AS n SET n.txId = $transactionId',{phase:'after'}); | ||
CREATE (f:Baz); | ||
``` | ||
|
||
Instead, it's necessary to put another phase or perform only reading operations. | ||
==== | ||
|
||
== Triggers Examples | ||
|
||
|
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.
Any reason why we had to change this?
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.
Because previously there was
call db.constraints ()
, now there isSHOW CONSTRAINTS YIELD createStatement
(line 160). The latter returns a different result.