Skip to content

Commit

Permalink
Use nanoseconds for Dropwizard timer snapshot mean (#1222)
Browse files Browse the repository at this point in the history
Closes gh-1161
  • Loading branch information
izeye authored and shakuzen committed Feb 13, 2019
1 parent 5a247f5 commit 12f9051
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public long getMax() {
@Override
public double getMean() {
double count = count();
return count == 0 ? 0 : totalTime(baseTimeUnit()) / count;
// This return value is expected to be in nanoseconds, for example in JmxReporter.JmxTimer.
return count == 0 ? 0 : totalTime(TimeUnit.NANOSECONDS) / count;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ void totalTimeWhenStateObjectChangedToNullShouldWorkWithChangedTimeUnit() {
assertThat(functionTimer.totalTime(TimeUnit.SECONDS)).isEqualTo(1d);
}

@Test
void getDropwizardMeterGetSnapshotGetMeanShouldReturnNanoseconds() {
DropwizardFunctionTimer functionTimer = new DropwizardFunctionTimer(
null, new MockClock(), new Object(), (o) -> 1L, (o) -> 1d, TimeUnit.SECONDS, TimeUnit.SECONDS);
assertThat(functionTimer.getDropwizardMeter().getSnapshot().getMean()).isEqualTo(1000_000_000d);
}

}

0 comments on commit 12f9051

Please sign in to comment.