@@ -1658,6 +1658,86 @@ describe('#unit RoutingConnectionProvider', () => {
1658
1658
} )
1659
1659
} , 10000 )
1660
1660
1661
+ describe ( 'when rediscovery.lookupRoutingTableOnRouter fails' , ( ) => {
1662
+ describe . each ( [
1663
+ 'Neo.ClientError.Database.DatabaseNotFound' ,
1664
+ 'Neo.ClientError.Transaction.InvalidBookmark' ,
1665
+ 'Neo.ClientError.Transaction.InvalidBookmarkMixture' ,
1666
+ 'Neo.ClientError.Security.Forbidden' ,
1667
+ 'Neo.ClientError.Security.IWontTellYou'
1668
+ ] ) ( 'with "%s"' , errorCode => {
1669
+ it ( 'should fail without change the error ' , async ( ) => {
1670
+ const error = newError ( 'something wrong' , errorCode )
1671
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1672
+ new FakeRediscovery ( null , error ) ,
1673
+ newPool ( )
1674
+ )
1675
+
1676
+ let completed = false
1677
+ try {
1678
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1679
+ completed = true
1680
+ } catch ( capturedError ) {
1681
+ expect ( capturedError ) . toBe ( error )
1682
+ }
1683
+
1684
+ expect ( completed ) . toBe ( false )
1685
+ } )
1686
+ } )
1687
+
1688
+ describe ( 'with "Neo.ClientError.Procedure.ProcedureNotFound"' , ( ) => {
1689
+ it ( 'should fail with SERVICE_UNAVAILABLE and a message about do not connect to cause cluster' , async ( ) => {
1690
+ const error = newError ( 'something wrong' , 'Neo.ClientError.Procedure.ProcedureNotFound' )
1691
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1692
+ new FakeRediscovery ( null , error ) ,
1693
+ newPool ( )
1694
+ )
1695
+
1696
+ let completed = false
1697
+ try {
1698
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1699
+ completed = true
1700
+ } catch ( capturedError ) {
1701
+ expect ( capturedError . code ) . toBe ( SERVICE_UNAVAILABLE )
1702
+ expect ( capturedError . message ) . toBe (
1703
+ 'Server at server-non-existing-seed-router:7687 can\'t '
1704
+ + 'perform routing. Make sure you are connecting to a causal cluster'
1705
+ )
1706
+ }
1707
+
1708
+ expect ( completed ) . toBe ( false )
1709
+ } )
1710
+ } )
1711
+
1712
+ describe . each ( [
1713
+ 'Neo.ClientError.Security.AuthorizationExpired' ,
1714
+ 'Neo.ClientError.MadeUp.Error'
1715
+ ] ) ( 'with "%s"' , errorCode => {
1716
+ it ( 'should fail with SERVICE_UNAVAILABLE and message about no routing servers available ' , async ( ) => {
1717
+ const error = newError ( 'something wrong' , errorCode )
1718
+ const connectionProvider = newRoutingConnectionProviderWithFakeRediscovery (
1719
+ new FakeRediscovery ( null , error ) ,
1720
+ newPool ( )
1721
+ )
1722
+
1723
+ let completed = false
1724
+ try {
1725
+ await connectionProvider . acquireConnection ( { accessMode : READ } )
1726
+ completed = true
1727
+ } catch ( capturedError ) {
1728
+ expect ( capturedError . code ) . toBe ( SERVICE_UNAVAILABLE )
1729
+ expect ( capturedError . message ) . toEqual ( expect . stringContaining (
1730
+ 'Could not perform discovery. ' +
1731
+ 'No routing servers available. Known routing table: '
1732
+ ) )
1733
+ }
1734
+
1735
+ expect ( completed ) . toBe ( false )
1736
+ } )
1737
+
1738
+ } )
1739
+ } )
1740
+
1661
1741
describe ( 'multi-database' , ( ) => {
1662
1742
it . each ( usersDataSet ) ( 'should acquire read connection from correct routing table [user=%s]' , async ( user ) => {
1663
1743
const pool = newPool ( )
@@ -2843,13 +2923,31 @@ function newRoutingConnectionProvider (
2843
2923
)
2844
2924
}
2845
2925
2926
+ function newRoutingConnectionProviderWithFakeRediscovery (
2927
+ fakeRediscovery ,
2928
+ pool = null ,
2929
+ routerToRoutingTable = { null : { } }
2930
+ ) {
2931
+ const seedRouter = ServerAddress . fromUrl ( 'server-non-existing-seed-router' )
2932
+ return newRoutingConnectionProviderWithSeedRouter (
2933
+ seedRouter ,
2934
+ [ seedRouter ] ,
2935
+ [ ] ,
2936
+ routerToRoutingTable ,
2937
+ pool ,
2938
+ null ,
2939
+ fakeRediscovery
2940
+ )
2941
+ }
2942
+
2846
2943
function newRoutingConnectionProviderWithSeedRouter (
2847
2944
seedRouter ,
2848
2945
seedRouterResolved ,
2849
2946
routingTables ,
2850
2947
routerToRoutingTable = { null : { } } ,
2851
2948
connectionPool = null ,
2852
- routingTablePurgeDelay = null
2949
+ routingTablePurgeDelay = null ,
2950
+ fakeRediscovery = null
2853
2951
) {
2854
2952
const pool = connectionPool || newPool ( )
2855
2953
const connectionProvider = new RoutingConnectionProvider ( {
@@ -2865,7 +2963,8 @@ function newRoutingConnectionProviderWithSeedRouter (
2865
2963
routingTables . forEach ( r => {
2866
2964
connectionProvider . _routingTableRegistry . register ( r )
2867
2965
} )
2868
- connectionProvider . _rediscovery = new FakeRediscovery ( routerToRoutingTable )
2966
+ connectionProvider . _rediscovery =
2967
+ fakeRediscovery || new FakeRediscovery ( routerToRoutingTable )
2869
2968
connectionProvider . _hostNameResolver = new FakeDnsResolver ( seedRouterResolved )
2870
2969
connectionProvider . _useSeedRouter = routingTables . every (
2871
2970
r => r . expirationTime !== Integer . ZERO
@@ -2999,11 +3098,15 @@ class FakeConnection extends Connection {
2999
3098
}
3000
3099
3001
3100
class FakeRediscovery {
3002
- constructor ( routerToRoutingTable ) {
3101
+ constructor ( routerToRoutingTable , error ) {
3003
3102
this . _routerToRoutingTable = routerToRoutingTable
3103
+ this . _error = error
3004
3104
}
3005
3105
3006
3106
lookupRoutingTableOnRouter ( ignored , database , router , user ) {
3107
+ if ( this . _error ) {
3108
+ return Promise . reject ( this . _error )
3109
+ }
3007
3110
const table = this . _routerToRoutingTable [ database || null ]
3008
3111
if ( table ) {
3009
3112
let routingTables = table [ router . asKey ( ) ]
0 commit comments