use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.
the class DistributionTest method createDistribution_ZeroCountAndPositiveMean.
@Test
public void createDistribution_ZeroCountAndPositiveMean() {
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
List<Bucket> buckets = Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("sum should be 0 if count is 0.");
Distribution.create(0, 6.6, 0, bucketOptions, buckets);
}
use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.
the class DistributionTest method createDistribution_NegativeCount.
@Test
public void createDistribution_NegativeCount() {
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
List<Bucket> buckets = Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("count should be non-negative.");
Distribution.create(-10, 6.6, 678.54, bucketOptions, buckets);
}
use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.
the class DistributionTest method createAndGet_ExplicitBuckets.
@Test
public void createAndGet_ExplicitBuckets() {
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 3.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
final List<Double> actual = new ArrayList<Double>();
bucketOptions.match(new Function<ExplicitOptions, Object>() {
@Override
public Object apply(ExplicitOptions arg) {
actual.addAll(arg.getBucketBoundaries());
return null;
}
}, Functions.throwAssertionError());
assertThat(actual).containsExactlyElementsIn(bucketBounds).inOrder();
}
use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.
the class DistributionTest method createAndGet_Distribution.
@Test
public void createAndGet_Distribution() {
Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP, ATTACHMENTS);
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
List<Bucket> buckets = Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4, exemplar));
Distribution distribution = Distribution.create(10, 6.6, 678.54, bucketOptions, buckets);
assertThat(distribution.getCount()).isEqualTo(10);
assertThat(distribution.getSum()).isWithin(TOLERANCE).of(6.6);
assertThat(distribution.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(678.54);
final List<Double> actual = new ArrayList<Double>();
distribution.getBucketOptions().match(new Function<ExplicitOptions, Object>() {
@Override
public Object apply(ExplicitOptions arg) {
actual.addAll(arg.getBucketBoundaries());
return null;
}
}, Functions.throwAssertionError());
assertThat(actual).containsExactlyElementsIn(bucketBounds).inOrder();
assertThat(distribution.getBuckets()).containsExactlyElementsIn(buckets).inOrder();
}
use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.
the class DistributionTest method createDistribution_NullBucketList.
@Test
public void createDistribution_NullBucketList() {
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
thrown.expect(NullPointerException.class);
thrown.expectMessage("buckets");
Distribution.create(10, 6.6, 678.54, bucketOptions, null);
}
Aggregations