Skip to content

Commit e24d07d

Browse files
author
Zhen Li
authored
Merge pull request #301 from neo4j/1.1-bookmark-when-tx-fails
Improve bookmark testing
2 parents 5723b6e + 4944bab commit e24d07d

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

driver/src/test/java/org/neo4j/driver/v1/integration/BookmarkIT.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
import org.junit.rules.ExpectedException;
2525

2626
import org.neo4j.driver.v1.Transaction;
27+
import org.neo4j.driver.v1.exceptions.ClientException;
2728
import org.neo4j.driver.v1.util.TestNeo4jSession;
2829

29-
import static org.hamcrest.MatcherAssert.assertThat;
30+
import static org.hamcrest.Matchers.instanceOf;
3031
import static org.hamcrest.core.StringStartsWith.startsWith;
3132
import static org.junit.Assert.assertNotNull;
3233
import static org.junit.Assert.assertNull;
34+
import static org.junit.Assert.assertThat;
35+
import static org.junit.Assert.fail;
3336
import static org.junit.Assume.assumeTrue;
3437
import static org.neo4j.driver.v1.util.ServerVersion.v3_1_0;
3538
import static org.neo4j.driver.v1.util.ServerVersion.version;
@@ -65,4 +68,55 @@ public void shouldReceiveBookmarkOnSuccessfulCommit() throws Throwable
6568
assertNotNull( session.lastBookmark() );
6669
assertThat( session.lastBookmark(), startsWith( "neo4j:bookmark:v1:tx" ) );
6770
}
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+
}
68122
}

0 commit comments

Comments
 (0)