BucketedCounter extends Bucketed<Counter> { public void add(long count) { add((double) count); }  void add(long count); void add(final double count);  }
@Test public void testInitialState() throws Exception { BucketedCounter counter = new BucketedCounter(); counter.add(1); assertPreviousCount(counter, 0); }
@Test public void testWithBucketIdProvider() throws Exception { BucketedCounter counter = new BucketedCounter(); counter.setBucketIdProvider(bucketIdProvider); counter.add(1); assertPreviousCount(counter, 0); ++bucketIdProvider.id; counter.add(2); counter.add(2.2); assertPreviousCount(counter, 1); ++bucketIdProvider.id; assertPreviousCount(counter, 4.2); }
@Test public void testDiscardsBuckets() throws Exception { BucketedCounter counter = new BucketedCounter(); counter.add(100); counter.setBucketIdProvider(bucketIdProvider); counter.add(1); assertPreviousCount(counter, 0); ++bucketIdProvider.id; counter.add(2); counter.add(2.2); assertPreviousCount(counter, 1); ++bucketIdProvider.id; ++bucketIdProvider.id; counter.add(100); assertPreviousCount(counter, 0); ++bucketIdProvider.id; assertPreviousCount(counter, 100); counter.add(200); ++bucketIdProvider.id; ++bucketIdProvider.id; assertPreviousCount(counter, 0); }