Skip to content

Instantly share code, notes, and snippets.

@scottmarlow
Last active July 19, 2016 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmarlow/2779d21653e8466d85e38c1d62d4bb1e to your computer and use it in GitHub Desktop.
Save scottmarlow/2779d21653e8466d85e38c1d62d4bb1e to your computer and use it in GitHub Desktop.
Neo4j Java driver example/tests using Session.beginTransaction
1. The shouldNotAllowMoreTxAfterClientException test asserts that no more statements can be run in Neo4j transaction once a client error occurs.
I think that this implies that a Neo4j transaction level failure should fail the Ne04j transaction.
Should a Neo4j transaction failure propagate to the JTA transaction as well, as "set rollback only"?
https://github.com/neo4j/neo4j-java-driver/blob/1.1/driver/src/test/java/org/neo4j/driver/v1/integration/ErrorIT.java#L59
2. The shouldAllowNewTransactionAfterRecoverableError() test is pretty close to the case we discussed on the WildFly dev mailing list on July 19th 2016. This test verifies that after a transaction error, a new transaction can be started, which can succeed.
https://github.com/neo4j/neo4j-java-driver/blob/1.1/driver/src/test/java/org/neo4j/driver/v1/integration/ErrorIT.java#L92
3. The shouldHandleFailureAtCommitTime() test shows how application code can be sensitive to when ClientException is thrown (http://neo4j.com/docs/api/java-driver/current/index.html?org/neo4j/driver/v1/exceptions/ClientException.html) at Neo4j transaction commit time is expected by this unit test.
https://github.com/neo4j/neo4j-java-driver/blob/1.1/driver/src/test/java/org/neo4j/driver/v1/integration/ErrorIT.java#L128
4. The shouldRunAndCommit() test shows that a session can be used after a Neo4j transaction ends.
https://github.com/neo4j/neo4j-java-driver/blob/1.1/driver/src/test/java/org/neo4j/driver/v1/integration/TransactionIT.java#L47
5. The shouldRunAndRollbackByDefault() test looks wrong to me, but I still wanted to point it out.
I wonder if they should call tx.close() in that test after the two tx.run() calls?
I'm still mentioning this test because it could be an interesting use case when we understand it.
https://github.com/neo4j/neo4j-java-driver/blob/1.1/driver/src/test/java/org/neo4j/driver/v1/integration/TransactionIT.java#L64
6. the shouldBeClosedAfterRollback()/shouldBeClosedAfterCommit() tests shows a dependency on expecting tx.isOpen() == false after the transaction ends. In same source as previous entry (TransactionIT).
7. The shouldHandleFailureAfterClosingTransaction() test is similar to the above shouldHandleFailureAtCommitTime() test (see TransactionIT).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment