|
26 | 26 | import java.net.URI;
|
27 | 27 | import java.util.ArrayList;
|
28 | 28 | import java.util.Arrays;
|
29 |
| -import java.util.Collections; |
30 | 29 | import java.util.List;
|
31 | 30 | import java.util.Map;
|
32 | 31 | import java.util.Set;
|
|
40 | 39 | import java.util.concurrent.TimeoutException;
|
41 | 40 | import java.util.concurrent.atomic.AtomicBoolean;
|
42 | 41 | import java.util.function.Function;
|
43 |
| -import java.util.stream.Collectors; |
44 | 42 |
|
45 | 43 | import org.neo4j.driver.AccessMode;
|
46 | 44 | import org.neo4j.driver.AuthToken;
|
|
70 | 68 | import org.neo4j.driver.internal.util.ServerVersion;
|
71 | 69 | import org.neo4j.driver.internal.util.ThrowingMessageEncoder;
|
72 | 70 | import org.neo4j.driver.internal.util.io.ChannelTrackingDriverFactory;
|
73 |
| -import org.neo4j.driver.net.ServerAddress; |
74 | 71 | import org.neo4j.driver.summary.ResultSummary;
|
75 | 72 | import org.neo4j.driver.util.cc.Cluster;
|
76 | 73 | import org.neo4j.driver.util.cc.ClusterExtension;
|
@@ -329,140 +326,6 @@ void beginTransactionThrowsForInvalidBookmark()
|
329 | 326 | }
|
330 | 327 | }
|
331 | 328 |
|
332 |
| - @Test |
333 |
| - void shouldHandleGracefulLeaderSwitch() throws Exception |
334 |
| - { |
335 |
| - Cluster cluster = clusterRule.getCluster(); |
336 |
| - ClusterMember leader = cluster.leader(); |
337 |
| - ServerAddress clusterAddress = ServerAddress.of( "cluster", 7687 ); |
338 |
| - URI clusterUri = URI.create( String.format( "neo4j://%s:%d", clusterAddress.host(), clusterAddress.port() ) ); |
339 |
| - Set<ServerAddress> coreAddresses = cluster.cores().stream() |
340 |
| - .map( ClusterMember::getBoltAddress ) |
341 |
| - .collect( Collectors.toSet() ); |
342 |
| - |
343 |
| - Config config = Config.builder() |
344 |
| - .withLogging( none() ) |
345 |
| - .withResolver( address -> address.equals( clusterAddress ) ? coreAddresses : Collections.singleton( address ) ) |
346 |
| - .build(); |
347 |
| - |
348 |
| - try ( Driver driver = GraphDatabase.driver( clusterUri, clusterRule.getDefaultAuthToken(), config ) ) |
349 |
| - { |
350 |
| - Session session1 = driver.session(); |
351 |
| - Transaction tx1 = session1.beginTransaction(); |
352 |
| - |
353 |
| - // gracefully stop current leader to force re-election |
354 |
| - cluster.stop( leader ); |
355 |
| - |
356 |
| - assertThrows( (Class<? extends Exception>) SessionExpiredException.class, |
357 |
| - () -> tx1.run( "CREATE (person:Person {name: $name, title: $title})", |
358 |
| - parameters( "name", "Webber", "title", "Mr" ) ) ); |
359 |
| - |
360 |
| - session1.close(); |
361 |
| - |
362 |
| - Bookmark bookmark = inExpirableSession( driver, Driver::session, session -> |
363 |
| - { |
364 |
| - try ( Transaction tx = session.beginTransaction() ) |
365 |
| - { |
366 |
| - tx.run( "CREATE (person:Person {name: $name, title: $title})", |
367 |
| - parameters( "name", "Webber", "title", "Mr" ) ); |
368 |
| - tx.commit(); |
369 |
| - } |
370 |
| - return session.lastBookmark(); |
371 |
| - } ); |
372 |
| - |
373 |
| - try ( Session session2 = driver.session( |
374 |
| - builder().withDefaultAccessMode( AccessMode.READ ).withBookmarks( bookmark ).build() ); |
375 |
| - Transaction tx2 = session2.beginTransaction() ) |
376 |
| - { |
377 |
| - Record record = tx2.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next(); |
378 |
| - tx2.commit(); |
379 |
| - assertEquals( 1, record.get( "count" ).asInt() ); |
380 |
| - } |
381 |
| - } |
382 |
| - } |
383 |
| - |
384 |
| - @Test |
385 |
| - void shouldNotServeWritesWhenMajorityOfCoresAreDead() |
386 |
| - { |
387 |
| - Cluster cluster = clusterRule.getCluster(); |
388 |
| - ClusterMember leader = cluster.leader(); |
389 |
| - |
390 |
| - try ( Driver driver = createDriver( leader.getRoutingUri() ) ) |
391 |
| - { |
392 |
| - Set<ClusterMember> cores = cluster.cores(); |
393 |
| - for ( ClusterMember follower : cluster.followers() ) |
394 |
| - { |
395 |
| - cluster.stop( follower ); |
396 |
| - } |
397 |
| - awaitLeaderToStepDown( cores ); |
398 |
| - |
399 |
| - // now we should be unable to write because majority of cores is down |
400 |
| - for ( int i = 0; i < 10; i++ ) |
401 |
| - { |
402 |
| - assertThrows( SessionExpiredException.class, () -> |
403 |
| - { |
404 |
| - try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).build() ) ) |
405 |
| - { |
406 |
| - session.run( "CREATE (p:Person {name: 'Gamora'})" ).consume(); |
407 |
| - } |
408 |
| - } ); |
409 |
| - } |
410 |
| - } |
411 |
| - } |
412 |
| - |
413 |
| - @Test |
414 |
| - void shouldServeReadsWhenMajorityOfCoresAreDead() |
415 |
| - { |
416 |
| - Cluster cluster = clusterRule.getCluster(); |
417 |
| - ClusterMember leader = cluster.leader(); |
418 |
| - |
419 |
| - try ( Driver driver = createDriver( leader.getRoutingUri() ) ) |
420 |
| - { |
421 |
| - Bookmark bookmark; |
422 |
| - try ( Session session = driver.session() ) |
423 |
| - { |
424 |
| - int writeResult = session.writeTransaction( tx -> |
425 |
| - { |
426 |
| - Result result = tx.run( "CREATE (:Person {name: 'Star Lord'}) RETURN 42" ); |
427 |
| - return result.single().get( 0 ).asInt(); |
428 |
| - } ); |
429 |
| - |
430 |
| - assertEquals( 42, writeResult ); |
431 |
| - bookmark = session.lastBookmark(); |
432 |
| - } |
433 |
| - |
434 |
| - ensureNodeVisible( cluster, "Star Lord", bookmark ); |
435 |
| - |
436 |
| - Set<ClusterMember> cores = cluster.cores(); |
437 |
| - for ( ClusterMember follower : cluster.followers() ) |
438 |
| - { |
439 |
| - cluster.stop( follower ); |
440 |
| - } |
441 |
| - awaitLeaderToStepDown( cores ); |
442 |
| - |
443 |
| - // now we should be unable to write because majority of cores is down |
444 |
| - assertThrows( SessionExpiredException.class, () -> |
445 |
| - { |
446 |
| - try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).build() ) ) |
447 |
| - { |
448 |
| - session.run( "CREATE (p:Person {name: 'Gamora'})" ).consume(); |
449 |
| - } |
450 |
| - } ); |
451 |
| - |
452 |
| - // but we should be able to read from the remaining core or read replicas |
453 |
| - try ( Session session = driver.session() ) |
454 |
| - { |
455 |
| - int count = session.readTransaction( tx -> |
456 |
| - { |
457 |
| - Result result = tx.run( "MATCH (:Person {name: 'Star Lord'}) RETURN COUNT(*)" ); |
458 |
| - return result.single().get( 0 ).asInt(); |
459 |
| - } ); |
460 |
| - |
461 |
| - assertEquals( 1, count ); |
462 |
| - } |
463 |
| - } |
464 |
| - } |
465 |
| - |
466 | 329 | @Test
|
467 | 330 | void shouldAcceptMultipleBookmarks() throws Exception
|
468 | 331 | {
|
|
0 commit comments