|
24 | 24 | import io.micrometer.core.instrument.internal.DefaultLongTaskTimer;
|
25 | 25 | import io.micrometer.core.instrument.simple.SimpleConfig;
|
26 | 26 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
27 |
| -import org.junit.jupiter.api.DisplayName; |
28 |
| -import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +import java.io.ByteArrayOutputStream; |
| 29 | + |
| 30 | +import java.io.PrintStream; |
| 31 | + |
| 32 | +import org.junit.jupiter.api.*; |
29 | 33 |
|
30 | 34 | import java.time.Duration;
|
31 | 35 | import java.util.Arrays;
|
32 | 36 | import java.util.List;
|
33 | 37 | import java.util.concurrent.TimeUnit;
|
34 | 38 |
|
35 | 39 | import static io.micrometer.core.instrument.MockClock.clock;
|
36 |
| -import static org.assertj.core.api.Assertions.assertThat; |
| 40 | +import static org.assertj.core.api.Assertions.*; |
37 | 41 |
|
38 | 42 | public class DefaultLongTaskTimerTest {
|
39 | 43 |
|
| 44 | + final ByteArrayOutputStream myErr = new ByteArrayOutputStream(); |
| 45 | + |
| 46 | + @BeforeEach |
| 47 | + void setup() { |
| 48 | + System.setErr(new PrintStream(myErr)); |
| 49 | + } |
| 50 | + |
| 51 | + @AfterAll |
| 52 | + static void cleanup() { |
| 53 | + System.setErr(System.err); |
| 54 | + } |
| 55 | + |
40 | 56 | @Test
|
41 | 57 | @DisplayName("supports sending histograms of active task duration")
|
42 | 58 | void histogram() {
|
@@ -97,4 +113,29 @@ protected LongTaskTimer newLongTaskTimer(Meter.Id id,
|
97 | 113 | }
|
98 | 114 | }
|
99 | 115 |
|
| 116 | + @Test |
| 117 | + void histogramToStringNotThrowingException() throws InterruptedException { |
| 118 | + SimpleMeterRegistry simpleMeterRegistry = new SimpleMeterRegistry(); |
| 119 | + |
| 120 | + LongTaskTimer timer = LongTaskTimer.builder("jobrunr.jobs") |
| 121 | + .publishPercentiles(0.25, 0.5, 0.75, 0.8, 0.9, 0.95) |
| 122 | + .publishPercentileHistogram() |
| 123 | + .register(simpleMeterRegistry); |
| 124 | + LongTaskTimer.Sample start = timer.start(); |
| 125 | + Thread.sleep(10); |
| 126 | + |
| 127 | + assertThatNoException().isThrownBy(() -> { |
| 128 | + simpleMeterRegistry.getMetersAsString(); |
| 129 | + String standardOutput = myErr.toString(); |
| 130 | + assertThat(standardOutput).doesNotContain("ArrayIndexOutOfBoundsException"); |
| 131 | + }); |
| 132 | + |
| 133 | + assertThatNoException().isThrownBy(() -> { |
| 134 | + start.stop(); |
| 135 | + simpleMeterRegistry.getMetersAsString(); |
| 136 | + String standardOutput = myErr.toString(); |
| 137 | + assertThat(standardOutput).doesNotContain("ArrayIndexOutOfBoundsException"); |
| 138 | + }); |
| 139 | + } |
| 140 | + |
100 | 141 | }
|
0 commit comments