1818import net .jodah .failsafe .Testing .ConnectException ;
1919import net .jodah .failsafe .Testing .Service ;
2020import net .jodah .failsafe .function .*;
21+ import net .jodah .failsafe .util .concurrent .Scheduler ;
22+ import org .testng .annotations .AfterClass ;
2123import org .testng .annotations .BeforeMethod ;
2224import org .testng .annotations .Test ;
2325
3840
3941@ Test
4042public class AsyncFailsafeTest extends AbstractFailsafeTest {
41- private ScheduledExecutorService executor = Executors .newScheduledThreadPool (5 );
43+ private ExecutorService executor = Executors .newFixedThreadPool (5 );
4244
4345 // Results from a getAsync against a future that wraps an asynchronous Failsafe call
4446 private @ SuppressWarnings ("unchecked" ) Class <? extends Throwable >[] futureAsyncThrowables = new Class [] {
@@ -50,8 +52,13 @@ protected void beforeMethod() {
5052 counter = new AtomicInteger ();
5153 }
5254
55+ @ AfterClass
56+ protected void afterClass () {
57+ executor .shutdownNow ();
58+ }
59+
5360 @ Override
54- ScheduledExecutorService getExecutor () {
61+ ExecutorService getExecutor () {
5562 return executor ;
5663 }
5764
@@ -476,13 +483,14 @@ public void shouldHandleCompletedExceptionallyGetStageAsync() {
476483 * Asserts that asynchronous completion via an execution is supported.
477484 */
478485 public void shouldCompleteAsync () throws Throwable {
479- Failsafe .with (retryAlways ).runAsyncExecution (exec -> executor .schedule (() -> {
486+ Failsafe .with (retryAlways ).runAsyncExecution (exec -> Scheduler . DEFAULT .schedule (() -> {
480487 try {
481488 exec .complete ();
482489 waiter .resume ();
483490 } catch (Exception e ) {
484491 waiter .fail (e );
485492 }
493+ return null ;
486494 }, 100 , TimeUnit .MILLISECONDS ));
487495
488496 waiter .await (5000 );
@@ -573,12 +581,13 @@ public void shouldInterruptExecutionOnCancelWithForkJoinPool() throws Throwable
573581 }
574582
575583 public void shouldInterruptExecutionOnCancelWithScheduledExecutorService () throws Throwable {
576- assertInterruptedExceptionOnCancel (Failsafe .with (retryAlways ).with (executor ));
584+ ScheduledExecutorService executorService = Executors .newScheduledThreadPool (1 );
585+ assertInterruptedExceptionOnCancel (Failsafe .with (retryAlways ).with (executorService ));
586+ executorService .shutdownNow ();
577587 }
578588
579589 public void shouldInterruptExecutionOnCancelWithExecutorService () throws Throwable {
580- ExecutorService executorService = Executors .newSingleThreadScheduledExecutor ();
581- assertInterruptedExceptionOnCancel (Failsafe .with (retryAlways ).with (executorService ));
590+ assertInterruptedExceptionOnCancel (Failsafe .with (retryAlways ).with (executor ));
582591 }
583592
584593 @ SuppressWarnings ("unused" )
0 commit comments