Skip to content

Commit

Permalink
more Bolt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Needham committed Oct 5, 2016
1 parent 602cba2 commit 419b959
Showing 1 changed file with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import static org.neo4j.test.assertion.Assert.assertEventually;
Expand Down Expand Up @@ -305,14 +306,19 @@ public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception
AuthTokens.basic( "neo4j", "neo4j" ) );

String bookmark;
try ( Session session = driver.session(); Transaction tx = session.beginTransaction() )
try ( Session session = driver.session() )
{
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Jim" ) );
tx.success();
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Jim" ) );
tx.success();
}

bookmark = session.lastBookmark();
}

assertNotNull( bookmark );

try ( Session session = driver.session(); Transaction tx = session.beginTransaction( bookmark ) )
{
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
Expand All @@ -321,6 +327,83 @@ public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception
}
}

@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception
{
// given
cluster = clusterRule.withNumberOfEdgeMembers( 1 ).startCluster();
CoreClusterMember leader = cluster.awaitLeader( );

Driver driver = GraphDatabase.driver( "bolt://" + leader.boltAdvertisedAddress(),
AuthTokens.basic( "neo4j", "neo4j" ) );

try ( Session session = driver.session(AccessMode.WRITE) )
{
session.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Jim" ) );
}

String bookmark;
try ( Session session = driver.session(AccessMode.READ) )
{
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
tx.success();
}

bookmark = session.lastBookmark();
}

assertNotNull( bookmark );

try ( Session session = driver.session( AccessMode.WRITE );
Transaction tx = session.beginTransaction( bookmark ) )
{
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Alistair" ) );
tx.success();
}

try ( Session session = driver.session() )
{
Record record = session.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 2, record.get( "count" ).asInt() );
}
}

@Test
public void shouldUseBookmarkFromAWriteSessionInAReadSession() throws Exception
{
// given
cluster = clusterRule.withNumberOfEdgeMembers( 1 ).startCluster();
CoreClusterMember leader = cluster.awaitLeader( );

Driver driver = GraphDatabase.driver( "bolt://" + leader.boltAdvertisedAddress(),
AuthTokens.basic( "neo4j", "neo4j" ) );

String bookmark;
try ( Session session = driver.session(AccessMode.WRITE) )
{
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Jim" ) );
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Alistair" ) );
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Mark" ) );
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Chris" ) );
tx.success();
}

bookmark = session.lastBookmark();
}

assertNotNull( bookmark );

try ( Session session = driver.session(AccessMode.READ) )
{
Record record = session.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 4, record.get( "count" ).asInt() );
}
}

private ClusterMember connectedServer( Session session ) throws NoSuchFieldException, IllegalAccessException
{
Field connectionField = NetworkSession.class.getDeclaredField( "connection" );
Expand Down

0 comments on commit 419b959

Please sign in to comment.