Search in sources :

Example 1 with RichGaugeReaderPublicMetrics

use of org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics in project spring-boot by spring-projects.

the class PublicMetricsAutoConfigurationTests method richGaugePublicMetrics.

@Test
public void richGaugePublicMetrics() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class);
    RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class);
    assertThat(richGaugeReader).isNotNull();
    given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d)));
    RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class);
    assertThat(publicMetrics).isNotNull();
    Collection<Metric<?>> metrics = publicMetrics.metrics();
    assertThat(metrics).isNotNull();
    assertThat(6).isEqualTo(metrics.size());
    assertHasMetric(metrics, new Metric<>("bar.val", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.avg", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.min", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.max", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.alpha", -1.d));
    assertHasMetric(metrics, new Metric<>("bar.count", 1L));
    context.close();
}
Also used : RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RichGauge(org.springframework.boot.actuate.metrics.rich.RichGauge) RichGaugeReader(org.springframework.boot.actuate.metrics.rich.RichGaugeReader) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 RichGaugeReaderPublicMetrics (org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics)1 Metric (org.springframework.boot.actuate.metrics.Metric)1 RichGauge (org.springframework.boot.actuate.metrics.rich.RichGauge)1 RichGaugeReader (org.springframework.boot.actuate.metrics.rich.RichGaugeReader)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1