BucketedDistribution extends Bucketed<BucketedDistribution.Distribution> { public void add(final long value) { applyToCurrentBucket((Function<Distribution, Void>) input -> { synchronized (input) { input.digest.add(value); input.total += value; } return null; }); }  void add(final long value);  }
@Test public void testInitialState() throws Exception { BucketedDistribution distribution = new BucketedDistribution(); distribution.add(1); assertPreviousDistributionEmpty(distribution); }
@Test public void testWithBucketIdProvider() throws Exception { BucketedDistribution distribution = new BucketedDistribution(); distribution.setBucketIdProvider(bucketIdProvider); distribution.add(1); assertPreviousDistributionEmpty(distribution); ++bucketIdProvider.id; distribution.add(2); distribution.add(3); assertPreviousDistribution(distribution, 1, 1, 1, 1); ++bucketIdProvider.id; assertPreviousDistribution(distribution, 2, 2, 3, 5); }
@Test public void testDiscardsBuckets() throws Exception { BucketedDistribution distribution = new BucketedDistribution(); distribution.add(100); distribution.setBucketIdProvider(bucketIdProvider); distribution.add(1); assertPreviousDistributionEmpty(distribution); ++bucketIdProvider.id; distribution.add(2); distribution.add(3); assertPreviousDistribution(distribution, 1, 1, 1, 1); ++bucketIdProvider.id; ++bucketIdProvider.id; distribution.add(100); assertPreviousDistributionEmpty(distribution); ++bucketIdProvider.id; assertPreviousDistribution(distribution, 1, 100, 100, 100); distribution.add(200); ++bucketIdProvider.id; ++bucketIdProvider.id; assertPreviousDistributionEmpty(distribution); }