Java 类org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RichGaugeReaderPublicMetricsTests.java   
@Test
public void testMetrics() throws Exception {
    InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();

    repository.set(new Metric<Double>("a", 0.d, new Date()));
    repository.set(new Metric<Double>("a", 0.5d, new Date()));

    RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics(
            repository);

    Map<String, Metric<?>> results = new HashMap<String, Metric<?>>();
    for (Metric<?> metric : metrics.metrics()) {
        results.put(metric.getName(), metric);
    }
    assertThat(results.containsKey("a.val")).isTrue();
    assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d);

    assertThat(results.containsKey("a.avg")).isTrue();
    assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d);

    assertThat(results.containsKey("a.min")).isTrue();
    assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d);

    assertThat(results.containsKey("a.max")).isTrue();
    assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d);

    assertThat(results.containsKey("a.count")).isTrue();
    assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L);

    assertThat(results.containsKey("a.alpha")).isTrue();
    assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d);
}
项目:spring-boot-concourse    文件:RichGaugeReaderPublicMetricsTests.java   
@Test
public void testMetrics() throws Exception {
    InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();

    repository.set(new Metric<Double>("a", 0.d, new Date()));
    repository.set(new Metric<Double>("a", 0.5d, new Date()));

    RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics(
            repository);

    Map<String, Metric<?>> results = new HashMap<String, Metric<?>>();
    for (Metric<?> metric : metrics.metrics()) {
        results.put(metric.getName(), metric);
    }
    assertThat(results.containsKey("a.val")).isTrue();
    assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d);

    assertThat(results.containsKey("a.avg")).isTrue();
    assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d);

    assertThat(results.containsKey("a.min")).isTrue();
    assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d);

    assertThat(results.containsKey("a.max")).isTrue();
    assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d);

    assertThat(results.containsKey("a.count")).isTrue();
    assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L);

    assertThat(results.containsKey("a.alpha")).isTrue();
    assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d);
}
项目:contestparser    文件:RichGaugeReaderPublicMetricsTests.java   
@Test
public void testMetrics() throws Exception {
    InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();

    repository.set(new Metric<Double>("a", 0.d, new Date()));
    repository.set(new Metric<Double>("a", 0.5d, new Date()));

    RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics(
            repository);

    Map<String, Metric<?>> results = new HashMap<String, Metric<?>>();
    for (Metric<?> metric : metrics.metrics()) {
        results.put(metric.getName(), metric);
    }
    assertTrue(results.containsKey("a.val"));
    assertThat(results.get("a.val").getValue().doubleValue(), equalTo(0.5d));

    assertTrue(results.containsKey("a.avg"));
    assertThat(results.get("a.avg").getValue().doubleValue(), equalTo(0.25d));

    assertTrue(results.containsKey("a.min"));
    assertThat(results.get("a.min").getValue().doubleValue(), equalTo(0.0d));

    assertTrue(results.containsKey("a.max"));
    assertThat(results.get("a.max").getValue().doubleValue(), equalTo(0.5d));

    assertTrue(results.containsKey("a.count"));
    assertThat(results.get("a.count").getValue().longValue(), equalTo(2L));

    assertTrue(results.containsKey("a.alpha"));
    assertThat(results.get("a.alpha").getValue().doubleValue(), equalTo(-1.d));
}
项目:building-microservices    文件:OperationsMetricsApplication.java   
@Bean
@Primary
public InMemoryRichGaugeRepository inMemoryRichGaugeRepository() {
    return new InMemoryRichGaugeRepository();
}
项目:spring-boot-starter-batch-web    文件:MetricsConfiguration.java   
/**
 * This repository will be added automatically to the ones getting data from the
 * GaugeService. Take a look at the MetricRepositoryAutoConfiguration for more information:
 * The 'primaryMetricWriter' is collecting references to all MetricWriter implementations,
 * and this is an implementation of MetricWriter.
 */
@Bean
@ConditionalOnMissingBean(RichGaugeRepository.class)
public RichGaugeRepository richGaugeRepository() {
    return new InMemoryRichGaugeRepository();
}