Search in sources :

Example 1 with BucketBoundaries

use of io.opencensus.stats.BucketBoundaries in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testCreateEmpty.

@Test
public void testCreateEmpty() {
    assertThat(MutableSumDouble.create().getSum()).isWithin(TOLERANCE).of(0);
    assertThat(MutableSumLong.create().getSum()).isWithin(TOLERANCE).of(0);
    assertThat(MutableCount.create().getCount()).isEqualTo(0);
    assertThat(MutableMean.create().getMean()).isWithin(TOLERANCE).of(0);
    assertThat(MutableLastValueDouble.create().getLastValue()).isNaN();
    assertThat(MutableLastValueLong.create().getLastValue()).isNaN();
    BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(0.1, 2.2, 33.3));
    MutableDistribution mutableDistribution = MutableDistribution.create(bucketBoundaries);
    assertThat(mutableDistribution.getMean()).isWithin(TOLERANCE).of(0);
    assertThat(mutableDistribution.getCount()).isEqualTo(0);
    assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(0);
    assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[4]);
    assertThat(mutableDistribution.getExemplars()).isEqualTo(new Exemplar[4]);
    MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY);
    assertThat(mutableDistributionNoHistogram.getExemplars()).isNull();
}
Also used : MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) BucketBoundaries(io.opencensus.stats.BucketBoundaries) Test(org.junit.Test)

Example 2 with BucketBoundaries

use of io.opencensus.stats.BucketBoundaries in project instrumentation-java by census-instrumentation.

the class RecordUtilsTest method createMutableAggregation.

@Test
public void createMutableAggregation() {
    BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(-1.0, 0.0, 1.0));
    assertThat(RecordUtils.createMutableAggregation(Sum.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(SumDataDouble.create(0));
    assertThat(RecordUtils.createMutableAggregation(Sum.create(), MEASURE_LONG).toAggregationData()).isEqualTo(SumDataLong.create(0));
    assertThat(RecordUtils.createMutableAggregation(Count.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(CountData.create(0));
    assertThat(RecordUtils.createMutableAggregation(Count.create(), MEASURE_LONG).toAggregationData()).isEqualTo(CountData.create(0));
    assertThat(RecordUtils.createMutableAggregation(Mean.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(MeanData.create(0, 0));
    assertThat(RecordUtils.createMutableAggregation(Mean.create(), MEASURE_LONG).toAggregationData()).isEqualTo(MeanData.create(0, 0));
    assertThat(RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(LastValueDataDouble.create(Double.NaN));
    assertThat(RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_LONG).toAggregationData()).isEqualTo(LastValueDataLong.create(0));
    MutableDistribution mutableDistribution = (MutableDistribution) RecordUtils.createMutableAggregation(Distribution.create(bucketBoundaries), MEASURE_DOUBLE);
    assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(EPSILON).of(0);
    assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[2]);
}
Also used : MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) BucketBoundaries(io.opencensus.stats.BucketBoundaries) Test(org.junit.Test)

Aggregations

MutableDistribution (io.opencensus.implcore.stats.MutableAggregation.MutableDistribution)2 BucketBoundaries (io.opencensus.stats.BucketBoundaries)2 Test (org.junit.Test)2