Skip to content

Commit

Permalink
Cleanup java-driver deprecated usage
Browse files Browse the repository at this point in the history
Switch bookmarks usage to be session based instead of transaction based
  • Loading branch information
MishaDemianenko committed Jan 17, 2018
1 parent 5dcd584 commit 93f821f
Showing 1 changed file with 12 additions and 13 deletions.
Expand Up @@ -119,7 +119,7 @@ public void shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfFollower()
assertEquals( 1, count );
}

private int executeWriteAndReadThroughBolt( CoreClusterMember core ) throws TimeoutException, InterruptedException
private int executeWriteAndReadThroughBolt( CoreClusterMember core ) throws TimeoutException
{
try ( Driver driver = GraphDatabase.driver( core.routingURI(), AuthTokens.basic( "neo4j", "neo4j" ) ) )
{
Expand Down Expand Up @@ -456,7 +456,7 @@ public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception

assertNotNull( bookmark );

try ( Session session = driver.session(); Transaction tx = session.beginTransaction( bookmark ) )
try ( Session session = driver.session( bookmark ); Transaction tx = session.beginTransaction() )
{
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 1, record.get( "count" ).asInt() );
Expand Down Expand Up @@ -494,9 +494,9 @@ public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception

assertNotNull( bookmark );

inExpirableSession( driver, d -> d.session( AccessMode.WRITE ), session ->
inExpirableSession( driver, d -> d.session( AccessMode.WRITE, bookmark ), session ->
{
try ( Transaction tx = session.beginTransaction( bookmark ) )
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "CREATE (p:Person {name: {name} })", Values.parameters( "name", "Alistair" ) );
tx.success();
Expand Down Expand Up @@ -545,9 +545,9 @@ public void shouldUseBookmarkFromAWriteSessionInAReadSession() throws Throwable

driver = GraphDatabase.driver( readReplica.directURI(), AuthTokens.basic( "neo4j", "neo4j" ) );

try ( Session session = driver.session( AccessMode.READ ) )
try ( Session session = driver.session( AccessMode.READ, bookmark ) )
{
try ( Transaction tx = session.beginTransaction( bookmark ) )
try ( Transaction tx = session.beginTransaction() )
{
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
tx.success();
Expand Down Expand Up @@ -599,7 +599,7 @@ public void shouldSendRequestsToNewlyAddedReadReplicas() throws Throwable
{
try ( Session session = driver.session( AccessMode.READ, bookmark ) )
{
executeReadQuery( bookmark, session );
executeReadQuery( session );

session.readTransaction( (TransactionWork<Void>) tx ->
{
Expand Down Expand Up @@ -748,17 +748,17 @@ public void transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused() th
assertEquals( numberOfRequests, happyCount );
}

private void executeReadQuery( String bookmark, Session session )
private void executeReadQuery( Session session )
{
try ( Transaction tx = session.beginTransaction( bookmark ) )
try ( Transaction tx = session.beginTransaction() )
{
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 1, record.get( "count" ).asInt() );
}
}

private <T> T inExpirableSession( Driver driver, Function<Driver,Session> acquirer, Function<Session,T> op )
throws TimeoutException, InterruptedException
throws TimeoutException
{
long endTime = System.currentTimeMillis() + DEFAULT_TIMEOUT_MS;

Expand Down Expand Up @@ -806,16 +806,15 @@ private void switchLeader( CoreClusterMember initialLeader ) throws InterruptedE
}
}

private CoreClusterMember triggerElection( CoreClusterMember initialLeader ) throws IOException, TimeoutException
private void triggerElection( CoreClusterMember initialLeader ) throws IOException, TimeoutException
{
for ( CoreClusterMember coreClusterMember : cluster.coreMembers() )
{
if ( !coreClusterMember.equals( initialLeader ) )
{
coreClusterMember.raft().triggerElection( Clock.systemUTC() );
return cluster.awaitLeader();
cluster.awaitLeader();
}
}
return initialLeader;
}
}

0 comments on commit 93f821f

Please sign in to comment.