File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Elasticsearch.Net/Connection
Tests/Nest.Tests.Integration/Exceptions Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ public class Transport : ITransport
3232 private readonly IConnectionPool _connectionPool ;
3333 private readonly IDateTimeProvider _dateTimeProvider ;
3434 private DateTime ? _lastSniff ;
35+ private bool _throwMaxRetry ;
3536
3637 public IConnectionConfigurationValues Settings { get { return ConfigurationValues ; } }
3738 public IElasticsearchSerializer Serializer { get { return _serializer ; } }
@@ -47,6 +48,7 @@ public Transport(
4748 this . Connection = connection ?? new HttpConnection ( configurationValues ) ;
4849 this . _serializer = serializer ?? new ElasticsearchDefaultSerializer ( ) ;
4950 this . _connectionPool = this . ConfigurationValues . ConnectionPool ;
51+ this . _throwMaxRetry = ! ( this . _connectionPool is SingleNodeConnectionPool ) ;
5052
5153 this . _dateTimeProvider = dateTimeProvider ?? new DateTimeProvider ( ) ;
5254
@@ -362,7 +364,11 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
362364 {
363365 requestState . SeenExceptions . Add ( e ) ;
364366 if ( maxRetries == 0 && retried == 0 )
365- throw ;
367+ {
368+ if ( _throwMaxRetry )
369+ new MaxRetryException ( e ) ;
370+ else throw ;
371+ }
366372 seenError = true ;
367373 return RetryRequest < T > ( requestState ) ;
368374 }
Original file line number Diff line number Diff line change @@ -105,8 +105,44 @@ public void WebException_WithThrowingClient_ThrowsMappedException()
105105 var e = Assert . Throws < ElasticsearchServerException > ( ( ) => client . Search < ElasticsearchProject > ( s => s . QueryRaw ( @"{ ""badjson"" : {} }" ) ) ) ;
106106 e . ExceptionType . Should ( ) . Contain ( "SearchPhaseExecutionException" ) ;
107107 }
108-
109-
108+
109+ [ Test ]
110+ public void ConnectionPool_SingleNode_PingExceptionThrowsMaxRetry ( )
111+ {
112+ var uris = new [ ]
113+ {
114+ ElasticsearchConfiguration . CreateBaseUri ( 9201 ) ,
115+ } ;
116+ var connectionPool = new StaticConnectionPool ( uris ) ;
117+ var client = new ElasticClient ( new ConnectionSettings ( connectionPool )
118+ . SetTimeout ( 1000 )
119+ ) ;
120+ var e = Assert . Throws < MaxRetryException > ( ( ) =>
121+ {
122+ var result = client . Search < ElasticsearchProject > ( s => s . MatchAll ( ) ) ;
123+ result . IsValid . Should ( ) . BeFalse ( ) ;
124+ } ) ;
125+ e . Should ( ) . NotBeNull ( ) ;
126+ }
127+
128+ [ Test ]
129+ public void ConnectionPool_SingleNode_PingExceptionThrowsMaxRetry_Async ( )
130+ {
131+ var uris = new [ ]
132+ {
133+ ElasticsearchConfiguration . CreateBaseUri ( 9201 ) ,
134+ } ;
135+ var connectionPool = new StaticConnectionPool ( uris ) ;
136+ var client = new ElasticClient ( new ConnectionSettings ( connectionPool )
137+ . SetTimeout ( 1000 )
138+ ) ;
139+ var e = Assert . Throws < MaxRetryException > ( async ( ) =>
140+ {
141+ var result = await client . SearchAsync < ElasticsearchProject > ( s => s . MatchAll ( ) ) ;
142+ result . IsValid . Should ( ) . BeFalse ( ) ;
143+ } ) ;
144+ e . Should ( ) . NotBeNull ( ) ;
145+ }
110146 [ Test ]
111147 public void ConnectionPool_DoesNotThrowOnServerExceptions_ThrowsMaxRetryException_OnDeadNodes ( )
112148 {
You can’t perform that action at this time.
0 commit comments