Skip to content

Commit 22ad745

Browse files
authored
Merge pull request #377 from lutovich/1.4-multi-bookmarks-it
Causal cluster integration test for multiple bookmarks
2 parents 55ed81a + 57adba5 commit 22ad745

File tree

1 file changed

+81
-2
lines changed

1 file changed

+81
-2
lines changed

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

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.CountDownLatch;
2929
import java.util.concurrent.ExecutorService;
3030
import java.util.concurrent.Executors;
31+
import java.util.concurrent.Future;
3132
import java.util.concurrent.TimeUnit;
3233
import java.util.concurrent.TimeoutException;
3334

@@ -59,6 +60,7 @@
5960
import org.neo4j.driver.v1.util.cc.ClusterMemberRole;
6061
import org.neo4j.driver.v1.util.cc.ClusterRule;
6162

63+
import static java.util.concurrent.TimeUnit.SECONDS;
6264
import static org.hamcrest.Matchers.containsString;
6365
import static org.hamcrest.Matchers.instanceOf;
6466
import static org.hamcrest.Matchers.startsWith;
@@ -233,7 +235,7 @@ public void shouldDropBrokenOldSessions() throws Exception
233235

234236
URI routingUri = cluster.leader().getRoutingUri();
235237
AuthToken auth = clusterRule.getDefaultAuthToken();
236-
RoutingSettings routingSettings = new RoutingSettings( 1, TimeUnit.SECONDS.toMillis( 5 ), null );
238+
RoutingSettings routingSettings = new RoutingSettings( 1, SECONDS.toMillis( 5 ), null );
237239
RetrySettings retrySettings = RetrySettings.DEFAULT;
238240

239241
try ( Driver driver = driverFactory.newInstance( routingUri, auth, routingSettings, retrySettings, config ) )
@@ -450,6 +452,43 @@ public Integer execute( Transaction tx )
450452
}
451453
}
452454

455+
@Test
456+
public void shouldAcceptMultipleBookmarks() throws Exception
457+
{
458+
int threadCount = 5;
459+
String label = "Person";
460+
String property = "name";
461+
String value = "Alice";
462+
463+
Cluster cluster = clusterRule.getCluster();
464+
ClusterMember leader = cluster.leader();
465+
ExecutorService executor = Executors.newCachedThreadPool();
466+
467+
try ( Driver driver = createDriver( leader.getRoutingUri() ) )
468+
{
469+
List<Future<String>> futures = new ArrayList<>();
470+
for ( int i = 0; i < threadCount; i++ )
471+
{
472+
futures.add( executor.submit( createNodeAndGetBookmark( driver, label, property, value ) ) );
473+
}
474+
475+
List<String> bookmarks = new ArrayList<>();
476+
for ( Future<String> future : futures )
477+
{
478+
bookmarks.add( future.get( 10, SECONDS ) );
479+
}
480+
481+
executor.shutdown();
482+
assertTrue( executor.awaitTermination( 5, SECONDS ) );
483+
484+
try ( Session session = driver.session( AccessMode.READ, bookmarks ) )
485+
{
486+
int count = countNodes( session, label, property, value );
487+
assertEquals( count, threadCount );
488+
}
489+
}
490+
}
491+
453492
private int executeWriteAndReadThroughBolt( ClusterMember member ) throws TimeoutException, InterruptedException
454493
{
455494
try ( Driver driver = createDriver( member.getRoutingUri() ) )
@@ -571,7 +610,7 @@ private void awaitLeaderToStepDown( Driver driver )
571610
int newLeadersCount = 0;
572611
int newFollowersCount = 0;
573612
int newReadReplicasCount = 0;
574-
for ( Record record : session.run( "CALL dbms.cluster.overview" ).list() )
613+
for ( Record record : session.run( "CALL dbms.cluster.overview()" ).list() )
575614
{
576615
ClusterMemberRole role = ClusterMemberRole.valueOf( record.get( "role" ).asString() );
577616
if ( role == ClusterMemberRole.LEADER )
@@ -669,4 +708,44 @@ private static void closeAndExpectException( AutoCloseable closeable, Class<? ex
669708
assertThat( e, instanceOf( exceptionClass ) );
670709
}
671710
}
711+
712+
private static int countNodes( Session session, final String label, final String property, final String value )
713+
{
714+
return session.readTransaction( new TransactionWork<Integer>()
715+
{
716+
@Override
717+
public Integer execute( Transaction tx )
718+
{
719+
StatementResult result = tx.run( "MATCH (n:" + label + " {" + property + ": $value}) RETURN count(n)",
720+
parameters( "value", value ) );
721+
return result.single().get( 0 ).asInt();
722+
}
723+
} );
724+
}
725+
726+
private static Callable<String> createNodeAndGetBookmark( final Driver driver, final String label,
727+
final String property, final String value )
728+
{
729+
return new Callable<String>()
730+
{
731+
@Override
732+
public String call()
733+
{
734+
try ( Session session = driver.session() )
735+
{
736+
session.writeTransaction( new TransactionWork<Void>()
737+
{
738+
@Override
739+
public Void execute( Transaction tx )
740+
{
741+
tx.run( "CREATE (n:" + label + ") SET n." + property + " = $value",
742+
parameters( "value", value ) );
743+
return null;
744+
}
745+
} );
746+
return session.lastBookmark();
747+
}
748+
}
749+
};
750+
}
672751
}

0 commit comments

Comments
 (0)