Merge branch '1.5.x'
This commit is contained in:
@@ -44,16 +44,16 @@ public class InMemoryMetricRepository implements MetricRepository {
|
||||
final int amount = delta.getValue().intValue();
|
||||
final Date timestamp = delta.getTimestamp();
|
||||
this.metrics.update(metricName, new Callback<Metric<?>>() {
|
||||
|
||||
@Override
|
||||
public Metric<?> modify(Metric<?> current) {
|
||||
if (current != null) {
|
||||
return new Metric<Long>(metricName,
|
||||
current.increment(amount).getValue(), timestamp);
|
||||
}
|
||||
else {
|
||||
return new Metric<Long>(metricName, (long) amount, timestamp);
|
||||
}
|
||||
return new Metric<Long>(metricName, (long) amount, timestamp);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashSet;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.writer.Delta;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link MultiMetricRepository} implementation backed by a
|
||||
@@ -36,14 +37,24 @@ public class InMemoryMultiMetricRepository implements MultiMetricRepository {
|
||||
|
||||
private final Collection<String> groups = new HashSet<String>();
|
||||
|
||||
public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link InMemoryMetricRepository} backed by a new
|
||||
* {@link InMemoryMetricRepository}.
|
||||
*/
|
||||
public InMemoryMultiMetricRepository() {
|
||||
this(new InMemoryMetricRepository());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link InMemoryMetricRepository} backed by the specified
|
||||
* {@link InMemoryMetricRepository}.
|
||||
* @param repository the backing repository
|
||||
*/
|
||||
public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) {
|
||||
Assert.notNull(repository, "Repository must not be null");
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String group, Collection<Metric<?>> values) {
|
||||
String prefix = group;
|
||||
|
||||
@@ -145,7 +145,7 @@ public class JolokiaAutoConfigurationTests {
|
||||
Collection<? extends MvcEndpoint> endpoints) {
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints);
|
||||
mapping.setSecurityInterceptor(
|
||||
new MvcEndpointSecurityInterceptor(false, Collections.EMPTY_LIST));
|
||||
new MvcEndpointSecurityInterceptor(false, Collections.emptyList()));
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ public class PrefixMetricGroupExporterTests {
|
||||
@Test
|
||||
public void countersIncremented() {
|
||||
this.writer.increment("counter.foo", new Delta<Long>("bar", 1L));
|
||||
this.reader.set("counter", Collections.<Metric<?>>singletonList(
|
||||
new Metric<Number>("counter.foo.bar", 1)));
|
||||
this.reader.set("counter", Collections
|
||||
.<Metric<?>>singletonList(new Metric<Number>("counter.foo.bar", 1)));
|
||||
this.exporter.setGroups(Collections.singleton("counter.foo"));
|
||||
this.exporter.export();
|
||||
assertThat(this.writer.findAll("counter.foo").iterator().next().getValue())
|
||||
@@ -65,8 +65,7 @@ public class PrefixMetricGroupExporterTests {
|
||||
@Test
|
||||
public void unprefixedMetricsNotCopied() {
|
||||
this.reader.set("foo", Arrays.<Metric<?>>asList(
|
||||
new Metric<Number>("foo.bar", 2.3),
|
||||
new Metric<Number>("foo.spam", 1.3)));
|
||||
new Metric<Number>("foo.bar", 2.3), new Metric<Number>("foo.spam", 1.3)));
|
||||
this.exporter.setGroups(Collections.singleton("bar"));
|
||||
this.exporter.export();
|
||||
assertThat(Iterables.collection(this.writer.groups())).isEmpty();
|
||||
@@ -84,10 +83,9 @@ public class PrefixMetricGroupExporterTests {
|
||||
@Test
|
||||
public void onlyPrefixedMetricsCopied() {
|
||||
this.reader.set("foo", Arrays.<Metric<?>>asList(
|
||||
new Metric<Number>("foo.bar", 2.3),
|
||||
new Metric<Number>("foo.spam", 1.3)));
|
||||
this.reader.set("foobar", Collections.<Metric<?>>singletonList(
|
||||
new Metric<Number>("foobar.spam", 1.3)));
|
||||
new Metric<Number>("foo.bar", 2.3), new Metric<Number>("foo.spam", 1.3)));
|
||||
this.reader.set("foobar", Collections
|
||||
.<Metric<?>>singletonList(new Metric<Number>("foobar.spam", 1.3)));
|
||||
this.exporter.setGroups(Collections.singleton("foo"));
|
||||
this.exporter.export();
|
||||
assertThat(Iterables.collection(this.writer.groups())).hasSize(1);
|
||||
|
||||
@@ -28,6 +28,8 @@ import static org.assertj.core.api.Assertions.offset;
|
||||
|
||||
/**
|
||||
* Tests for {@link InMemoryMetricRepository}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class InMemoryMetricRepositoryTests {
|
||||
|
||||
|
||||
@@ -29,12 +29,13 @@ import org.springframework.boot.actuate.metrics.writer.Delta;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InMemoryMultiMetricRepository}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class InMemoryMultiMetricRepositoryTests {
|
||||
|
||||
private final InMemoryMultiMetricRepository repository =
|
||||
new InMemoryMultiMetricRepository();
|
||||
private final InMemoryMultiMetricRepository repository = new InMemoryMultiMetricRepository();
|
||||
|
||||
@Test
|
||||
public void registeredPrefixCounted() {
|
||||
|
||||
Reference in New Issue
Block a user