Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ private Histogram latestHistogram(long now) {
}

/**
* Writes to the histogram. Caps recording to highestTrackableValue
* Writes to the histogram. Caps recording between 0 and highestTrackableValue.
*
* @param value The value to be recorded. Cannot be negative.
* @param value The value to be recorded.
*/
public void record(long value) {
recorder.recordValue(Math.min(value, highestTrackableValue));
recorder.recordValue(Math.min(Math.max(value, 0), highestTrackableValue));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,14 @@ public void testLatestHistogramRace() throws InterruptedException, ExecutionExce

@Test
public void testRecordLimit() {
long now = System.currentTimeMillis();
long highestTrackableValue = 10L;
HdrHistogram hdrHistogram = new HdrHistogram(10L, highestTrackableValue, 3);

hdrHistogram.record(highestTrackableValue + 1000L);
assertEquals(highestTrackableValue, hdrHistogram.max(System.currentTimeMillis()));
assertEquals(highestTrackableValue, hdrHistogram.max(now));

hdrHistogram.record(-50L);
assertEquals(0, hdrHistogram.max(now + 1000L));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no histogram min method. We can add one, but it'd be only used in this one test.

}
}