@@ -316,7 +316,32 @@ protected Logger getLogger() {
316
316
public void testScheduleRetryAfterClose () throws Exception {
317
317
// This tests that once the listener has been closed, even the retries would not be scheduled.
318
318
final AtomicLong runCount = new AtomicLong ();
319
- ReleasableRetryableRefreshListener testRefreshListener = new ReleasableRetryableRefreshListener (threadPool ) {
319
+ ReleasableRetryableRefreshListener testRefreshListener = getRetryableRefreshListener (runCount );
320
+ Thread thread1 = new Thread (() -> {
321
+ try {
322
+ testRefreshListener .afterRefresh (true );
323
+ } catch (IOException e ) {
324
+ throw new AssertionError (e );
325
+ }
326
+ });
327
+ Thread thread2 = new Thread (() -> {
328
+ try {
329
+ Thread .sleep (500 );
330
+ testRefreshListener .drainRefreshes ();
331
+ } catch (InterruptedException e ) {
332
+ throw new AssertionError (e );
333
+ }
334
+ });
335
+ thread1 .start ();
336
+ thread2 .start ();
337
+ thread1 .join ();
338
+ thread2 .join ();
339
+ assertBusy (() -> assertEquals (1 , runCount .get ()));
340
+ assertRefreshListenerClosed (testRefreshListener );
341
+ }
342
+
343
+ private ReleasableRetryableRefreshListener getRetryableRefreshListener (AtomicLong runCount ) {
344
+ return new ReleasableRetryableRefreshListener (threadPool ) {
320
345
@ Override
321
346
protected boolean performAfterRefreshWithPermit (boolean didRefresh ) {
322
347
try {
@@ -341,6 +366,11 @@ protected String getRetryThreadPoolName() {
341
366
return ThreadPool .Names .REMOTE_REFRESH_RETRY ;
342
367
}
343
368
369
+ @ Override
370
+ protected boolean isRetryEnabled () {
371
+ return true ;
372
+ }
373
+
344
374
@ Override
345
375
protected TimeValue getNextRetryInterval () {
346
376
try {
@@ -351,6 +381,12 @@ protected TimeValue getNextRetryInterval() {
351
381
return TimeValue .timeValueMillis (100 );
352
382
}
353
383
};
384
+ }
385
+
386
+ public void testScheduleRetryAfterThreadpoolShutdown () throws Exception {
387
+ // This tests that once the thread-pool is shut down, the exception is handled.
388
+ final AtomicLong runCount = new AtomicLong ();
389
+ ReleasableRetryableRefreshListener testRefreshListener = getRetryableRefreshListener (runCount );
354
390
Thread thread1 = new Thread (() -> {
355
391
try {
356
392
testRefreshListener .afterRefresh (true );
@@ -361,7 +397,7 @@ protected TimeValue getNextRetryInterval() {
361
397
Thread thread2 = new Thread (() -> {
362
398
try {
363
399
Thread .sleep (500 );
364
- testRefreshListener . drainRefreshes ();
400
+ threadPool . shutdown ();
365
401
} catch (InterruptedException e ) {
366
402
throw new AssertionError (e );
367
403
}
@@ -371,7 +407,7 @@ protected TimeValue getNextRetryInterval() {
371
407
thread1 .join ();
372
408
thread2 .join ();
373
409
assertBusy (() -> assertEquals (1 , runCount .get ()));
374
- assertRefreshListenerClosed (testRefreshListener );
410
+ assertFalse (testRefreshListener . getRetryScheduledStatus () );
375
411
}
376
412
377
413
public void testConcurrentScheduleRetry () throws Exception {
0 commit comments