12
12
import org .elasticsearch .common .unit .ByteSizeUnit ;
13
13
import org .elasticsearch .common .unit .ByteSizeValue ;
14
14
import org .elasticsearch .common .unit .TimeValue ;
15
+ import org .elasticsearch .common .util .concurrent .EsRejectedExecutionException ;
15
16
import org .elasticsearch .index .seqno .SequenceNumbers ;
16
17
import org .elasticsearch .index .shard .ShardId ;
17
18
import org .elasticsearch .index .shard .ShardNotFoundException ;
@@ -257,8 +258,16 @@ public void testReceiveRetryableError() {
257
258
startTask (task , 63 , -1 );
258
259
259
260
int max = randomIntBetween (1 , 30 );
261
+ final Exception [] exceptions = new Exception [max ];
260
262
for (int i = 0 ; i < max ; i ++) {
261
- readFailures .add (new ShardNotFoundException (new ShardId ("leader_index" , "" , 0 )));
263
+ final Exception exception ;
264
+ if (randomBoolean ()) {
265
+ exception = new ShardNotFoundException (new ShardId ("leader_index" , "" , 0 ));
266
+ } else {
267
+ exception = new EsRejectedExecutionException ("leader_index rejected" );
268
+ }
269
+ exceptions [i ] = exception ;
270
+ readFailures .add (exception );
262
271
}
263
272
mappingVersions .add (1L );
264
273
leaderGlobalCheckpoints .add (63L );
@@ -274,10 +283,17 @@ public void testReceiveRetryableError() {
274
283
final Map .Entry <Long , Tuple <Integer , ElasticsearchException >> entry = status .readExceptions ().entrySet ().iterator ().next ();
275
284
assertThat (entry .getValue ().v1 (), equalTo (Math .toIntExact (retryCounter .get ())));
276
285
assertThat (entry .getKey (), equalTo (0L ));
277
- assertThat (entry .getValue ().v2 (), instanceOf (ShardNotFoundException .class ));
278
- final ShardNotFoundException shardNotFoundException = (ShardNotFoundException ) entry .getValue ().v2 ();
279
- assertThat (shardNotFoundException .getShardId ().getIndexName (), equalTo ("leader_index" ));
280
- assertThat (shardNotFoundException .getShardId ().getId (), equalTo (0 ));
286
+ if (exceptions [Math .toIntExact (retryCounter .get ()) - 1 ] instanceof ShardNotFoundException ) {
287
+ assertThat (entry .getValue ().v2 (), instanceOf (ShardNotFoundException .class ));
288
+ final ShardNotFoundException shardNotFoundException = (ShardNotFoundException ) entry .getValue ().v2 ();
289
+ assertThat (shardNotFoundException .getShardId ().getIndexName (), equalTo ("leader_index" ));
290
+ assertThat (shardNotFoundException .getShardId ().getId (), equalTo (0 ));
291
+ } else {
292
+ assertThat (entry .getValue ().v2 ().getCause (), instanceOf (EsRejectedExecutionException .class ));
293
+ final EsRejectedExecutionException rejectedExecutionException =
294
+ (EsRejectedExecutionException ) entry .getValue ().v2 ().getCause ();
295
+ assertThat (rejectedExecutionException .getMessage (), equalTo ("leader_index rejected" ));
296
+ }
281
297
}
282
298
retryCounter .incrementAndGet ();
283
299
};
0 commit comments