|
22 | 22 | import org.junit.Test;
|
23 | 23 |
|
24 | 24 | import java.net.URI;
|
| 25 | +import java.util.ArrayList; |
25 | 26 | import java.util.List;
|
26 | 27 | import java.util.concurrent.Callable;
|
27 | 28 | import java.util.concurrent.CountDownLatch;
|
@@ -85,6 +86,16 @@ public void shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfLeader() th
|
85 | 86 | assertEquals( 1, count );
|
86 | 87 | }
|
87 | 88 |
|
| 89 | + @Test |
| 90 | + public void shouldExecuteReadAndWritesWhenRouterIsDiscovered() throws Exception |
| 91 | + { |
| 92 | + Cluster cluster = clusterRule.getCluster(); |
| 93 | + |
| 94 | + int count = executeWriteAndReadThroughBoltOnFirstAvailableAddress( cluster.anyReadReplica(), cluster.leader() ); |
| 95 | + |
| 96 | + assertEquals( 1, count ); |
| 97 | + } |
| 98 | + |
88 | 99 | @Test
|
89 | 100 | public void shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfFollower() throws Exception
|
90 | 101 | {
|
@@ -446,6 +457,19 @@ private int executeWriteAndReadThroughBolt( ClusterMember member ) throws Timeou
|
446 | 457 | }
|
447 | 458 | }
|
448 | 459 |
|
| 460 | + private int executeWriteAndReadThroughBoltOnFirstAvailableAddress( ClusterMember... members ) throws TimeoutException, InterruptedException |
| 461 | + { |
| 462 | + List<String> addresses = new ArrayList<>( members.length ); |
| 463 | + for ( ClusterMember member : members ) |
| 464 | + { |
| 465 | + addresses.add( member.getRoutingUri().getAuthority() ); |
| 466 | + } |
| 467 | + try ( Driver driver = discoverDriver( addresses ) ) |
| 468 | + { |
| 469 | + return inExpirableSession( driver, createWritableSession( null ), executeWriteAndRead() ); |
| 470 | + } |
| 471 | + } |
| 472 | + |
449 | 473 | private Function<Driver,Session> createSession()
|
450 | 474 | {
|
451 | 475 | return new Function<Driver,Session>()
|
@@ -592,6 +616,24 @@ public Logger getLog( String name )
|
592 | 616 | return GraphDatabase.driver( boltUri, clusterRule.getDefaultAuthToken(), config );
|
593 | 617 | }
|
594 | 618 |
|
| 619 | + private Driver discoverDriver( List<String> addresses ) |
| 620 | + { |
| 621 | + Logging devNullLogging = new Logging() |
| 622 | + { |
| 623 | + @Override |
| 624 | + public Logger getLog( String name ) |
| 625 | + { |
| 626 | + return DevNullLogger.DEV_NULL_LOGGER; |
| 627 | + } |
| 628 | + }; |
| 629 | + |
| 630 | + Config config = Config.build() |
| 631 | + .withLogging( devNullLogging ) |
| 632 | + .toConfig(); |
| 633 | + |
| 634 | + return GraphDatabase.routingDriverFromFirstAvailableAddress( addresses, clusterRule.getDefaultAuthToken(), config ); |
| 635 | + } |
| 636 | + |
595 | 637 | private static void createNodesInDifferentThreads( int count, final Driver driver ) throws Exception
|
596 | 638 | {
|
597 | 639 | final CountDownLatch beforeRunLatch = new CountDownLatch( count );
|
|
0 commit comments