@Bean @ExportMetricWriter @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "spring.metrics.export.statsd", name = "host") public StatsdMetricWriter statsdMetricWriter() { MetricExportProperties.Statsd statsdProperties = this.properties.getStatsd(); return new StatsdMetricWriter(statsdProperties.getPrefix(), statsdProperties.getHost(), statsdProperties.getPort()); }
@Test public void statsdMissingHost() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(WriterConfig.class, MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); this.thrown.expect(NoSuchBeanDefinitionException.class); this.context.getBean(StatsdMetricWriter.class); }
@Test public void statsdWithHost() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.metrics.export.statsd.host=localhost"); this.context.register(WriterConfig.class, MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(StatsdMetricWriter.class)).isNotNull(); }
@Test public void statsdWithHost() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.metrics.export.statsd.host=localhost"); this.context.register(WriterConfig.class, MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(StatsdMetricWriter.class), notNullValue()); }