Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Aug 25, 2021
1 parent 9cf7c93 commit 1010ab9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
}
}

0 comments on commit 1010ab9

Please sign in to comment.