From 53c6ed618293695b4c9a1acd9ab3017768183485 Mon Sep 17 00:00:00 2001 From: robsunday Date: Tue, 23 Jun 2026 19:30:41 +0200 Subject: [PATCH] Fixed build issue --- .../profiler/PeriodicRecordingFlusher.java | 13 +++++++++++-- .../profiler/PeriodicRecordingFlusherTest.java | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/profiler/src/main/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusher.java b/profiler/src/main/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusher.java index 9a9d6f89d..ae6c2f16e 100644 --- a/profiler/src/main/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusher.java +++ b/profiler/src/main/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusher.java @@ -31,15 +31,24 @@ class PeriodicRecordingFlusher { private static final Logger logger = Logger.getLogger(PeriodicRecordingFlusher.class.getName()); - private final ScheduledExecutorService executor = - HelpfulExecutors.newSingleThreadedScheduledExecutor("JFR Recording Flusher"); + private final ScheduledExecutorService executor; private final Duration recordingDuration; private final JfrRecorder recorder; private ScheduledFuture scheduledFlushFuture = null; PeriodicRecordingFlusher(JfrRecorder recorder, Duration recordingDuration) { + this( + recorder, + recordingDuration, + HelpfulExecutors.newSingleThreadedScheduledExecutor("JFR Recording Flusher")); + } + + @VisibleForTesting + PeriodicRecordingFlusher( + JfrRecorder recorder, Duration recordingDuration, ScheduledExecutorService executor) { this.recordingDuration = recordingDuration; this.recorder = recorder; + this.executor = executor; } public void start() { diff --git a/profiler/src/test/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusherTest.java b/profiler/src/test/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusherTest.java index 85b140dca..b8a13b87e 100644 --- a/profiler/src/test/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusherTest.java +++ b/profiler/src/test/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusherTest.java @@ -23,6 +23,9 @@ import java.time.Duration; import java.util.Collections; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -36,6 +39,8 @@ class PeriodicRecordingFlusherTest { @Mock JfrRecorder recorder; @Mock RecordingFileNamingConvention namingConvention; + @Mock ScheduledExecutorService executor; + @Mock ScheduledFuture scheduledFlushFuture; @Test void canContinueNotStarted() { @@ -66,15 +71,24 @@ void startThroughFlushSequence() throws Exception { @Test void stopCancelsScheduledFutureAndStopsRecorder() { - @SuppressWarnings("unchecked") - PeriodicRecordingFlusher recordingFlusher = buildRecordingFlusher(); + doReturn(scheduledFlushFuture) + .when(executor) + .scheduleAtFixedRate( + any(Runnable.class), eq(0L), eq(duration.toMillis()), eq(TimeUnit.MILLISECONDS)); + PeriodicRecordingFlusher recordingFlusher = + new PeriodicRecordingFlusher(recorder, duration, executor); recordingFlusher.start(); recordingFlusher.stop(); verify(recorder).start(); verify(recorder).stop(); + verify(executor) + .scheduleAtFixedRate( + any(Runnable.class), eq(0L), eq(duration.toMillis()), eq(TimeUnit.MILLISECONDS)); + verify(scheduledFlushFuture).cancel(false); verifyNoMoreInteractions(recorder); + verifyNoMoreInteractions(executor, scheduledFlushFuture); } private PeriodicRecordingFlusher buildRecordingFlusher() {