Skip to content

Commit 22b372b

Browse files
authored
Fixed build issue (#2899)
1 parent 6915330 commit 22b372b

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

profiler/src/main/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusher.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,24 @@
3131
class PeriodicRecordingFlusher {
3232
private static final Logger logger = Logger.getLogger(PeriodicRecordingFlusher.class.getName());
3333

34-
private final ScheduledExecutorService executor =
35-
HelpfulExecutors.newSingleThreadedScheduledExecutor("JFR Recording Flusher");
34+
private final ScheduledExecutorService executor;
3635
private final Duration recordingDuration;
3736
private final JfrRecorder recorder;
3837
private ScheduledFuture<?> scheduledFlushFuture = null;
3938

4039
PeriodicRecordingFlusher(JfrRecorder recorder, Duration recordingDuration) {
40+
this(
41+
recorder,
42+
recordingDuration,
43+
HelpfulExecutors.newSingleThreadedScheduledExecutor("JFR Recording Flusher"));
44+
}
45+
46+
@VisibleForTesting
47+
PeriodicRecordingFlusher(
48+
JfrRecorder recorder, Duration recordingDuration, ScheduledExecutorService executor) {
4149
this.recordingDuration = recordingDuration;
4250
this.recorder = recorder;
51+
this.executor = executor;
4352
}
4453

4554
public void start() {

profiler/src/test/java/com/splunk/opentelemetry/profiler/PeriodicRecordingFlusherTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import java.time.Duration;
2424
import java.util.Collections;
2525
import java.util.concurrent.CountDownLatch;
26+
import java.util.concurrent.ScheduledExecutorService;
27+
import java.util.concurrent.ScheduledFuture;
28+
import java.util.concurrent.TimeUnit;
2629
import java.util.function.Consumer;
2730
import org.junit.jupiter.api.Test;
2831
import 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

Comments
 (0)