|
24 | 24 | import org.junit.rules.ExpectedException;
|
25 | 25 |
|
26 | 26 | import org.neo4j.driver.v1.Transaction;
|
| 27 | +import org.neo4j.driver.v1.exceptions.ClientException; |
27 | 28 | import org.neo4j.driver.v1.util.TestNeo4jSession;
|
28 | 29 |
|
29 |
| -import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | +import static org.hamcrest.Matchers.instanceOf; |
30 | 31 | import static org.hamcrest.core.StringStartsWith.startsWith;
|
31 | 32 | import static org.junit.Assert.assertNotNull;
|
32 | 33 | import static org.junit.Assert.assertNull;
|
| 34 | +import static org.junit.Assert.assertThat; |
| 35 | +import static org.junit.Assert.fail; |
33 | 36 | import static org.junit.Assume.assumeTrue;
|
34 | 37 | import static org.neo4j.driver.v1.util.ServerVersion.v3_1_0;
|
35 | 38 | import static org.neo4j.driver.v1.util.ServerVersion.version;
|
@@ -65,4 +68,55 @@ public void shouldReceiveBookmarkOnSuccessfulCommit() throws Throwable
|
65 | 68 | assertNotNull( session.lastBookmark() );
|
66 | 69 | assertThat( session.lastBookmark(), startsWith( "neo4j:bookmark:v1:tx" ) );
|
67 | 70 | }
|
| 71 | + |
| 72 | + @Test |
| 73 | + public void bookmarkSetToNullAfterRolledBackTx() |
| 74 | + { |
| 75 | + assertNull( session.lastBookmark() ); |
| 76 | + |
| 77 | + try ( Transaction tx = session.beginTransaction() ) |
| 78 | + { |
| 79 | + tx.run( "CREATE (a:Person)" ); |
| 80 | + tx.success(); |
| 81 | + } |
| 82 | + |
| 83 | + assertNotNull( session.lastBookmark() ); |
| 84 | + |
| 85 | + try ( Transaction tx = session.beginTransaction() ) |
| 86 | + { |
| 87 | + tx.run( "CREATE (a:Person)" ); |
| 88 | + tx.failure(); |
| 89 | + } |
| 90 | + |
| 91 | + assertNull( session.lastBookmark() ); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void bookmarkSetToNullAfterTxFailure() |
| 96 | + { |
| 97 | + assertNull( session.lastBookmark() ); |
| 98 | + |
| 99 | + try ( Transaction tx = session.beginTransaction() ) |
| 100 | + { |
| 101 | + tx.run( "CREATE (a:Person)" ); |
| 102 | + tx.success(); |
| 103 | + } |
| 104 | + |
| 105 | + assertNotNull( session.lastBookmark() ); |
| 106 | + |
| 107 | + Transaction tx = session.beginTransaction(); |
| 108 | + tx.run( "RETURN" ); |
| 109 | + tx.success(); |
| 110 | + try |
| 111 | + { |
| 112 | + tx.close(); |
| 113 | + fail( "Exception expected" ); |
| 114 | + } |
| 115 | + catch ( Exception e ) |
| 116 | + { |
| 117 | + assertThat( e, instanceOf( ClientException.class ) ); |
| 118 | + } |
| 119 | + |
| 120 | + assertNull( session.lastBookmark() ); |
| 121 | + } |
68 | 122 | }
|
0 commit comments