### Question:
Buckets { public final Buckets<P>.Bucket getBucket(long timestamp) { long bucketTimestamp = getBucketTimestamp(timestamp); return bucketList.get(bucketTimestamp); } Buckets();  Buckets(final long secondsPerBucket); Map<Long, Bucket> getBucketList(); void addQueryStatus(P key, QueryStatus status); QueryStatus getQueryStatus(P key); final void add(final P primaryKey, final long timestamp, final double value); final void addInterpolated(final P primaryKey, final long timestamp, final double value); final Buckets<P>.Bucket getBucket(long timestamp); final SortedSet<Long> getTimestamps(); final long getSecondsPerBucket(); final void dump(PrintStream ps); static final long DEFAULT_BUCKET_SIZE; }### Answer:
@Test public void testGetBucket() throws Exception { Buckets<IHasShortcut> testSubject = makeTestBuckets(); MetricKey key = MetricKey.fromValue("My.Metric.Formal.Name", "MyMetric", "Foo=Bar"); testSubject.add(key, 123, 4.567); Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(123); assertEquals("getValue should return the value put in with that key", bucket.getValue(key).getValue(), 4.567, EPSILON); assertEquals("getValueByShortcut should return the value put in with that shortcut", bucket.getValueByShortcut("My.Metric.Formal.Name").getValue(), 4.567, EPSILON); }
@Test public void testGetValuePastEndOfDataReturnsNaN() { Buckets<IHasShortcut> testSubject = BucketTestUtilities.makeAndPopulateTestBuckets(); final Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(1500); assertNull("get bucket outside of time series should return null.", bucket); }
@Test public void testGetValueNotInDataReturnsNaNByShortcut() { Buckets<IHasShortcut> testSubject = BucketTestUtilities.makeAndPopulateTestBuckets(); final Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(1000); assertNotNull("get bucket in time series should return a bucket.", bucket); double valueForNonexistentSeries = bucket.getValueByShortcut("nonexistentSeries").getValue(); assertEquals("Value for nonexistent series should be NaN", Double.NaN, valueForNonexistentSeries, EPSILON); }
@Test public void testGetValueNotInDataReturnsNaNByMetricKey() { Buckets<IHasShortcut> testSubject = BucketTestUtilities.makeAndPopulateTestBuckets(); final Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(1000); assertNotNull("get bucket in time series should return a bucket.", bucket); MetricKey nonexistentMetric = MetricKey.fromValue("NonexistentMetric", "Nonexistent Series", "device=dev1 Series=M1"); double valueForNonexistentSeries = bucket.getValue(nonexistentMetric).getValue(); assertEquals("Value for nonexistent series should be NaN", Double.NaN, valueForNonexistentSeries, EPSILON); }
@Test(expected = IllegalArgumentException.class) public void getValueWithNullShouldThrowException() { Buckets<IHasShortcut> testSubject = BucketTestUtilities.makeAndPopulateTestBuckets(); final Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(1000); bucket.getValue(null); }
@Test(expected = IllegalArgumentException.class) public void getValueByShortcutWithNullShouldThrowException() { Buckets<IHasShortcut> testSubject = BucketTestUtilities.makeAndPopulateTestBuckets(); final Buckets<IHasShortcut>.Bucket bucket = testSubject.getBucket(1000); bucket.getValueByShortcut(null); }