|
43 | 43 | import org.neo4j.driver.v1.GraphDatabase;
|
44 | 44 | import org.neo4j.driver.v1.Record;
|
45 | 45 | import org.neo4j.driver.v1.Session;
|
| 46 | +import org.neo4j.driver.v1.Transaction; |
46 | 47 | import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
|
47 | 48 | import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
|
48 | 49 | import org.neo4j.driver.v1.exceptions.SessionExpiredException;
|
@@ -521,6 +522,103 @@ public void shouldHandleLeaderSwitchWhenWriting()
|
521 | 522 | assertThat( server.exitStatus(), equalTo( 0 ) );
|
522 | 523 | }
|
523 | 524 |
|
| 525 | + @Test |
| 526 | + public void shouldHandleLeaderSwitchWhenWritingWithoutConsuming() |
| 527 | + throws IOException, InterruptedException, StubServer.ForceKilled |
| 528 | + { |
| 529 | + // Given |
| 530 | + StubServer server = StubServer.start( "acquire_endpoints.script", 9001 ); |
| 531 | + |
| 532 | + //START a write server that doesn't accept writes |
| 533 | + StubServer.start( "not_able_to_write_server.script", 9007 ); |
| 534 | + URI uri = URI.create( "bolt+routing://127.0.0.1:9001" ); |
| 535 | + RoutingDriver driver = (RoutingDriver) GraphDatabase.driver( uri, config ); |
| 536 | + boolean failed = false; |
| 537 | + try ( Session session = driver.session( AccessMode.WRITE ) ) |
| 538 | + { |
| 539 | + assertThat( driver.writeServers(), hasItem(address( 9007 ) ) ); |
| 540 | + assertThat( driver.writeServers(), hasItem( address( 9008 ) ) ); |
| 541 | + session.run( "CREATE ()" ); |
| 542 | + } |
| 543 | + catch ( SessionExpiredException e ) |
| 544 | + { |
| 545 | + failed = true; |
| 546 | + assertThat( e.getMessage(), equalTo( "Server at 127.0.0.1:9007 no longer accepts writes" ) ); |
| 547 | + } |
| 548 | + assertTrue( failed ); |
| 549 | + assertThat( driver.writeServers(), not( hasItem( address( 9007 ) ) ) ); |
| 550 | + assertThat( driver.writeServers(), hasItem( address( 9008 ) ) ); |
| 551 | + assertTrue( driver.connectionPool().hasAddress( address( 9007 ) ) ); |
| 552 | + |
| 553 | + driver.close(); |
| 554 | + // Finally |
| 555 | + assertThat( server.exitStatus(), equalTo( 0 ) ); |
| 556 | + } |
| 557 | + |
| 558 | + @Ignore |
| 559 | + public void shouldHandleLeaderSwitchWhenWritingInTransaction() |
| 560 | + throws IOException, InterruptedException, StubServer.ForceKilled |
| 561 | + { |
| 562 | + // Given |
| 563 | + StubServer server = StubServer.start( "acquire_endpoints.script", 9001 ); |
| 564 | + |
| 565 | + //START a write server that doesn't accept writes |
| 566 | + StubServer.start( "not_able_to_write_server.script", 9007 ); |
| 567 | + URI uri = URI.create( "bolt+routing://127.0.0.1:9001" ); |
| 568 | + RoutingDriver driver = (RoutingDriver) GraphDatabase.driver( uri, config ); |
| 569 | + boolean failed = false; |
| 570 | + try ( Session session = driver.session( AccessMode.WRITE ); |
| 571 | + Transaction tx = session.beginTransaction() ) |
| 572 | + { |
| 573 | + tx.run( "CREATE ()" ).consume(); |
| 574 | + } |
| 575 | + catch ( SessionExpiredException e ) |
| 576 | + { |
| 577 | + failed = true; |
| 578 | + assertThat( e.getMessage(), equalTo( "Server at 127.0.0.1:9007 no longer accepts writes" ) ); |
| 579 | + } |
| 580 | + assertTrue( failed ); |
| 581 | + assertThat( driver.writeServers(), not( hasItem( address( 9007 ) ) ) ); |
| 582 | + assertThat( driver.writeServers(), hasItem( address( 9008 ) ) ); |
| 583 | + assertTrue( driver.connectionPool().hasAddress( address( 9007 ) ) ); |
| 584 | + |
| 585 | + driver.close(); |
| 586 | + // Finally |
| 587 | + assertThat( server.exitStatus(), equalTo( 0 ) ); |
| 588 | + } |
| 589 | + |
| 590 | + @Ignore |
| 591 | + public void shouldHandleLeaderSwitchWhenWritingInTransactionWithoutConsuming() |
| 592 | + throws IOException, InterruptedException, StubServer.ForceKilled |
| 593 | + { |
| 594 | + // Given |
| 595 | + StubServer server = StubServer.start( "acquire_endpoints.script", 9001 ); |
| 596 | + |
| 597 | + //START a write server that doesn't accept writes |
| 598 | + StubServer.start( "not_able_to_write_server.script", 9007 ); |
| 599 | + URI uri = URI.create( "bolt+routing://127.0.0.1:9001" ); |
| 600 | + RoutingDriver driver = (RoutingDriver) GraphDatabase.driver( uri, config ); |
| 601 | + boolean failed = false; |
| 602 | + try ( Session session = driver.session( AccessMode.WRITE ); |
| 603 | + Transaction tx = session.beginTransaction() ) |
| 604 | + { |
| 605 | + tx.run( "CREATE ()" ); |
| 606 | + } |
| 607 | + catch ( SessionExpiredException e ) |
| 608 | + { |
| 609 | + failed = true; |
| 610 | + assertThat( e.getMessage(), equalTo( "Server at 127.0.0.1:9007 no longer accepts writes" ) ); |
| 611 | + } |
| 612 | + assertTrue( failed ); |
| 613 | + assertThat( driver.writeServers(), not( hasItem( address( 9007 ) ) ) ); |
| 614 | + assertThat( driver.writeServers(), hasItem( address( 9008 ) ) ); |
| 615 | + assertTrue( driver.connectionPool().hasAddress( address( 9007 ) ) ); |
| 616 | + |
| 617 | + driver.close(); |
| 618 | + // Finally |
| 619 | + assertThat( server.exitStatus(), equalTo( 0 ) ); |
| 620 | + } |
| 621 | + |
524 | 622 | @Test
|
525 | 623 | public void shouldRediscoverOnExpiry() throws IOException, InterruptedException, StubServer.ForceKilled
|
526 | 624 | {
|
@@ -589,7 +687,7 @@ public void shouldNotPutBackPurgedConnection() throws IOException, InterruptedEx
|
589 | 687 |
|
590 | 688 | // now we close the read session and the connection should not be put
|
591 | 689 | // back to the pool
|
592 |
| - Connection connection = ((RoutingNetworkSession) readSession).connection; |
| 690 | + Connection connection = ((NetworkSession) ((RoutingNetworkSession) readSession).delegate).connection; |
593 | 691 | assertTrue( connection.isOpen() );
|
594 | 692 | readSession.close();
|
595 | 693 | assertFalse( connection.isOpen() );
|
|
0 commit comments