2323import java .time .Duration ;
2424import java .util .Collections ;
2525import java .util .concurrent .CountDownLatch ;
26+ import java .util .concurrent .ScheduledExecutorService ;
27+ import java .util .concurrent .ScheduledFuture ;
28+ import java .util .concurrent .TimeUnit ;
2629import java .util .function .Consumer ;
2730import org .junit .jupiter .api .Test ;
2831import org .junit .jupiter .api .extension .ExtendWith ;
@@ -36,6 +39,8 @@ class PeriodicRecordingFlusherTest {
3639
3740 @ Mock JfrRecorder recorder ;
3841 @ Mock RecordingFileNamingConvention namingConvention ;
42+ @ Mock ScheduledExecutorService executor ;
43+ @ Mock ScheduledFuture <?> scheduledFlushFuture ;
3944
4045 @ Test
4146 void canContinueNotStarted () {
@@ -66,15 +71,24 @@ void startThroughFlushSequence() throws Exception {
6671
6772 @ Test
6873 void stopCancelsScheduledFutureAndStopsRecorder () {
69- @ SuppressWarnings ("unchecked" )
70- PeriodicRecordingFlusher recordingFlusher = buildRecordingFlusher ();
74+ doReturn (scheduledFlushFuture )
75+ .when (executor )
76+ .scheduleAtFixedRate (
77+ any (Runnable .class ), eq (0L ), eq (duration .toMillis ()), eq (TimeUnit .MILLISECONDS ));
78+ PeriodicRecordingFlusher recordingFlusher =
79+ new PeriodicRecordingFlusher (recorder , duration , executor );
7180
7281 recordingFlusher .start ();
7382 recordingFlusher .stop ();
7483
7584 verify (recorder ).start ();
7685 verify (recorder ).stop ();
86+ verify (executor )
87+ .scheduleAtFixedRate (
88+ any (Runnable .class ), eq (0L ), eq (duration .toMillis ()), eq (TimeUnit .MILLISECONDS ));
89+ verify (scheduledFlushFuture ).cancel (false );
7790 verifyNoMoreInteractions (recorder );
91+ verifyNoMoreInteractions (executor , scheduledFlushFuture );
7892 }
7993
8094 private PeriodicRecordingFlusher buildRecordingFlusher () {
0 commit comments