Polish updated metrics code
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
@@ -38,8 +36,10 @@ import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests for {@link MetricRepositoryAutoConfiguration}.
|
||||
* Tests for {@link MetricExportAutoConfiguration}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
@@ -88,15 +88,15 @@ public class MetricExportAutoConfigurationTests {
|
||||
@Test
|
||||
public void exportMetricsEndpoint() {
|
||||
this.context = new AnnotationConfigApplicationContext(WriterConfig.class,
|
||||
MetricEndpointConfiguration.class,
|
||||
MetricExportAutoConfiguration.class,
|
||||
MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
MetricExporters exporters = this.context.getBean(MetricExporters.class);
|
||||
MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters().get(
|
||||
"writer");
|
||||
exporter.setIgnoreTimestamps(true);
|
||||
exporter.export();
|
||||
MetricsEndpointMetricReader reader = this.context.getBean("endpointReader", MetricsEndpointMetricReader.class);
|
||||
MetricsEndpointMetricReader reader = this.context.getBean("endpointReader",
|
||||
MetricsEndpointMetricReader.class);
|
||||
Mockito.verify(reader, Mockito.atLeastOnce()).findAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
@@ -39,6 +33,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link MetricRepositoryAutoConfiguration}.
|
||||
*
|
||||
|
||||
@@ -27,6 +27,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for {@link AggregateMetricReader}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class AggregateMetricReaderTests {
|
||||
|
||||
@@ -164,4 +164,5 @@ public class BufferGaugeServiceSpeedTests {
|
||||
}
|
||||
watch.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,4 +61,5 @@ public class CounterBuffersTests {
|
||||
public void findNonExistent() {
|
||||
assertNull(this.buffers.find("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Speed tests for {@link CounterService}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(Theories.class)
|
||||
@@ -162,4 +163,5 @@ public class CounterServiceSpeedTests {
|
||||
}
|
||||
watch.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,4 +126,5 @@ public class DefaultGaugeServiceSpeedTests {
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertTrue(0 < total.longValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
@@ -114,13 +113,15 @@ public class DropwizardMetricServicesTests {
|
||||
}
|
||||
|
||||
public static class WriterThread extends Thread {
|
||||
|
||||
private int index;
|
||||
|
||||
private boolean failed;
|
||||
|
||||
private DropwizardMetricServices writer;
|
||||
|
||||
public WriterThread(ThreadGroup group, int index, DropwizardMetricServices writer) {
|
||||
super(group, "Writer-" + index);
|
||||
|
||||
this.index = index;
|
||||
this.writer = writer;
|
||||
}
|
||||
@@ -143,5 +144,7 @@ public class DropwizardMetricServicesTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,12 +25,16 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link MetricCopyExporter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class MetricCopyExporterTests {
|
||||
|
||||
private final InMemoryMetricRepository writer = new InMemoryMetricRepository();
|
||||
|
||||
private final InMemoryMetricRepository reader = new InMemoryMetricRepository();
|
||||
|
||||
private final MetricCopyExporter exporter = new MetricCopyExporter(this.reader,
|
||||
this.writer);
|
||||
|
||||
|
||||
@@ -29,14 +29,20 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests for {@link MetricExporters}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class MetricExportersTests {
|
||||
|
||||
private MetricExporters exporters;
|
||||
|
||||
private MetricExportProperties export = new MetricExportProperties();
|
||||
|
||||
private Map<String, MetricWriter> writers = new LinkedHashMap<String, MetricWriter>();
|
||||
|
||||
private MetricReader reader = Mockito.mock(MetricReader.class);
|
||||
|
||||
private MetricWriter writer = Mockito.mock(MetricWriter.class);
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,12 +25,16 @@ import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link RichGaugeExporter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class RichGaugeExporterTests {
|
||||
|
||||
private final InMemoryRichGaugeRepository reader = new InMemoryRichGaugeRepository();
|
||||
|
||||
private final InMemoryMetricRepository writer = new InMemoryMetricRepository();
|
||||
|
||||
private final RichGaugeExporter exporter = new RichGaugeExporter(this.reader,
|
||||
this.writer);
|
||||
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
package org.springframework.boot.actuate.metrics.integration;
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
package org.springframework.boot.actuate.metrics.integration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -17,22 +31,29 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringIntegrationMetricReader}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes=TestConfiguration.class)
|
||||
@SpringApplicationConfiguration(classes = TestConfiguration.class)
|
||||
@IntegrationTest("spring.jmx.enabled=true")
|
||||
@DirtiesContext
|
||||
public class SpringIntegrationMetricReaderTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SpringIntegrationMetricReader reader;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(reader.count()>0);
|
||||
assertTrue(this.reader.count() > 0);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import({JmxAutoConfiguration.class, IntegrationAutoConfiguration.class})
|
||||
@Import({ JmxAutoConfiguration.class, IntegrationAutoConfiguration.class })
|
||||
protected static class TestConfiguration {
|
||||
@Bean
|
||||
public SpringIntegrationMetricReader reader(IntegrationMBeanExporter exporter) {
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultMetricNamingStrategy}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class DefaultMetricNamingStrategyTests {
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -29,9 +28,13 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link OpenTsdbMetricWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OpenTsdbMetricWriterTests {
|
||||
@@ -48,25 +51,19 @@ public class OpenTsdbMetricWriterTests {
|
||||
@Test
|
||||
public void postSuccessfullyOnFlush() {
|
||||
this.writer.set(new Metric<Double>("foo", 2.4));
|
||||
given(
|
||||
this.restTemplate.postForEntity(Matchers.anyString(),
|
||||
Matchers.any(Object.class), anyMap()))
|
||||
given(this.restTemplate.postForEntity(anyString(), any(Object.class), anyMap()))
|
||||
.willReturn(emptyResponse());
|
||||
this.writer.flush();
|
||||
verify(this.restTemplate).postForEntity(Matchers.anyString(),
|
||||
Matchers.any(Object.class), anyMap());
|
||||
verify(this.restTemplate).postForEntity(anyString(), any(Object.class), anyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flushAutomaticlly() {
|
||||
given(
|
||||
this.restTemplate.postForEntity(Matchers.anyString(),
|
||||
Matchers.any(Object.class), anyMap()))
|
||||
given(this.restTemplate.postForEntity(anyString(), any(Object.class), anyMap()))
|
||||
.willReturn(emptyResponse());
|
||||
this.writer.setBufferSize(0);
|
||||
this.writer.set(new Metric<Double>("foo", 2.4));
|
||||
verify(this.restTemplate).postForEntity(Matchers.anyString(),
|
||||
Matchers.any(Object.class), anyMap());
|
||||
verify(this.restTemplate).postForEntity(anyString(), any(Object.class), anyMap());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -76,7 +73,7 @@ public class OpenTsdbMetricWriterTests {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private Class<Map> anyMap() {
|
||||
return Matchers.any(Class.class);
|
||||
return any(Class.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ public class StatsdMetricWriterTests {
|
||||
private static final class DummyStatsDServer {
|
||||
|
||||
private final List<String> messagesReceived = new ArrayList<String>();
|
||||
|
||||
private final DatagramSocket server;
|
||||
|
||||
public DummyStatsDServer(int port) {
|
||||
@@ -141,5 +142,7 @@ public class StatsdMetricWriterTests {
|
||||
public List<String> messagesReceived() {
|
||||
return new ArrayList<String>(this.messagesReceived);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user