diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowMax.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowMax.java index de3d74756c..536cbb14a3 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowMax.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowMax.java @@ -131,7 +131,7 @@ private void rotate() { try { synchronized (this) { if (timeSinceLastRotateMillis >= durationBetweenRotatesMillis * ringBuffer.length) { - // it past too many time since this instance was used, we can just cleare + // time since last rotation is enough to clear whole ring buffer for (AtomicLong bufferItem: ringBuffer) { bufferItem.set(0); } diff --git a/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/TimeWindowMaxTest.java b/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/TimeWindowMaxTest.java index 122ed36c31..a3e53470e7 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/TimeWindowMaxTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/TimeWindowMaxTest.java @@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for {@link TimeWindowMax} @@ -48,24 +47,23 @@ void decaysToZero() { } @Test - void testLongPeriaOfInactivity() { + void testLongPeriodOfInactivity() { timeWindowMax = new TimeWindowMax(clock, 60_000, 3); timeWindowMax.record(32); - System.out.println(timeWindowMax.poll()); // prints 32 + assertThat(timeWindowMax.poll()).isEqualTo(32); // 0 | 0 | 32 - // emulate 12 hours of inactivity clock.add(Duration.ofHours(12)); - assertEquals(0.0, timeWindowMax.poll()); + assertThat(timeWindowMax.poll()).isZero(); // 0 | 0 | 0 timeWindowMax.record(666); - assertEquals(666, timeWindowMax.poll()); + assertThat(timeWindowMax.poll()).isEqualTo(666); // 0 | 0 | 666 clock.add(Duration.ofSeconds(62)); timeWindowMax.record(500); - assertEquals(666, timeWindowMax.poll()); + assertThat(timeWindowMax.poll()).isEqualTo(666); // 0 | 666 | 500 clock.add(Duration.ofSeconds(62)); timeWindowMax.record(100500); - assertEquals(100500, timeWindowMax.poll()); + assertThat(timeWindowMax.poll()).isEqualTo(100500); // 666 | 500 | 100500 } }