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
32
32
private readonly IConnectionPool _connectionPool ;
33
33
private readonly IDateTimeProvider _dateTimeProvider ;
34
34
private DateTime ? _lastSniff ;
35
+ private bool _throwMaxRetry ;
35
36
36
37
public IConnectionConfigurationValues Settings { get { return ConfigurationValues ; } }
37
38
public IElasticsearchSerializer Serializer { get { return _serializer ; } }
@@ -47,6 +48,7 @@ public Transport(
47
48
this . Connection = connection ?? new HttpConnection ( configurationValues ) ;
48
49
this . _serializer = serializer ?? new ElasticsearchDefaultSerializer ( ) ;
49
50
this . _connectionPool = this . ConfigurationValues . ConnectionPool ;
51
+ this . _throwMaxRetry = ! ( this . _connectionPool is SingleNodeConnectionPool ) ;
50
52
51
53
this . _dateTimeProvider = dateTimeProvider ?? new DateTimeProvider ( ) ;
52
54
@@ -362,7 +364,11 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
362
364
{
363
365
requestState . SeenExceptions . Add ( e ) ;
364
366
if ( maxRetries == 0 && retried == 0 )
365
- throw ;
367
+ {
368
+ if ( _throwMaxRetry )
369
+ new MaxRetryException ( e ) ;
370
+ else throw ;
371
+ }
366
372
seenError = true ;
367
373
return RetryRequest < T > ( requestState ) ;
368
374
}
Original file line number Diff line number Diff line change @@ -105,8 +105,44 @@ public void WebException_WithThrowingClient_ThrowsMappedException()
105
105
var e = Assert . Throws < ElasticsearchServerException > ( ( ) => client . Search < ElasticsearchProject > ( s => s . QueryRaw ( @"{ ""badjson"" : {} }" ) ) ) ;
106
106
e . ExceptionType . Should ( ) . Contain ( "SearchPhaseExecutionException" ) ;
107
107
}
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
+ }
110
146
[ Test ]
111
147
public void ConnectionPool_DoesNotThrowOnServerExceptions_ThrowsMaxRetryException_OnDeadNodes ( )
112
148
{
You can’t perform that action at this time.
0 commit comments