Search in sources :

Example 1 with HistogramMetric

use of org.springside.modules.metrics.metric.HistogramMetric in project springside4 by springside.

the class HistogramTest method emptyMesures.

@Test
public void emptyMesures() {
    Histogram histogram = new Histogram(90d, 95d);
    HistogramMetric metric = histogram.calculateMetric();
    assertThat(metric.min).isZero();
    assertThat(metric.max).isZero();
    assertThat(metric.avg).isZero();
    assertThat(metric.pcts.get(90d)).isZero();
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) HistogramMetric(org.springside.modules.metrics.metric.HistogramMetric) Test(org.junit.Test)

Example 2 with HistogramMetric

use of org.springside.modules.metrics.metric.HistogramMetric in project springside4 by springside.

the class HistogramTest method fewData.

@Test
public void fewData() {
    Histogram histogram = new Histogram(90d, 95d);
    histogram.update(1);
    HistogramMetric metric = histogram.calculateMetric();
    assertThat(metric.pcts.get(90d)).isEqualTo(1);
    assertThat(metric.pcts.get(95d)).isEqualTo(1);
    for (int i = 1; i <= 3; i++) {
        histogram.update(i);
    }
    metric = histogram.calculateMetric();
    assertThat(metric.min).isEqualTo(1);
    assertThat(metric.max).isEqualTo(3);
    assertThat(metric.avg).isEqualTo(2);
    assertThat(metric.pcts.get(90d)).isEqualTo(3);
    assertThat(metric.pcts.get(95d)).isEqualTo(3);
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) HistogramMetric(org.springside.modules.metrics.metric.HistogramMetric) Test(org.junit.Test)

Example 3 with HistogramMetric

use of org.springside.modules.metrics.metric.HistogramMetric in project springside4 by springside.

the class HistogramTest method normal.

@Test
public void normal() {
    Histogram histogram = new Histogram(90d, 95d);
    for (int i = 1; i <= 100; i++) {
        histogram.update(i);
    }
    HistogramMetric metric = histogram.calculateMetric();
    assertThat(metric.min).isEqualTo(1);
    assertThat(metric.max).isEqualTo(100);
    assertThat(metric.avg).isEqualTo(50.5);
    assertThat(metric.pcts.get(90d)).isEqualTo(90);
    assertThat(metric.pcts.get(95d)).isEqualTo(95);
    for (int i = 1; i <= 100; i++) {
        histogram.update(i * 2);
    }
    metric = histogram.calculateMetric();
    assertThat(metric.min).isEqualTo(2);
    assertThat(metric.max).isEqualTo(200);
    assertThat(metric.avg).isEqualTo(101);
    assertThat(metric.pcts.get(90d)).isEqualTo(180);
    assertThat(metric.pcts.get(95d)).isEqualTo(190);
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) HistogramMetric(org.springside.modules.metrics.metric.HistogramMetric) Test(org.junit.Test)

Example 4 with HistogramMetric

use of org.springside.modules.metrics.metric.HistogramMetric in project springside4 by springside.

the class HistogramTest method emptyPcts.

@Test()
public void emptyPcts() {
    Histogram histogram = new Histogram();
    for (int i = 1; i <= 3; i++) {
        histogram.update(i);
    }
    HistogramMetric metric = histogram.calculateMetric();
    assertThat(metric.max).isEqualTo(3);
    assertThat(metric.pcts).isEmpty();
    assertThat(metric.pcts.get(90d)).isNull();
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) HistogramMetric(org.springside.modules.metrics.metric.HistogramMetric) Test(org.junit.Test)

Example 5 with HistogramMetric

use of org.springside.modules.metrics.metric.HistogramMetric in project springside4 by springside.

the class MetricRegistryTest method defaultPcts.

@Test
public void defaultPcts() {
    MetricRegistry metricRegistry = new MetricRegistry();
    // set pcts 60,70
    Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.histogram.setPcts"), 60d, 70d);
    for (int i = 1; i <= 100; i++) {
        histogram.update(i);
    }
    HistogramMetric metric = histogram.calculateMetric();
    assertThat(metric.pcts.get(60d)).isEqualTo(60);
    assertThat(metric.pcts.get(70d)).isEqualTo(70);
    // new default 50
    metricRegistry.setDefaultPcts(new Double[] { 50d });
    Histogram histogramWithNewDefaultPcts = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.histogram.newDefault"));
    for (int i = 1; i <= 100; i++) {
        histogramWithNewDefaultPcts.update(i);
    }
    metric = histogramWithNewDefaultPcts.calculateMetric();
    assertThat(metric.pcts.get(50d)).isEqualTo(50);
    assertThat(metric.pcts.get(90d)).isNull();
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) HistogramMetric(org.springside.modules.metrics.metric.HistogramMetric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Histogram (org.springside.modules.metrics.metric.Histogram)5 HistogramMetric (org.springside.modules.metrics.metric.HistogramMetric)5