@@ -1657,6 +1657,86 @@ describe('#unit RoutingConnectionProvider', () => {
1657
1657
} )
1658
1658
} , 10000 )
1659
1659
1660
+ describe ( 'when rediscovery.lookupRoutingTableOnRouter fails' , ( ) => {
1661
+ describe . each ( [
1662
+ 'Neo.ClientError.Database.DatabaseNotFound' ,
1663
+ 'Neo.ClientError.Transaction.InvalidBookmark' ,
1664
+ 'Neo.ClientError.Transaction.InvalidBookmarkMixture' ,
1665
+ 'Neo.ClientError.Security.Forbidden' ,
1666
+ 'Neo.ClientError.Security.IWontTellYou'
1667
+ ] ) ( 'with "%s"' , errorCode => {
1668
+ it ( 'should fail without change the error ' , async ( ) => {
1669
+ const error = newError ( 'something wrong' , errorCode )
1670
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1671
+ new FakeRediscovery ( null , error ) ,
1672
+ newPool ( )
1673
+ )
1674
+
1675
+ let completed = false
1676
+ try {
1677
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1678
+ completed = true
1679
+ } catch ( capturedError ) {
1680
+ expect ( capturedError ) . toBe ( error )
1681
+ }
1682
+
1683
+ expect ( completed ) . toBe ( false )
1684
+ } )
1685
+ } )
1686
+
1687
+ describe ( 'with "Neo.ClientError.Procedure.ProcedureNotFound"' , ( ) => {
1688
+ it ( 'should fail with SERVICE_UNAVAILABLE and a message about do not connect to cause cluster' , async ( ) => {
1689
+ const error = newError ( 'something wrong' , 'Neo.ClientError.Procedure.ProcedureNotFound' )
1690
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1691
+ new FakeRediscovery ( null , error ) ,
1692
+ newPool ( )
1693
+ )
1694
+
1695
+ let completed = false
1696
+ try {
1697
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1698
+ completed = true
1699
+ } catch ( capturedError ) {
1700
+ expect ( capturedError . code ) . toBe ( SERVICE_UNAVAILABLE )
1701
+ expect ( capturedError . message ) . toBe (
1702
+ 'Server at server-non-existing-seed-router:7687 can\'t '
1703
+ + 'perform routing. Make sure you are connecting to a causal cluster'
1704
+ )
1705
+ }
1706
+
1707
+ expect ( completed ) . toBe ( false )
1708
+ } )
1709
+ } )
1710
+
1711
+ describe . each ( [
1712
+ 'Neo.ClientError.Security.AuthorizationExpired' ,
1713
+ 'Neo.ClientError.MadeUp.Error'
1714
+ ] ) ( 'with "%s"' , errorCode => {
1715
+ it ( 'should fail with SERVICE_UNAVAILABLE and message about no routing servers available ' , async ( ) => {
1716
+ const error = newError ( 'something wrong' , errorCode )
1717
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1718
+ new FakeRediscovery ( null , error ) ,
1719
+ newPool ( )
1720
+ )
1721
+
1722
+ let completed = false
1723
+ try {
1724
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1725
+ completed = true
1726
+ } catch ( capturedError ) {
1727
+ expect ( capturedError . code ) . toBe ( SERVICE_UNAVAILABLE )
1728
+ expect ( capturedError . message ) . toEqual ( expect . stringContaining (
1729
+ 'Could not perform discovery. ' +
1730
+ 'No routing servers available. Known routing table: '
1731
+ ) )
1732
+ }
1733
+
1734
+ expect ( completed ) . toBe ( false )
1735
+ } )
1736
+
1737
+ } )
1738
+ } )
1739
+
1660
1740
describe ( 'multi-database' , ( ) => {
1661
1741
it . each ( usersDataSet ) ( 'should acquire read connection from correct routing table [user=%s]' , async ( user ) => {
1662
1742
const pool = newPool ( )
@@ -2491,13 +2571,31 @@ function newRoutingConnectionProvider (
2491
2571
)
2492
2572
}
2493
2573
2574
+ function newRoutingConnectionProviderWithFakeRediscovery (
2575
+ fakeRediscovery ,
2576
+ pool = null ,
2577
+ routerToRoutingTable = { null : { } }
2578
+ ) {
2579
+ const seedRouter = ServerAddress . fromUrl ( 'server-non-existing-seed-router' )
2580
+ return newRoutingConnectionProviderWithSeedRouter (
2581
+ seedRouter ,
2582
+ [ seedRouter ] ,
2583
+ [ ] ,
2584
+ routerToRoutingTable ,
2585
+ pool ,
2586
+ null ,
2587
+ fakeRediscovery
2588
+ )
2589
+ }
2590
+
2494
2591
function newRoutingConnectionProviderWithSeedRouter (
2495
2592
seedRouter ,
2496
2593
seedRouterResolved ,
2497
2594
routingTables ,
2498
2595
routerToRoutingTable = { null : { } } ,
2499
2596
connectionPool = null ,
2500
- routingTablePurgeDelay = null
2597
+ routingTablePurgeDelay = null ,
2598
+ fakeRediscovery = null
2501
2599
) {
2502
2600
const pool = connectionPool || newPool ( )
2503
2601
const connectionProvider = new RoutingConnectionProvider ( {
@@ -2513,7 +2611,8 @@ function newRoutingConnectionProviderWithSeedRouter (
2513
2611
routingTables . forEach ( r => {
2514
2612
connectionProvider . _routingTableRegistry . register ( r )
2515
2613
} )
2516
- connectionProvider . _rediscovery = new FakeRediscovery ( routerToRoutingTable )
2614
+ connectionProvider . _rediscovery =
2615
+ fakeRediscovery || new FakeRediscovery ( routerToRoutingTable )
2517
2616
connectionProvider . _hostNameResolver = new FakeDnsResolver ( seedRouterResolved )
2518
2617
connectionProvider . _useSeedRouter = routingTables . every (
2519
2618
r => r . expirationTime !== Integer . ZERO
@@ -2630,11 +2729,15 @@ class FakeConnection extends Connection {
2630
2729
}
2631
2730
2632
2731
class FakeRediscovery {
2633
- constructor ( routerToRoutingTable ) {
2732
+ constructor ( routerToRoutingTable , error ) {
2634
2733
this . _routerToRoutingTable = routerToRoutingTable
2734
+ this . _error = error
2635
2735
}
2636
2736
2637
2737
lookupRoutingTableOnRouter ( ignored , database , router , user ) {
2738
+ if ( this . _error ) {
2739
+ return Promise . reject ( this . _error )
2740
+ }
2638
2741
const table = this . _routerToRoutingTable [ database || null ]
2639
2742
if ( table ) {
2640
2743
let routingTables = table [ router . asKey ( ) ]
0 commit comments