SparseTimeStat extends Bucketed<SparseTimeStat.Distribution> { public void add(long value, TimeUnit timeUnit) { add(timeUnit.toNanos(value)); } SparseTimeStat();  SparseTimeStat(Ticker ticker); void add(long value, TimeUnit timeUnit); void add(double value, TimeUnit timeUnit); void add(Duration duration); T time(Callable<T> callable); BlockTimer time();  }
@Test public void testInitialState() throws Exception { SparseTimeStat stat = new SparseTimeStat(); stat.add(1, NANOSECONDS); assertPreviousDistributionEmpty(stat); }
@Test public void testWithBucketIdProvider() throws Exception { SparseTimeStat stat = new SparseTimeStat(); stat.setBucketIdProvider(bucketIdProvider); stat.add(1, MILLISECONDS); assertPreviousDistributionEmpty(stat); ++bucketIdProvider.id; stat.add(new Duration(2, MILLISECONDS)); stat.add(3_000_000, NANOSECONDS); assertPreviousDistribution(stat, 1, .001, .001, .001); ++bucketIdProvider.id; assertPreviousDistribution(stat, 2, .002, .003, .005); }
@Test public void testDiscardsBuckets() throws Exception { SparseTimeStat distribution = new SparseTimeStat(); distribution.add(100, MILLISECONDS); distribution.setBucketIdProvider(bucketIdProvider); distribution.add(1, MILLISECONDS); assertPreviousDistributionEmpty(distribution); ++bucketIdProvider.id; distribution.add(2, MILLISECONDS); distribution.add(3, MILLISECONDS); assertPreviousDistribution(distribution, 1, .001, .001, .001); ++bucketIdProvider.id; ++bucketIdProvider.id; distribution.add(0.1, SECONDS); assertPreviousDistributionEmpty(distribution); ++bucketIdProvider.id; assertPreviousDistribution(distribution, 1, .1, .1, .1); distribution.add(0.2, SECONDS); ++bucketIdProvider.id; ++bucketIdProvider.id; assertPreviousDistributionEmpty(distribution); }