mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 15:49:33 +00:00
11162 lines
451 KiB
Diff
11162 lines
451 KiB
Diff
--- a/metrics-benchmarks/src/main/java/io/dropwizard/metrics5/benchmarks/SlidingTimeWindowReservoirsBenchmark.java
|
|
+++ b/metrics-benchmarks/src/main/java/io/dropwizard/metrics5/benchmarks/SlidingTimeWindowReservoirsBenchmark.java
|
|
@@ -2,7 +2,6 @@ package io.dropwizard.metrics5.benchmarks;
|
|
|
|
import io.dropwizard.metrics5.SlidingTimeWindowArrayReservoir;
|
|
import io.dropwizard.metrics5.SlidingTimeWindowReservoir;
|
|
-import io.dropwizard.metrics5.Snapshot;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.openjdk.jmh.annotations.Benchmark;
|
|
import org.openjdk.jmh.annotations.Group;
|
|
@@ -42,8 +41,7 @@ public class SlidingTimeWindowReservoirsBenchmark {
|
|
@Group("slidingTime")
|
|
@GroupThreads(1)
|
|
public Object slidingTimeRead() {
|
|
- Snapshot snapshot = slidingTime.getSnapshot();
|
|
- return snapshot;
|
|
+ return slidingTime.getSnapshot();
|
|
}
|
|
|
|
@Benchmark
|
|
@@ -58,8 +56,7 @@ public class SlidingTimeWindowReservoirsBenchmark {
|
|
@Group("arrTime")
|
|
@GroupThreads(1)
|
|
public Object arrTimeRead() {
|
|
- Snapshot snapshot = arrTime.getSnapshot();
|
|
- return snapshot;
|
|
+ return arrTime.getSnapshot();
|
|
}
|
|
|
|
public static void main(String[] args) throws RunnerException {
|
|
--- a/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/CollectdReporter.java
|
|
+++ b/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/CollectdReporter.java
|
|
@@ -1,13 +1,12 @@
|
|
package io.dropwizard.metrics5.collectd;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
import static io.dropwizard.metrics5.MetricAttribute.COUNT;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M15_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M1_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M5_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MAX;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MIN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P50;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P75;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P95;
|
|
@@ -16,6 +15,7 @@ import static io.dropwizard.metrics5.MetricAttribute.P99;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P999;
|
|
import static io.dropwizard.metrics5.MetricAttribute.STDDEV;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
@@ -30,7 +30,6 @@ import io.dropwizard.metrics5.Snapshot;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import java.io.IOException;
|
|
import java.net.InetAddress;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -81,7 +80,7 @@ public class CollectdReporter extends ScheduledReporter {
|
|
private SecurityLevel securityLevel = SecurityLevel.NONE;
|
|
private String username = "";
|
|
private String password = "";
|
|
- private Set<MetricAttribute> disabledMetricAttributes = Collections.emptySet();
|
|
+ private Set<MetricAttribute> disabledMetricAttributes = ImmutableSet.of();
|
|
private int maxLength = Sanitize.DEFAULT_MAX_LENGTH;
|
|
|
|
private Builder(MetricRegistry registry) {
|
|
@@ -150,14 +149,10 @@ public class CollectdReporter extends ScheduledReporter {
|
|
|
|
public CollectdReporter build(Sender sender) {
|
|
if (securityLevel != SecurityLevel.NONE) {
|
|
- if (username.isEmpty()) {
|
|
- throw new IllegalArgumentException(
|
|
- "username is required for securityLevel: " + securityLevel);
|
|
- }
|
|
- if (password.isEmpty()) {
|
|
- throw new IllegalArgumentException(
|
|
- "password is required for securityLevel: " + securityLevel);
|
|
- }
|
|
+ checkArgument(
|
|
+ !username.isEmpty(), "username is required for securityLevel: %s", securityLevel);
|
|
+ checkArgument(
|
|
+ !password.isEmpty(), "password is required for securityLevel: %s", securityLevel);
|
|
}
|
|
return new CollectdReporter(
|
|
registry,
|
|
@@ -302,7 +297,7 @@ public class CollectdReporter extends ScheduledReporter {
|
|
try {
|
|
writer.write(metaData, value);
|
|
} catch (RuntimeException e) {
|
|
- LOG.warn("Failed to process metric '" + metaData.getPlugin() + "': " + e.getMessage());
|
|
+ LOG.warn("Failed to process metric '{}': {}", metaData.getPlugin(), e.getMessage());
|
|
} catch (IOException e) {
|
|
LOG.error("Failed to send metric to collectd", e);
|
|
}
|
|
@@ -336,9 +331,9 @@ public class CollectdReporter extends ScheduledReporter {
|
|
private void serializeHistogram(MetaData.Builder metaData, Histogram metric) {
|
|
final Snapshot snapshot = metric.getSnapshot();
|
|
writeValue(metaData, COUNT, (double) metric.getCount());
|
|
- writeValue(metaData, MAX, (double) snapshot.getMax());
|
|
+ writeValue(metaData, MetricAttribute.MAX, (double) snapshot.getMax());
|
|
writeValue(metaData, MEAN, snapshot.getMean());
|
|
- writeValue(metaData, MIN, (double) snapshot.getMin());
|
|
+ writeValue(metaData, MetricAttribute.MIN, (double) snapshot.getMin());
|
|
writeValue(metaData, STDDEV, snapshot.getStdDev());
|
|
writeValue(metaData, P50, snapshot.getMedian());
|
|
writeValue(metaData, P75, snapshot.get75thPercentile());
|
|
@@ -351,9 +346,9 @@ public class CollectdReporter extends ScheduledReporter {
|
|
private void serializeTimer(MetaData.Builder metaData, Timer metric) {
|
|
final Snapshot snapshot = metric.getSnapshot();
|
|
writeValue(metaData, COUNT, (double) metric.getCount());
|
|
- writeDuration(metaData, MAX, (double) snapshot.getMax());
|
|
+ writeDuration(metaData, MetricAttribute.MAX, (double) snapshot.getMax());
|
|
writeDuration(metaData, MEAN, snapshot.getMean());
|
|
- writeDuration(metaData, MIN, (double) snapshot.getMin());
|
|
+ writeDuration(metaData, MetricAttribute.MIN, (double) snapshot.getMin());
|
|
writeDuration(metaData, STDDEV, snapshot.getStdDev());
|
|
writeDuration(metaData, P50, snapshot.getMedian());
|
|
writeDuration(metaData, P75, snapshot.get75thPercentile());
|
|
--- a/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/PacketWriter.java
|
|
+++ b/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/PacketWriter.java
|
|
@@ -1,10 +1,14 @@
|
|
package io.dropwizard.metrics5.collectd;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
+import static java.nio.charset.StandardCharsets.US_ASCII;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
+
|
|
+import com.google.common.base.Strings;
|
|
import java.io.IOException;
|
|
import java.nio.BufferOverflowException;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.security.InvalidKeyException;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -64,8 +68,8 @@ class PacketWriter {
|
|
PacketWriter(Sender sender, String username, String password, SecurityLevel securityLevel) {
|
|
this.sender = sender;
|
|
this.securityLevel = securityLevel;
|
|
- this.username = username != null ? username.getBytes(StandardCharsets.UTF_8) : null;
|
|
- this.password = password != null ? password.getBytes(StandardCharsets.UTF_8) : null;
|
|
+ this.username = username != null ? username.getBytes(UTF_8) : null;
|
|
+ this.password = password != null ? password.getBytes(UTF_8) : null;
|
|
}
|
|
|
|
void write(MetaData metaData, Number... values) throws BufferOverflowException, IOException {
|
|
@@ -119,12 +123,12 @@ class PacketWriter {
|
|
}
|
|
|
|
private void writeString(ByteBuffer buffer, int type, String val) {
|
|
- if (val == null || val.length() == 0) {
|
|
+ if (Strings.isNullOrEmpty(val)) {
|
|
return;
|
|
}
|
|
int len = HEADER_LEN + val.length() + 1;
|
|
writeHeader(buffer, type, len);
|
|
- buffer.put(val.getBytes(StandardCharsets.US_ASCII)).put(NULL);
|
|
+ buffer.put(val.getBytes(US_ASCII)).put(NULL);
|
|
}
|
|
|
|
private void writeNumber(ByteBuffer buffer, int type, long val) {
|
|
@@ -236,9 +240,7 @@ class PacketWriter {
|
|
} catch (InvalidParameterSpecException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
- if (iv.length != IV_LENGTH) {
|
|
- throw new IllegalStateException("Bad initialization vector");
|
|
- }
|
|
+ checkState(iv.length == IV_LENGTH, "Bad initialization vector");
|
|
final ByteBuffer output = ByteBuffer.allocate(input.remaining() * 2);
|
|
try {
|
|
cipher.doFinal(input, output);
|
|
@@ -261,9 +263,7 @@ class PacketWriter {
|
|
final MessageDigest digest = MessageDigest.getInstance(SHA_1_ALGORITHM);
|
|
digest.update(input);
|
|
final byte[] output = digest.digest();
|
|
- if (output.length != SHA1_LENGTH) {
|
|
- throw new IllegalStateException("Bad SHA1 hash");
|
|
- }
|
|
+ checkState(output.length == SHA1_LENGTH, "Bad SHA1 hash");
|
|
return output;
|
|
} catch (NoSuchAlgorithmException e) {
|
|
throw new RuntimeException(e);
|
|
--- a/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/Sender.java
|
|
+++ b/metrics-collectd/src/main/java/io/dropwizard/metrics5/collectd/Sender.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.collectd;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
+
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.ByteBuffer;
|
|
@@ -19,9 +21,7 @@ public class Sender {
|
|
}
|
|
|
|
public void connect() throws IOException {
|
|
- if (isConnected()) {
|
|
- throw new IllegalStateException("Already connected");
|
|
- }
|
|
+ checkState(!isConnected(), "Already connected");
|
|
if (host != null) {
|
|
address = new InetSocketAddress(host, port);
|
|
}
|
|
--- a/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/CollectdReporterSecurityTest.java
|
|
+++ b/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/CollectdReporterSecurityTest.java
|
|
@@ -1,37 +1,37 @@
|
|
package io.dropwizard.metrics5.collectd;
|
|
|
|
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CollectdReporterSecurityTest {
|
|
+final class CollectdReporterSecurityTest {
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
|
|
@Test
|
|
- void testUnableSetSecurityLevelToSignWithoutUsername() {
|
|
- assertThatIllegalArgumentException()
|
|
- .isThrownBy(
|
|
+ void unableSetSecurityLevelToSignWithoutUsername() {
|
|
+ assertThatThrownBy(
|
|
() ->
|
|
CollectdReporter.forRegistry(registry)
|
|
.withHostName("eddie")
|
|
.withSecurityLevel(SecurityLevel.SIGN)
|
|
.withPassword("t1_g3r")
|
|
.build(new Sender("localhost", 25826)))
|
|
- .withMessage("username is required for securityLevel: SIGN");
|
|
+ .isInstanceOf(IllegalArgumentException.class)
|
|
+ .hasMessage("username is required for securityLevel: SIGN");
|
|
}
|
|
|
|
@Test
|
|
- void testUnableSetSecurityLevelToSignWithoutPassword() {
|
|
- assertThatIllegalArgumentException()
|
|
- .isThrownBy(
|
|
+ void unableSetSecurityLevelToSignWithoutPassword() {
|
|
+ assertThatThrownBy(
|
|
() ->
|
|
CollectdReporter.forRegistry(registry)
|
|
.withHostName("eddie")
|
|
.withSecurityLevel(SecurityLevel.SIGN)
|
|
.withUsername("scott")
|
|
.build(new Sender("localhost", 25826)))
|
|
- .withMessage("password is required for securityLevel: SIGN");
|
|
+ .isInstanceOf(IllegalArgumentException.class)
|
|
+ .hasMessage("password is required for securityLevel: SIGN");
|
|
}
|
|
}
|
|
--- a/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/CollectdReporterTest.java
|
|
+++ b/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/CollectdReporterTest.java
|
|
@@ -1,11 +1,14 @@
|
|
package io.dropwizard.metrics5.collectd;
|
|
|
|
+import static java.util.Collections.emptySortedMap;
|
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Histogram;
|
|
import io.dropwizard.metrics5.Meter;
|
|
@@ -14,7 +17,6 @@ import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import io.dropwizard.metrics5.Snapshot;
|
|
import io.dropwizard.metrics5.Timer;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -25,7 +27,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
|
|
|
-public class CollectdReporterTest {
|
|
+final class CollectdReporterTest {
|
|
@RegisterExtension public static Receiver receiver = new Receiver(25826);
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
@@ -96,7 +98,7 @@ public class CollectdReporterTest {
|
|
|
|
@Test
|
|
void reportsCounters() throws Exception {
|
|
- Counter counter = mock(Counter.class);
|
|
+ Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(42L);
|
|
|
|
reporter.report(
|
|
@@ -111,7 +113,7 @@ public class CollectdReporterTest {
|
|
|
|
@Test
|
|
void reportsMeters() throws Exception {
|
|
- Meter meter = mock(Meter.class);
|
|
+ Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
when(meter.getFiveMinuteRate()).thenReturn(3.0);
|
|
@@ -130,8 +132,8 @@ public class CollectdReporterTest {
|
|
|
|
@Test
|
|
void reportsHistograms() throws Exception {
|
|
- Histogram histogram = mock(Histogram.class);
|
|
- Snapshot snapshot = mock(Snapshot.class);
|
|
+ Histogram histogram = mock();
|
|
+ Snapshot snapshot = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSnapshot()).thenReturn(snapshot);
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
@@ -154,8 +156,8 @@ public class CollectdReporterTest {
|
|
|
|
@Test
|
|
void reportsTimers() throws Exception {
|
|
- Timer timer = mock(Timer.class);
|
|
- Snapshot snapshot = mock(Snapshot.class);
|
|
+ Timer timer = mock();
|
|
+ Snapshot snapshot = mock();
|
|
when(timer.getSnapshot()).thenReturn(snapshot);
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSnapshot()).thenReturn(snapshot);
|
|
@@ -195,14 +197,14 @@ public class CollectdReporterTest {
|
|
|
|
@Test
|
|
void doesNotReportDisabledMetricAttributes() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
when(meter.getFiveMinuteRate()).thenReturn(3.0);
|
|
when(meter.getFifteenMinuteRate()).thenReturn(4.0);
|
|
when(meter.getMeanRate()).thenReturn(5.0);
|
|
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(11L);
|
|
|
|
CollectdReporter reporter =
|
|
@@ -236,37 +238,37 @@ public class CollectdReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testUnableSetSecurityLevelToSignWithoutUsername() {
|
|
- assertThatIllegalArgumentException()
|
|
- .isThrownBy(
|
|
+ void unableSetSecurityLevelToSignWithoutUsername() {
|
|
+ assertThatThrownBy(
|
|
() ->
|
|
CollectdReporter.forRegistry(registry)
|
|
.withHostName("eddie")
|
|
.withSecurityLevel(SecurityLevel.SIGN)
|
|
.withPassword("t1_g3r")
|
|
.build(new Sender("localhost", 25826)))
|
|
- .withMessage("username is required for securityLevel: SIGN");
|
|
+ .isInstanceOf(IllegalArgumentException.class)
|
|
+ .hasMessage("username is required for securityLevel: SIGN");
|
|
}
|
|
|
|
@Test
|
|
- void testUnableSetSecurityLevelToSignWithoutPassword() {
|
|
- assertThatIllegalArgumentException()
|
|
- .isThrownBy(
|
|
+ void unableSetSecurityLevelToSignWithoutPassword() {
|
|
+ assertThatThrownBy(
|
|
() ->
|
|
CollectdReporter.forRegistry(registry)
|
|
.withHostName("eddie")
|
|
.withSecurityLevel(SecurityLevel.SIGN)
|
|
.withUsername("scott")
|
|
.build(new Sender("localhost", 25826)))
|
|
- .withMessage("password is required for securityLevel: SIGN");
|
|
+ .isInstanceOf(IllegalArgumentException.class)
|
|
+ .hasMessage("password is required for securityLevel: SIGN");
|
|
}
|
|
|
|
private <T> SortedMap<MetricName, T> map() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
private <T> SortedMap<MetricName, T> map(MetricName name, T metric) {
|
|
- final Map<MetricName, T> map = Collections.singletonMap(name, metric);
|
|
+ final Map<MetricName, T> map = ImmutableMap.of(name, metric);
|
|
return new TreeMap<>(map);
|
|
}
|
|
|
|
@@ -289,6 +291,6 @@ public class CollectdReporterTest {
|
|
|
|
private List<Number> nextValues(Receiver receiver) throws Exception {
|
|
final ValueList valueList = receiver.next();
|
|
- return valueList == null ? Collections.emptyList() : valueList.getValues();
|
|
+ return valueList == null ? ImmutableList.of() : valueList.getValues();
|
|
}
|
|
}
|
|
--- a/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/PacketWriterTest.java
|
|
+++ b/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/PacketWriterTest.java
|
|
@@ -17,7 +17,7 @@ import javax.crypto.spec.IvParameterSpec;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class PacketWriterTest {
|
|
+final class PacketWriterTest {
|
|
|
|
private MetaData metaData =
|
|
new MetaData.Builder("nw-1.alpine.example.com", 1520961345L, 100)
|
|
@@ -28,7 +28,7 @@ class PacketWriterTest {
|
|
private String password = "t1_g$r";
|
|
|
|
@Test
|
|
- void testSignRequest() throws Exception {
|
|
+ void signRequest() throws Exception {
|
|
AtomicBoolean packetVerified = new AtomicBoolean();
|
|
Sender sender =
|
|
new Sender("localhost", 4009) {
|
|
@@ -74,7 +74,7 @@ class PacketWriterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testEncryptRequest() throws Exception {
|
|
+ void encryptRequest() throws Exception {
|
|
AtomicBoolean packetVerified = new AtomicBoolean();
|
|
Sender sender =
|
|
new Sender("localhost", 4009) {
|
|
@@ -190,6 +190,6 @@ class PacketWriterTest {
|
|
assertThat(amountOfValues).isEqualTo((short) 1);
|
|
byte dataType = packet.get();
|
|
assertThat(dataType).isEqualTo((byte) 1);
|
|
- assertThat(packet.order(ByteOrder.LITTLE_ENDIAN).getDouble()).isEqualTo(42.0, offset(0.01));
|
|
+ assertThat(packet.order(ByteOrder.LITTLE_ENDIAN).getDouble()).isCloseTo(42.0, offset(0.01));
|
|
}
|
|
}
|
|
--- a/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/SanitizeTest.java
|
|
+++ b/metrics-collectd/src/test/java/io/dropwizard/metrics5/collectd/SanitizeTest.java
|
|
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SanitizeTest {
|
|
+final class SanitizeTest {
|
|
|
|
private Sanitize sanitize = new Sanitize(Sanitize.DEFAULT_MAX_LENGTH);
|
|
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/ConsoleReporter.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/ConsoleReporter.java
|
|
@@ -1,8 +1,8 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import java.io.PrintStream;
|
|
import java.text.DateFormat;
|
|
-import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
@@ -53,7 +53,7 @@ public class ConsoleReporter extends ScheduledReporter {
|
|
this.filter = MetricFilter.ALL;
|
|
this.executor = null;
|
|
this.shutdownExecutorOnStop = true;
|
|
- disabledMetricAttributes = Collections.emptySet();
|
|
+ disabledMetricAttributes = ImmutableSet.of();
|
|
}
|
|
|
|
/**
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/CsvReporter.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/CsvReporter.java
|
|
@@ -179,7 +179,7 @@ public class CsvReporter extends ScheduledReporter {
|
|
}
|
|
}
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(CsvReporter.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(CsvReporter.class);
|
|
|
|
private final File directory;
|
|
private final Locale locale;
|
|
@@ -391,7 +391,7 @@ public class CsvReporter extends ScheduledReporter {
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
- LOGGER.warn("Error writing to {}", name, e);
|
|
+ LOG.warn("Error writing to {}", name, e);
|
|
}
|
|
}
|
|
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/ExponentialMovingAverages.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/ExponentialMovingAverages.java
|
|
@@ -17,9 +17,9 @@ public class ExponentialMovingAverages implements MovingAverages {
|
|
* If ticking would reduce even Long.MAX_VALUE in the 15 minute EWMA below this target then don't
|
|
* bother ticking in a loop and instead reset all the EWMAs.
|
|
*/
|
|
- private static final double maxTickZeroTarget = 0.0001;
|
|
+ private static final double MAX_TICK_ZERO_TARGET = 0.0001;
|
|
|
|
- private static final int maxTicks;
|
|
+ private static final int MAX_TICKS;
|
|
private static final long TICK_INTERVAL = TimeUnit.SECONDS.toNanos(5);
|
|
|
|
static {
|
|
@@ -29,8 +29,8 @@ public class ExponentialMovingAverages implements MovingAverages {
|
|
do {
|
|
m3.tick();
|
|
m3Ticks++;
|
|
- } while (m3.getRate(TimeUnit.SECONDS) > maxTickZeroTarget);
|
|
- maxTicks = m3Ticks;
|
|
+ } while (m3.getRate(TimeUnit.SECONDS) > MAX_TICK_ZERO_TARGET);
|
|
+ MAX_TICKS = m3Ticks;
|
|
}
|
|
|
|
private final EWMA m1Rate = EWMA.oneMinuteEWMA();
|
|
@@ -69,7 +69,7 @@ public class ExponentialMovingAverages implements MovingAverages {
|
|
if (lastTick.compareAndSet(oldTick, newIntervalStartTick)) {
|
|
sum.add(age);
|
|
final long requiredTicks = age / TICK_INTERVAL;
|
|
- if (requiredTicks >= maxTicks) {
|
|
+ if (requiredTicks >= MAX_TICKS) {
|
|
m1Rate.reset();
|
|
m5Rate.reset();
|
|
m15Rate.reset();
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/LockFreeExponentiallyDecayingReservoir.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/LockFreeExponentiallyDecayingReservoir.java
|
|
@@ -1,8 +1,10 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+import static java.util.Objects.requireNonNull;
|
|
+
|
|
import io.dropwizard.metrics5.WeightedSnapshot.WeightedSample;
|
|
import java.time.Duration;
|
|
-import java.util.Objects;
|
|
import java.util.concurrent.ConcurrentSkipListMap;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
|
@@ -41,7 +43,7 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
|
|
private static final double SECONDS_PER_NANO = .000_000_001D;
|
|
private static final AtomicReferenceFieldUpdater<LockFreeExponentiallyDecayingReservoir, State>
|
|
- stateUpdater =
|
|
+ STATE_UPDATER =
|
|
AtomicReferenceFieldUpdater.newUpdater(
|
|
LockFreeExponentiallyDecayingReservoir.class, State.class, "state");
|
|
|
|
@@ -53,7 +55,7 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
|
|
private static final class State {
|
|
|
|
- private static final AtomicIntegerFieldUpdater<State> countUpdater =
|
|
+ private static final AtomicIntegerFieldUpdater<State> COUNT_UPDATER =
|
|
AtomicIntegerFieldUpdater.newUpdater(State.class, "count");
|
|
|
|
private final double alphaNanos;
|
|
@@ -89,7 +91,7 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
private void addSample(
|
|
double priority, long value, double itemWeight, boolean bypassIncrement) {
|
|
if (values.putIfAbsent(priority, new WeightedSample(value, itemWeight)) == null
|
|
- && (bypassIncrement || countUpdater.incrementAndGet(this) > size)) {
|
|
+ && (bypassIncrement || COUNT_UPDATER.incrementAndGet(this) > size)) {
|
|
values.pollFirstEntry();
|
|
}
|
|
}
|
|
@@ -126,7 +128,7 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
// It's possible that more values were added while the map was scanned, those with the
|
|
// minimum priorities are removed.
|
|
while (newCount > size) {
|
|
- Objects.requireNonNull(newValues.pollFirstEntry(), "Expected an entry");
|
|
+ requireNonNull(newValues.pollFirstEntry(), "Expected an entry");
|
|
newCount--;
|
|
}
|
|
return new State(alphaNanos, size, newTick, newCount, newValues);
|
|
@@ -193,7 +195,7 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
|
|
private State doRescale(long currentTick, State stateSnapshot) {
|
|
State newState = stateSnapshot.rescale(currentTick);
|
|
- if (stateUpdater.compareAndSet(this, stateSnapshot, newState)) {
|
|
+ if (STATE_UPDATER.compareAndSet(this, stateSnapshot, newState)) {
|
|
// newState successfully installed
|
|
return newState;
|
|
}
|
|
@@ -235,10 +237,8 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
* are replaced (based on weight, with some amount of random jitter).
|
|
*/
|
|
public Builder size(int value) {
|
|
- if (value <= 0) {
|
|
- throw new IllegalArgumentException(
|
|
- "LockFreeExponentiallyDecayingReservoir size must be positive: " + value);
|
|
- }
|
|
+ checkArgument(
|
|
+ value > 0, "LockFreeExponentiallyDecayingReservoir size must be positive: %s", value);
|
|
this.size = value;
|
|
return this;
|
|
}
|
|
@@ -254,13 +254,13 @@ public final class LockFreeExponentiallyDecayingReservoir implements Reservoir {
|
|
|
|
/** Interval at which this reservoir is rescaled. */
|
|
public Builder rescaleThreshold(Duration value) {
|
|
- this.rescaleThreshold = Objects.requireNonNull(value, "rescaleThreshold is required");
|
|
+ this.rescaleThreshold = requireNonNull(value, "rescaleThreshold is required");
|
|
return this;
|
|
}
|
|
|
|
/** Clock instance used for decay. */
|
|
public Builder clock(Clock value) {
|
|
- this.clock = Objects.requireNonNull(value, "clock is required");
|
|
+ this.clock = requireNonNull(value, "clock is required");
|
|
return this;
|
|
}
|
|
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/MetricName.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/MetricName.java
|
|
@@ -1,13 +1,19 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
-import java.util.Collections;
|
|
-import java.util.Comparator;
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+import static java.util.Map.Entry.comparingByKey;
|
|
+import static java.util.Objects.requireNonNull;
|
|
+import static java.util.stream.Collectors.joining;
|
|
+
|
|
+import com.google.common.base.Strings;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
+import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
-import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
|
|
/**
|
|
@@ -17,7 +23,7 @@ import java.util.stream.Stream;
|
|
public class MetricName implements Comparable<MetricName> {
|
|
|
|
private static final String SEPARATOR = ".";
|
|
- private static final Map<String, String> EMPTY_TAGS = Collections.emptyMap();
|
|
+ private static final Map<String, String> EMPTY_TAGS = ImmutableMap.of();
|
|
static final MetricName EMPTY = new MetricName("", EMPTY_TAGS);
|
|
|
|
/**
|
|
@@ -33,7 +39,7 @@ public class MetricName implements Comparable<MetricName> {
|
|
private final Map<String, String> tags;
|
|
|
|
public MetricName(String key, Map<String, String> tags) {
|
|
- this.key = Objects.requireNonNull(key);
|
|
+ this.key = requireNonNull(key);
|
|
this.tags = tags.isEmpty() ? EMPTY_TAGS : unmodifiableSortedCopy(tags);
|
|
}
|
|
|
|
@@ -63,9 +69,9 @@ public class MetricName implements Comparable<MetricName> {
|
|
}
|
|
|
|
String newKey =
|
|
- Stream.concat(Stream.of(key), Stream.of(parts))
|
|
- .filter(s -> s != null && !s.isEmpty())
|
|
- .collect(Collectors.joining(SEPARATOR));
|
|
+ Stream.concat(Stream.of(key), Arrays.stream(parts))
|
|
+ .filter(s -> !Strings.isNullOrEmpty(s))
|
|
+ .collect(joining(SEPARATOR));
|
|
return new MetricName(newKey, tags);
|
|
}
|
|
|
|
@@ -94,9 +100,7 @@ public class MetricName implements Comparable<MetricName> {
|
|
return this;
|
|
}
|
|
|
|
- if (pairs.length % 2 != 0) {
|
|
- throw new IllegalArgumentException("Argument count must be even");
|
|
- }
|
|
+ checkArgument(pairs.length % 2 == 0, "Argument count must be even");
|
|
|
|
final Map<String, String> add = new HashMap<>();
|
|
for (int i = 0; i < pairs.length; i += 2) {
|
|
@@ -201,8 +205,8 @@ public class MetricName implements Comparable<MetricName> {
|
|
private static <K extends Comparable<K>, V> Map<K, V> unmodifiableSortedCopy(Map<K, V> map) {
|
|
LinkedHashMap<K, V> sorted = new LinkedHashMap<>();
|
|
map.entrySet().stream()
|
|
- .sorted(Comparator.comparing(Map.Entry::getKey))
|
|
+ .sorted(comparingByKey())
|
|
.forEach(e -> sorted.put(e.getKey(), e.getValue()));
|
|
- return Collections.unmodifiableMap(sorted);
|
|
+ return unmodifiableMap(sorted);
|
|
}
|
|
}
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/MetricRegistry.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/MetricRegistry.java
|
|
@@ -1,6 +1,10 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
-import java.util.Collections;
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+import static java.util.Collections.unmodifiableSortedMap;
|
|
+import static java.util.Collections.unmodifiableSortedSet;
|
|
+import static java.util.Objects.requireNonNull;
|
|
+
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.SortedMap;
|
|
@@ -91,9 +95,7 @@ public class MetricRegistry implements MetricSet {
|
|
* @throws IllegalArgumentException if the name is already registered or metric variable is null
|
|
*/
|
|
public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException {
|
|
- if (metric == null) {
|
|
- throw new NullPointerException("metric == null");
|
|
- }
|
|
+ requireNonNull(metric, "metric == null");
|
|
|
|
if (metric instanceof MetricRegistry) {
|
|
final MetricRegistry childRegistry = (MetricRegistry) metric;
|
|
@@ -213,7 +215,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Counter.class.isInstance(metric);
|
|
+ return metric instanceof Counter;
|
|
}
|
|
});
|
|
}
|
|
@@ -253,7 +255,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Histogram.class.isInstance(metric);
|
|
+ return metric instanceof Histogram;
|
|
}
|
|
});
|
|
}
|
|
@@ -293,7 +295,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Meter.class.isInstance(metric);
|
|
+ return metric instanceof Meter;
|
|
}
|
|
});
|
|
}
|
|
@@ -328,7 +330,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Timer.class.isInstance(metric);
|
|
+ return metric instanceof Timer;
|
|
}
|
|
});
|
|
}
|
|
@@ -366,7 +368,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Gauge.class.isInstance(metric);
|
|
+ return metric instanceof Gauge;
|
|
}
|
|
});
|
|
}
|
|
@@ -430,7 +432,7 @@ public class MetricRegistry implements MetricSet {
|
|
* @return the names of all the metrics
|
|
*/
|
|
public SortedSet<MetricName> getNames() {
|
|
- return Collections.unmodifiableSortedSet(new TreeSet<>(metrics.keySet()));
|
|
+ return unmodifiableSortedSet(new TreeSet<>(metrics.keySet()));
|
|
}
|
|
|
|
/**
|
|
@@ -455,7 +457,7 @@ public class MetricRegistry implements MetricSet {
|
|
timers.put(entry.getKey(), (Gauge<?>) entry.getValue());
|
|
}
|
|
}
|
|
- return Collections.unmodifiableSortedMap(timers);
|
|
+ return unmodifiableSortedMap(timers);
|
|
}
|
|
|
|
/**
|
|
@@ -562,7 +564,7 @@ public class MetricRegistry implements MetricSet {
|
|
timers.put(entry.getKey(), (T) entry.getValue());
|
|
}
|
|
}
|
|
- return Collections.unmodifiableSortedMap(timers);
|
|
+ return unmodifiableSortedMap(timers);
|
|
}
|
|
|
|
private void onMetricAdded(MetricName name, Metric metric) {
|
|
@@ -627,7 +629,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public Map<MetricName, Metric> getMetrics() {
|
|
- return Collections.unmodifiableMap(metrics);
|
|
+ return unmodifiableMap(metrics);
|
|
}
|
|
|
|
@FunctionalInterface
|
|
@@ -646,7 +648,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Counter.class.isInstance(metric);
|
|
+ return metric instanceof Counter;
|
|
}
|
|
};
|
|
|
|
@@ -659,7 +661,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Histogram.class.isInstance(metric);
|
|
+ return metric instanceof Histogram;
|
|
}
|
|
};
|
|
|
|
@@ -672,7 +674,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Meter.class.isInstance(metric);
|
|
+ return metric instanceof Meter;
|
|
}
|
|
};
|
|
|
|
@@ -685,7 +687,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Timer.class.isInstance(metric);
|
|
+ return metric instanceof Timer;
|
|
}
|
|
};
|
|
|
|
@@ -699,7 +701,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
@Override
|
|
public boolean isInstance(Metric metric) {
|
|
- return Gauge.class.isInstance(metric);
|
|
+ return metric instanceof Gauge;
|
|
}
|
|
};
|
|
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/NoopMetricRegistry.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/NoopMetricRegistry.java
|
|
@@ -1,11 +1,14 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static java.util.Collections.emptySortedMap;
|
|
+import static java.util.Collections.emptySortedSet;
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import java.io.OutputStream;
|
|
import java.time.Duration;
|
|
import java.util.Collection;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -158,67 +161,67 @@ public final class NoopMetricRegistry extends MetricRegistry {
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedSet<MetricName> getNames() {
|
|
- return Collections.emptySortedSet();
|
|
+ return emptySortedSet();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Gauge<?>> getGauges() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Gauge<?>> getGauges(MetricFilter filter) {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Counter> getCounters() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Counter> getCounters(MetricFilter filter) {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Histogram> getHistograms() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Histogram> getHistograms(MetricFilter filter) {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Meter> getMeters() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Meter> getMeters(MetricFilter filter) {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Timer> getTimers() {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public SortedMap<MetricName, Timer> getTimers(MetricFilter filter) {
|
|
- return Collections.emptySortedMap();
|
|
+ return emptySortedMap();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@@ -236,7 +239,7 @@ public final class NoopMetricRegistry extends MetricRegistry {
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public Map<MetricName, Metric> getMetrics() {
|
|
- return Collections.emptyMap();
|
|
+ return ImmutableMap.of();
|
|
}
|
|
|
|
static final class NoopMetric implements Metric {
|
|
@@ -630,19 +633,19 @@ public final class NoopMetricRegistry extends MetricRegistry {
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public Set<K> keySet() {
|
|
- return Collections.emptySet();
|
|
+ return ImmutableSet.of();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public Collection<V> values() {
|
|
- return Collections.emptySet();
|
|
+ return ImmutableSet.of();
|
|
}
|
|
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
public Set<Entry<K, V>> entrySet() {
|
|
- return Collections.emptySet();
|
|
+ return ImmutableSet.of();
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/ScheduledReporter.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/ScheduledReporter.java
|
|
@@ -1,7 +1,10 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+import static java.util.Objects.requireNonNull;
|
|
+
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import java.io.Closeable;
|
|
-import java.util.Collections;
|
|
import java.util.Locale;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -128,7 +131,7 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
durationUnit,
|
|
executor,
|
|
shutdownExecutorOnStop,
|
|
- Collections.emptySet());
|
|
+ ImmutableSet.of());
|
|
}
|
|
|
|
protected ScheduledReporter(
|
|
@@ -141,9 +144,7 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
boolean shutdownExecutorOnStop,
|
|
Set<MetricAttribute> disabledMetricAttributes) {
|
|
|
|
- if (registry == null) {
|
|
- throw new NullPointerException("registry == null");
|
|
- }
|
|
+ requireNonNull(registry, "registry == null");
|
|
|
|
this.registry = registry;
|
|
this.filter = filter;
|
|
@@ -154,7 +155,7 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
this.durationFactor = durationUnit.toNanos(1);
|
|
this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
|
|
this.disabledMetricAttributes =
|
|
- disabledMetricAttributes != null ? disabledMetricAttributes : Collections.emptySet();
|
|
+ disabledMetricAttributes != null ? disabledMetricAttributes : ImmutableSet.of();
|
|
}
|
|
|
|
/**
|
|
@@ -172,9 +173,7 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
* for testing.
|
|
*/
|
|
synchronized void start(long initialDelay, long period, TimeUnit unit, Runnable runnable) {
|
|
- if (this.scheduledFuture != null) {
|
|
- throw new IllegalArgumentException("Reporter already started");
|
|
- }
|
|
+ checkArgument(this.scheduledFuture == null, "Reporter already started");
|
|
|
|
this.scheduledFuture = getScheduledFuture(initialDelay, period, unit, runnable);
|
|
}
|
|
@@ -185,8 +184,8 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
* @deprecated Use {@link #getScheduledFuture(long, long, TimeUnit, Runnable,
|
|
* ScheduledExecutorService)} instead.
|
|
*/
|
|
- @SuppressWarnings("DeprecatedIsStillUsed")
|
|
@Deprecated
|
|
+ @SuppressWarnings("DeprecatedIsStillUsed")
|
|
protected ScheduledFuture<?> getScheduledFuture(
|
|
long initialDelay, long period, TimeUnit unit, Runnable runnable) {
|
|
return getScheduledFuture(initialDelay, period, unit, runnable, this.executor);
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/SharedMetricRegistries.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/SharedMetricRegistries.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
+
|
|
import java.util.Set;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentMap;
|
|
@@ -84,9 +86,7 @@ public class SharedMetricRegistries {
|
|
*/
|
|
public static MetricRegistry getDefault() {
|
|
MetricRegistry metricRegistry = tryGetDefault();
|
|
- if (metricRegistry == null) {
|
|
- throw new IllegalStateException("Default registry name has not been set.");
|
|
- }
|
|
+ checkState(metricRegistry != null, "Default registry name has not been set.");
|
|
return metricRegistry;
|
|
}
|
|
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/Slf4jReporter.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/Slf4jReporter.java
|
|
@@ -4,10 +4,8 @@ import static io.dropwizard.metrics5.MetricAttribute.COUNT;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M15_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M1_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M5_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MAX;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MIN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P50;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P75;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P95;
|
|
@@ -16,7 +14,7 @@ import static io.dropwizard.metrics5.MetricAttribute.P99;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P999;
|
|
import static io.dropwizard.metrics5.MetricAttribute.STDDEV;
|
|
|
|
-import java.util.Collections;
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import java.util.Map.Entry;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -81,7 +79,7 @@ public class Slf4jReporter extends ScheduledReporter {
|
|
this.loggingLevel = LoggingLevel.INFO;
|
|
this.executor = null;
|
|
this.shutdownExecutorOnStop = true;
|
|
- this.disabledMetricAttributes = Collections.emptySet();
|
|
+ this.disabledMetricAttributes = ImmutableSet.of();
|
|
}
|
|
|
|
/**
|
|
@@ -306,8 +304,8 @@ public class Slf4jReporter extends ScheduledReporter {
|
|
b.append("type=TIMER");
|
|
append(b, "name", prefix(name));
|
|
appendCountIfEnabled(b, timer);
|
|
- appendLongDurationIfEnabled(b, MIN, snapshot::getMin);
|
|
- appendLongDurationIfEnabled(b, MAX, snapshot::getMax);
|
|
+ appendLongDurationIfEnabled(b, MetricAttribute.MIN, snapshot::getMin);
|
|
+ appendLongDurationIfEnabled(b, MetricAttribute.MAX, snapshot::getMax);
|
|
appendDoubleDurationIfEnabled(b, MEAN, snapshot::getMean);
|
|
appendDoubleDurationIfEnabled(b, STDDEV, snapshot::getStdDev);
|
|
appendDoubleDurationIfEnabled(b, P50, snapshot::getMedian);
|
|
@@ -338,8 +336,8 @@ public class Slf4jReporter extends ScheduledReporter {
|
|
b.append("type=HISTOGRAM");
|
|
append(b, "name", prefix(name));
|
|
appendCountIfEnabled(b, histogram);
|
|
- appendLongIfEnabled(b, MIN, snapshot::getMin);
|
|
- appendLongIfEnabled(b, MAX, snapshot::getMax);
|
|
+ appendLongIfEnabled(b, MetricAttribute.MIN, snapshot::getMin);
|
|
+ appendLongIfEnabled(b, MetricAttribute.MAX, snapshot::getMax);
|
|
appendDoubleIfEnabled(b, MEAN, snapshot::getMean);
|
|
appendDoubleIfEnabled(b, STDDEV, snapshot::getStdDev);
|
|
appendDoubleIfEnabled(b, P50, snapshot::getMedian);
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/SlidingTimeWindowMovingAverages.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/SlidingTimeWindowMovingAverages.java
|
|
@@ -186,8 +186,7 @@ public class SlidingTimeWindowMovingAverages implements MovingAverages {
|
|
buckets.stream().limit(toIndex).mapToLong(LongAdder::longValue).forEach(adder::add);
|
|
buckets.stream().skip(fromIndex).mapToLong(LongAdder::longValue).forEach(adder::add);
|
|
}
|
|
- long retval = adder.longValue();
|
|
- return retval;
|
|
+ return adder.longValue();
|
|
}
|
|
|
|
@Override
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/UniformSnapshot.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/UniformSnapshot.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
import static java.lang.Math.floor;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
@@ -47,9 +48,10 @@ public class UniformSnapshot extends Snapshot {
|
|
*/
|
|
@Override
|
|
public double getValue(double quantile) {
|
|
- if (quantile < 0.0 || quantile > 1.0 || Double.isNaN(quantile)) {
|
|
- throw new IllegalArgumentException(quantile + " is not in [0..1]");
|
|
- }
|
|
+ checkArgument(
|
|
+ quantile >= 0.0 && quantile <= 1.0 && !Double.isNaN(quantile),
|
|
+ "%s is not in [0..1]",
|
|
+ quantile);
|
|
|
|
if (values.length == 0) {
|
|
return 0.0;
|
|
--- a/metrics-core/src/main/java/io/dropwizard/metrics5/WeightedSnapshot.java
|
|
+++ b/metrics-core/src/main/java/io/dropwizard/metrics5/WeightedSnapshot.java
|
|
@@ -1,13 +1,14 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
+import static java.util.Comparator.comparingLong;
|
|
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStreamWriter;
|
|
import java.io.PrintWriter;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
-import java.util.Comparator;
|
|
|
|
/** A statistical snapshot of a {@link WeightedSnapshot}. */
|
|
public class WeightedSnapshot extends Snapshot {
|
|
@@ -35,7 +36,7 @@ public class WeightedSnapshot extends Snapshot {
|
|
public WeightedSnapshot(Collection<WeightedSample> values) {
|
|
final WeightedSample[] copy = values.toArray(new WeightedSample[] {});
|
|
|
|
- Arrays.sort(copy, Comparator.comparingLong(w -> w.value));
|
|
+ Arrays.sort(copy, comparingLong(w -> w.value));
|
|
|
|
this.values = new long[copy.length];
|
|
this.normWeights = new double[copy.length];
|
|
@@ -64,9 +65,10 @@ public class WeightedSnapshot extends Snapshot {
|
|
*/
|
|
@Override
|
|
public double getValue(double quantile) {
|
|
- if (quantile < 0.0 || quantile > 1.0 || Double.isNaN(quantile)) {
|
|
- throw new IllegalArgumentException(quantile + " is not in [0..1]");
|
|
- }
|
|
+ checkArgument(
|
|
+ quantile >= 0.0 && quantile <= 1.0 && !Double.isNaN(quantile),
|
|
+ "%s is not in [0..1]",
|
|
+ quantile);
|
|
|
|
if (values.length == 0) {
|
|
return 0.0;
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/CachedGaugeTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/CachedGaugeTest.java
|
|
@@ -1,7 +1,6 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
@@ -15,8 +14,8 @@ import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
-class CachedGaugeTest {
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(CachedGaugeTest.class);
|
|
+final class CachedGaugeTest {
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(CachedGaugeTest.class);
|
|
private static final int THREAD_COUNT = 10;
|
|
private static final long RUNNING_TIME_MILLIS = TimeUnit.SECONDS.toMillis(10);
|
|
|
|
@@ -100,12 +99,12 @@ class CachedGaugeTest {
|
|
Integer newValue = shortTimeoutGauge.getValue();
|
|
|
|
if (newValue == null) {
|
|
- LOGGER.warn("Cached gauge returned null value");
|
|
+ LOG.warn("Cached gauge returned null value");
|
|
return false;
|
|
}
|
|
|
|
if (newValue < lastValue) {
|
|
- LOGGER.error(
|
|
+ LOG.error(
|
|
"Cached gauge returned stale value, last: {}, new: {}",
|
|
lastValue,
|
|
newValue);
|
|
@@ -122,7 +121,7 @@ class CachedGaugeTest {
|
|
}
|
|
|
|
for (int i = 0; i < futures.size(); i++) {
|
|
- assertTrue(futures.get(i).get(), "Future " + i + " failed");
|
|
+ assertThat(futures.get(i).get()).withFailMessage("Future %s failed", i).isTrue();
|
|
}
|
|
|
|
executor.shutdown();
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ChunkedAssociativeLongArrayTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ChunkedAssociativeLongArrayTest.java
|
|
@@ -4,10 +4,10 @@ import static org.assertj.core.api.BDDAssertions.then;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ChunkedAssociativeLongArrayTest {
|
|
+final class ChunkedAssociativeLongArrayTest {
|
|
|
|
@Test
|
|
- void testTrim() {
|
|
+ void trim() {
|
|
ChunkedAssociativeLongArray array = new ChunkedAssociativeLongArray(3);
|
|
array.put(-3, 3);
|
|
array.put(-2, 1);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ClassMetadataTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ClassMetadataTest.java
|
|
@@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class ClassMetadataTest {
|
|
+final class ClassMetadataTest {
|
|
@Test
|
|
- public void testParameterMetadataIsAvailable() throws NoSuchMethodException {
|
|
+ void parameterMetadataIsAvailable() throws NoSuchMethodException {
|
|
assertThat(DefaultSettableGauge.class.getConstructor(Object.class).getParameters())
|
|
.allSatisfy(parameter -> assertThat(parameter.isNamePresent()).isTrue());
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ClockTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ClockTest.java
|
|
@@ -5,15 +5,15 @@ import static org.assertj.core.api.Assertions.offset;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ClockTest {
|
|
+final class ClockTest {
|
|
|
|
@Test
|
|
void userTimeClock() {
|
|
final Clock.UserTimeClock clock = new Clock.UserTimeClock();
|
|
|
|
- assertThat((double) clock.getTime()).isEqualTo(System.currentTimeMillis(), offset(100.0));
|
|
+ assertThat((double) clock.getTime()).isCloseTo(System.currentTimeMillis(), offset(100.0));
|
|
|
|
- assertThat((double) clock.getTick()).isEqualTo(System.nanoTime(), offset(1000000.0));
|
|
+ assertThat((double) clock.getTick()).isCloseTo(System.nanoTime(), offset(1000000.0));
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ConsoleReporterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ConsoleReporterTest.java
|
|
@@ -19,12 +19,12 @@ import org.apache.commons.lang3.SystemUtils;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ConsoleReporterTest {
|
|
+final class ConsoleReporterTest {
|
|
private final Locale locale = Locale.US;
|
|
private final TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
|
|
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
- private final Clock clock = mock(Clock.class);
|
|
+ private final MetricRegistry registry = mock();
|
|
+ private final Clock clock = mock();
|
|
private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
private final PrintStream output = new PrintStream(bytes);
|
|
private final ConsoleReporter reporter =
|
|
@@ -74,7 +74,7 @@ class ConsoleReporterTest {
|
|
|
|
@Test
|
|
void reportsCounterValues() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
reporter.report(map(), map(MetricName.build("test.counter"), counter), map(), map(), map());
|
|
@@ -93,11 +93,11 @@ class ConsoleReporterTest {
|
|
|
|
@Test
|
|
void reportsHistogramValues() throws Exception {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(4L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -138,7 +138,7 @@ class ConsoleReporterTest {
|
|
|
|
@Test
|
|
void reportsMeterValues() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(3L);
|
|
when(meter.getMeanRate()).thenReturn(2.0);
|
|
@@ -167,7 +167,7 @@ class ConsoleReporterTest {
|
|
|
|
@Test
|
|
void reportsTimerValues() throws Exception {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(5));
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -175,7 +175,7 @@ class ConsoleReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -239,7 +239,7 @@ class ConsoleReporterTest {
|
|
.disabledMetricAttributes(disabledMetricAttributes)
|
|
.build();
|
|
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(5L);
|
|
when(meter.getMeanRate()).thenReturn(2.0);
|
|
@@ -283,7 +283,7 @@ class ConsoleReporterTest {
|
|
.disabledMetricAttributes(disabledMetricAttributes)
|
|
.build();
|
|
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(6));
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -291,7 +291,7 @@ class ConsoleReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -349,11 +349,11 @@ class ConsoleReporterTest {
|
|
.disabledMetricAttributes(disabledMetricAttributes)
|
|
.build();
|
|
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(5L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/CounterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/CounterTest.java
|
|
@@ -4,12 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CounterTest {
|
|
+final class CounterTest {
|
|
private final Counter counter = new Counter();
|
|
|
|
@Test
|
|
void startsAtZero() {
|
|
- assertThat(counter.getCount()).isZero();
|
|
+ assertThat(counter.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/CsvReporterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/CsvReporterTest.java
|
|
@@ -7,7 +7,6 @@ import static org.mockito.Mockito.when;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.util.Locale;
|
|
import java.util.SortedMap;
|
|
@@ -17,11 +16,11 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
-public class CsvReporterTest {
|
|
+final class CsvReporterTest {
|
|
@TempDir public File folder;
|
|
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
- private final Clock clock = mock(Clock.class);
|
|
+ private final MetricRegistry registry = mock();
|
|
+ private final Clock clock = mock();
|
|
|
|
private File dataDirectory;
|
|
private CsvReporter reporter;
|
|
@@ -53,7 +52,7 @@ public class CsvReporterTest {
|
|
|
|
@Test
|
|
void reportsCounterValues() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
reporter.report(map(), map(MetricName.build("test.counter"), counter), map(), map(), map());
|
|
@@ -63,11 +62,11 @@ public class CsvReporterTest {
|
|
|
|
@Test
|
|
void reportsHistogramValues() throws Exception {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(12L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -105,7 +104,7 @@ public class CsvReporterTest {
|
|
|
|
@Test
|
|
void reportsTimerValues() throws Exception {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(6));
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -113,7 +112,7 @@ public class CsvReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -137,8 +136,8 @@ public class CsvReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCsvFileProviderIsUsed() {
|
|
- CsvFileProvider fileProvider = mock(CsvFileProvider.class);
|
|
+ void csvFileProviderIsUsed() {
|
|
+ CsvFileProvider fileProvider = mock();
|
|
when(fileProvider.getFile(dataDirectory, "gauge"))
|
|
.thenReturn(new File(dataDirectory, "guage.csv"));
|
|
|
|
@@ -177,7 +176,7 @@ public class CsvReporterTest {
|
|
}
|
|
|
|
private Meter mockMeter() {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getMeanRate()).thenReturn(2.0);
|
|
@@ -197,8 +196,7 @@ public class CsvReporterTest {
|
|
}
|
|
|
|
private String fileContents(String filename) throws IOException {
|
|
- return new String(
|
|
- Files.readAllBytes(new File(dataDirectory, filename).toPath()), StandardCharsets.UTF_8);
|
|
+ return Files.readString(new File(dataDirectory, filename).toPath());
|
|
}
|
|
|
|
private <T> SortedMap<MetricName, T> map() {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/DefaultSettableGaugeTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/DefaultSettableGaugeTest.java
|
|
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class DefaultSettableGaugeTest {
|
|
+final class DefaultSettableGaugeTest {
|
|
@Test
|
|
void newSettableGaugeWithoutDefaultReturnsNull() {
|
|
DefaultSettableGauge<String> gauge = new DefaultSettableGauge<>();
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/DerivativeGaugeTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/DerivativeGaugeTest.java
|
|
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class DerivativeGaugeTest {
|
|
+final class DerivativeGaugeTest {
|
|
private final Gauge<String> gauge1 = () -> "woo";
|
|
private final Gauge<Integer> gauge2 =
|
|
new DerivativeGauge<String, Integer>(gauge1) {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/EWMATest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/EWMATest.java
|
|
@@ -6,74 +6,74 @@ import static org.assertj.core.api.Assertions.offset;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class EWMATest {
|
|
+final class EWMATest {
|
|
@Test
|
|
void aOneMinuteEWMAWithAValueOfThree() {
|
|
final EWMA ewma = EWMA.oneMinuteEWMA();
|
|
ewma.update(3);
|
|
ewma.tick();
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.6, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.6, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.22072766, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.22072766, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.08120117, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.08120117, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.02987224, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.02987224, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.01098938, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.01098938, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00404277, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00404277, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00148725, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00148725, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00054713, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00054713, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00020128, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00020128, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00007405, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00007405, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00002724, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00002724, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00001002, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00001002, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00000369, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00000369, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00000136, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00000136, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00000050, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00000050, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.00000018, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.00000018, offset(0.000001));
|
|
}
|
|
|
|
@Test
|
|
@@ -82,67 +82,67 @@ class EWMATest {
|
|
ewma.update(3);
|
|
ewma.tick();
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.6, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.6, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.49123845, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.49123845, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.40219203, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.40219203, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.32928698, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.32928698, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.26959738, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.26959738, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.22072766, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.22072766, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.18071653, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.18071653, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.14795818, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.14795818, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.12113791, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.12113791, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.09917933, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.09917933, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.08120117, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.08120117, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.06648190, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.06648190, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.05443077, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.05443077, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.04456415, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.04456415, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.03648604, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.03648604, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.02987224, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.02987224, offset(0.000001));
|
|
}
|
|
|
|
@Test
|
|
@@ -151,67 +151,67 @@ class EWMATest {
|
|
ewma.update(3);
|
|
ewma.tick();
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.6, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.6, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.56130419, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.56130419, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.52510399, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.52510399, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.49123845, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.49123845, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.45955700, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.45955700, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.42991879, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.42991879, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.40219203, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.40219203, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.37625345, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.37625345, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.35198773, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.35198773, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.32928698, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.32928698, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.30805027, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.30805027, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.28818318, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.28818318, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.26959738, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.26959738, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.25221023, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.25221023, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.23594443, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.23594443, offset(0.000001));
|
|
|
|
elapseMinute(ewma);
|
|
|
|
- assertThat(ewma.getRate(TimeUnit.SECONDS)).isEqualTo(0.22072766, offset(0.000001));
|
|
+ assertThat(ewma.getRate(TimeUnit.SECONDS)).isCloseTo(0.22072766, offset(0.000001));
|
|
}
|
|
|
|
private void elapseMinute(EWMA ewma) {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ExponentialMovingAveragesTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ExponentialMovingAveragesTest.java
|
|
@@ -7,10 +7,10 @@ import static org.mockito.Mockito.when;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class ExponentialMovingAveragesTest {
|
|
+final class ExponentialMovingAveragesTest {
|
|
@Test
|
|
- public void testMaxTicks() {
|
|
- final Clock clock = mock(Clock.class);
|
|
+ void maxTicks() {
|
|
+ final Clock clock = mock();
|
|
when(clock.getTick()).thenReturn(0L, Long.MAX_VALUE);
|
|
final ExponentialMovingAverages ema = new ExponentialMovingAverages(clock);
|
|
ema.update(Long.MAX_VALUE);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ExponentiallyDecayingReservoirTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ExponentiallyDecayingReservoirTest.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.collect.ImmutableList.toImmutableList;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import java.util.Arrays;
|
|
@@ -7,11 +8,10 @@ import java.util.Collection;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
-import java.util.stream.Collectors;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
-public class ExponentiallyDecayingReservoirTest {
|
|
+final class ExponentiallyDecayingReservoirTest {
|
|
|
|
public enum ReservoirFactory {
|
|
EXPONENTIALLY_DECAYING() {
|
|
@@ -42,7 +42,7 @@ public class ExponentiallyDecayingReservoirTest {
|
|
public static Collection<Object[]> reservoirs() {
|
|
return Arrays.stream(ReservoirFactory.values())
|
|
.map(value -> new Object[] {value})
|
|
- .collect(Collectors.toList());
|
|
+ .collect(toImmutableList());
|
|
}
|
|
|
|
private ReservoirFactory reservoirFactory;
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/FixedNameCsvFileProviderTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/FixedNameCsvFileProviderTest.java
|
|
@@ -8,7 +8,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
-public class FixedNameCsvFileProviderTest {
|
|
+final class FixedNameCsvFileProviderTest {
|
|
@TempDir public File folder;
|
|
|
|
private File dataDirectory;
|
|
@@ -19,7 +19,7 @@ public class FixedNameCsvFileProviderTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetFile() {
|
|
+ void getFile() {
|
|
FixedNameCsvFileProvider provider = new FixedNameCsvFileProvider();
|
|
File file = provider.getFile(dataDirectory, "test");
|
|
assertThat(file.getParentFile()).isEqualTo(dataDirectory);
|
|
@@ -27,7 +27,7 @@ public class FixedNameCsvFileProviderTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetFileSanitize() {
|
|
+ void getFileSanitize() {
|
|
FixedNameCsvFileProvider provider = new FixedNameCsvFileProvider();
|
|
File file = provider.getFile(dataDirectory, "/myfake/uri");
|
|
assertThat(file.getParentFile()).isEqualTo(dataDirectory);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/HistogramTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/HistogramTest.java
|
|
@@ -7,14 +7,14 @@ import static org.mockito.Mockito.when;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HistogramTest {
|
|
- private final Reservoir reservoir = mock(Reservoir.class);
|
|
+final class HistogramTest {
|
|
+ private final Reservoir reservoir = mock();
|
|
private final Histogram histogram = new Histogram(reservoir);
|
|
|
|
@Test
|
|
void updatesTheCountAndSumOnUpdates() {
|
|
- assertThat(histogram.getCount()).isZero();
|
|
- assertThat(histogram.getSum()).isZero();
|
|
+ assertThat(histogram.getCount()).isEqualTo(0);
|
|
+ assertThat(histogram.getSum()).isEqualTo(0);
|
|
|
|
histogram.update(1);
|
|
histogram.update(5);
|
|
@@ -25,7 +25,7 @@ class HistogramTest {
|
|
|
|
@Test
|
|
void returnsTheSnapshotFromTheReservoir() {
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(reservoir.getSnapshot()).thenReturn(snapshot);
|
|
|
|
assertThat(histogram.getSnapshot()).isEqualTo(snapshot);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedExecutorServiceTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedExecutorServiceTest.java
|
|
@@ -19,10 +19,9 @@ import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
-class InstrumentedExecutorServiceTest {
|
|
+final class InstrumentedExecutorServiceTest {
|
|
|
|
- private static final Logger LOGGER =
|
|
- LoggerFactory.getLogger(InstrumentedExecutorServiceTest.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(InstrumentedExecutorServiceTest.class);
|
|
private ExecutorService executor;
|
|
private MetricRegistry registry;
|
|
private InstrumentedExecutorService instrumentedExecutorService;
|
|
@@ -48,7 +47,7 @@ class InstrumentedExecutorServiceTest {
|
|
void tearDown() throws Exception {
|
|
instrumentedExecutorService.shutdown();
|
|
if (!instrumentedExecutorService.awaitTermination(2, TimeUnit.SECONDS)) {
|
|
- LOGGER.error("InstrumentedExecutorService did not terminate.");
|
|
+ LOG.error("InstrumentedExecutorService did not terminate.");
|
|
}
|
|
}
|
|
|
|
@@ -115,8 +114,8 @@ class InstrumentedExecutorServiceTest {
|
|
assertThat(idle.getSnapshot().size()).isEqualTo(1);
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void reportsTasksInformationForThreadPoolExecutor() throws Exception {
|
|
executor =
|
|
new ThreadPoolExecutor(4, 16, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(32));
|
|
@@ -180,7 +179,7 @@ class InstrumentedExecutorServiceTest {
|
|
}
|
|
|
|
@Test
|
|
- public void reportsRejectedTasksForThreadPoolExecutor() throws Exception {
|
|
+ void reportsRejectedTasksForThreadPoolExecutor() throws Exception {
|
|
executor =
|
|
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1));
|
|
instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "tp");
|
|
@@ -207,7 +206,7 @@ class InstrumentedExecutorServiceTest {
|
|
}
|
|
|
|
@Test
|
|
- public void removesMetricsAfterShutdownForThreadPoolExecutor() {
|
|
+ void removesMetricsAfterShutdownForThreadPoolExecutor() {
|
|
executor =
|
|
new ThreadPoolExecutor(4, 16, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(32));
|
|
instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "stp");
|
|
@@ -236,8 +235,8 @@ class InstrumentedExecutorServiceTest {
|
|
MetricRegistry.name("stp", "tasks.capacity"));
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void reportsTasksInformationForForkJoinPool() throws Exception {
|
|
executor = Executors.newWorkStealingPool(4);
|
|
instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "fjp");
|
|
@@ -291,7 +290,7 @@ class InstrumentedExecutorServiceTest {
|
|
}
|
|
|
|
@Test
|
|
- public void removesMetricsAfterShutdownForForkJoinPool() {
|
|
+ void removesMetricsAfterShutdownForForkJoinPool() {
|
|
executor = Executors.newWorkStealingPool(4);
|
|
instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "sfjp");
|
|
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedScheduledExecutorServiceTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedScheduledExecutorServiceTest.java
|
|
@@ -13,8 +13,8 @@ import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
-class InstrumentedScheduledExecutorServiceTest {
|
|
- private static final Logger LOGGER =
|
|
+final class InstrumentedScheduledExecutorServiceTest {
|
|
+ private static final Logger LOG =
|
|
LoggerFactory.getLogger(InstrumentedScheduledExecutorServiceTest.class);
|
|
|
|
private final ScheduledExecutorService scheduledExecutor =
|
|
@@ -35,17 +35,17 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
private final Histogram percentOfPeriod = registry.histogram("xs.scheduled.percent-of-period");
|
|
|
|
@Test
|
|
- void testSubmitRunnable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void submitRunnable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
Future<?> theFuture =
|
|
instrumentedScheduledExecutor.submit(
|
|
@@ -53,87 +53,87 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
assertThat(submitted.getCount()).isEqualTo(1);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
});
|
|
|
|
theFuture.get();
|
|
|
|
assertThat(submitted.getCount()).isEqualTo(1);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isEqualTo(1);
|
|
assertThat(duration.getCount()).isEqualTo(1);
|
|
assertThat(duration.getSnapshot().size()).isEqualTo(1);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testScheduleRunnable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void scheduleRunnable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
ScheduledFuture<?> theFuture =
|
|
instrumentedScheduledExecutor.schedule(
|
|
() -> {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
assertThat(scheduledOnce.getCount()).isEqualTo(1);
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
},
|
|
10L,
|
|
TimeUnit.MILLISECONDS);
|
|
|
|
theFuture.get();
|
|
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isEqualTo(1);
|
|
assertThat(duration.getCount()).isEqualTo(1);
|
|
assertThat(duration.getSnapshot().size()).isEqualTo(1);
|
|
|
|
assertThat(scheduledOnce.getCount()).isEqualTo(1);
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testSubmitCallable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void submitCallable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
final Object obj = new Object();
|
|
|
|
@@ -143,13 +143,13 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
assertThat(submitted.getCount()).isEqualTo(1);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
return obj;
|
|
});
|
|
@@ -158,45 +158,45 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
|
|
assertThat(submitted.getCount()).isEqualTo(1);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isEqualTo(1);
|
|
assertThat(duration.getCount()).isEqualTo(1);
|
|
assertThat(duration.getSnapshot().size()).isEqualTo(1);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testScheduleCallable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void scheduleCallable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
final Object obj = new Object();
|
|
|
|
ScheduledFuture<Object> theFuture =
|
|
instrumentedScheduledExecutor.schedule(
|
|
() -> {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
assertThat(scheduledOnce.getCount()).isEqualTo(1);
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
return obj;
|
|
},
|
|
@@ -205,37 +205,37 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
|
|
assertThat(theFuture.get()).isEqualTo(obj);
|
|
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isEqualTo(1);
|
|
assertThat(duration.getCount()).isEqualTo(1);
|
|
assertThat(duration.getSnapshot().size()).isEqualTo(1);
|
|
|
|
assertThat(scheduledOnce.getCount()).isEqualTo(1);
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testScheduleFixedRateCallable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void scheduleFixedRateCallable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(1);
|
|
ScheduledFuture<?> theFuture =
|
|
instrumentedScheduledExecutor.scheduleAtFixedRate(
|
|
() -> {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
|
|
@@ -257,37 +257,37 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
theFuture.cancel(true);
|
|
TimeUnit.MILLISECONDS.sleep(200); // Wait while the task is cancelled
|
|
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isNotEqualTo(0);
|
|
assertThat(duration.getCount()).isNotEqualTo(0);
|
|
assertThat(duration.getSnapshot().size()).isNotEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
assertThat(scheduledRepetitively.getCount()).isEqualTo(1);
|
|
assertThat(scheduledOverrun.getCount()).isNotEqualTo(0);
|
|
assertThat(percentOfPeriod.getCount()).isNotEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testScheduleFixedDelayCallable() throws Exception {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ void scheduleFixedDelayCallable() throws Exception {
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
- assertThat(completed.getCount()).isZero();
|
|
- assertThat(duration.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
+ assertThat(completed.getCount()).isEqualTo(0);
|
|
+ assertThat(duration.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(scheduledOnce.getCount()).isZero();
|
|
- assertThat(scheduledRepetitively.getCount()).isZero();
|
|
- assertThat(scheduledOverrun.getCount()).isZero();
|
|
- assertThat(percentOfPeriod.getCount()).isZero();
|
|
+ assertThat(scheduledOnce.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledRepetitively.getCount()).isEqualTo(0);
|
|
+ assertThat(scheduledOverrun.getCount()).isEqualTo(0);
|
|
+ assertThat(percentOfPeriod.getCount()).isEqualTo(0);
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(1);
|
|
ScheduledFuture<?> theFuture =
|
|
instrumentedScheduledExecutor.scheduleWithFixedDelay(
|
|
() -> {
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
assertThat(running.getCount()).isEqualTo(1);
|
|
|
|
@@ -310,9 +310,9 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
theFuture.cancel(true);
|
|
TimeUnit.MILLISECONDS.sleep(200);
|
|
|
|
- assertThat(submitted.getCount()).isZero();
|
|
+ assertThat(submitted.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(running.getCount()).isZero();
|
|
+ assertThat(running.getCount()).isEqualTo(0);
|
|
assertThat(completed.getCount()).isNotEqualTo(0);
|
|
assertThat(duration.getCount()).isNotEqualTo(0);
|
|
assertThat(duration.getSnapshot().size()).isNotEqualTo(0);
|
|
@@ -322,7 +322,7 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
void tearDown() throws Exception {
|
|
instrumentedScheduledExecutor.shutdown();
|
|
if (!instrumentedScheduledExecutor.awaitTermination(2, TimeUnit.SECONDS)) {
|
|
- LOGGER.error("InstrumentedScheduledExecutorService did not terminate.");
|
|
+ LOG.error("InstrumentedScheduledExecutorService did not terminate.");
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedThreadFactoryTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/InstrumentedThreadFactoryTest.java
|
|
@@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedThreadFactoryTest {
|
|
+final class InstrumentedThreadFactoryTest {
|
|
private static final int THREAD_COUNT = 10;
|
|
|
|
private final ThreadFactory factory = Executors.defaultThreadFactory();
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MeterApproximationTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MeterApproximationTest.java
|
|
@@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
-public class MeterApproximationTest {
|
|
+final class MeterApproximationTest {
|
|
|
|
public static Collection<Object[]> ratesPerMinute() {
|
|
Object[][] data = new Object[][] {{15}, {60}, {600}, {6000}};
|
|
@@ -32,7 +32,7 @@ public class MeterApproximationTest {
|
|
3, TimeUnit.MINUTES);
|
|
|
|
assertThat(meter.getOneMinuteRate() * 60.0)
|
|
- .isEqualTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
+ .isCloseTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
}
|
|
|
|
@MethodSource("ratesPerMinute")
|
|
@@ -45,7 +45,7 @@ public class MeterApproximationTest {
|
|
13, TimeUnit.MINUTES);
|
|
|
|
assertThat(meter.getFiveMinuteRate() * 60.0)
|
|
- .isEqualTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
+ .isCloseTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
}
|
|
|
|
@MethodSource("ratesPerMinute")
|
|
@@ -58,7 +58,7 @@ public class MeterApproximationTest {
|
|
38, TimeUnit.MINUTES);
|
|
|
|
assertThat(meter.getFifteenMinuteRate() * 60.0)
|
|
- .isEqualTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
+ .isCloseTo(ratePerMinute, offset(0.1 * ratePerMinute));
|
|
}
|
|
|
|
private Meter simulateMetronome(
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MeterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MeterTest.java
|
|
@@ -9,8 +9,8 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MeterTest {
|
|
- private final Clock clock = mock(Clock.class);
|
|
+final class MeterTest {
|
|
+ private final Clock clock = mock();
|
|
private final Meter meter = new Meter(clock);
|
|
|
|
@BeforeEach
|
|
@@ -20,17 +20,17 @@ class MeterTest {
|
|
|
|
@Test
|
|
void startsOutWithNoRatesOrCount() {
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(meter.getSum()).isZero();
|
|
+ assertThat(meter.getSum()).isEqualTo(0);
|
|
|
|
- assertThat(meter.getMeanRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(meter.getMeanRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(meter.getOneMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(meter.getOneMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(meter.getFiveMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(meter.getFiveMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(meter.getFifteenMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(meter.getFifteenMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
}
|
|
|
|
@Test
|
|
@@ -42,12 +42,12 @@ class MeterTest {
|
|
|
|
assertThat(meter.getSum()).isEqualTo(10000000000L);
|
|
|
|
- assertThat(meter.getMeanRate()).isEqualTo(0.3, offset(0.001));
|
|
+ assertThat(meter.getMeanRate()).isCloseTo(0.3, offset(0.001));
|
|
|
|
- assertThat(meter.getOneMinuteRate()).isEqualTo(0.1840, offset(0.001));
|
|
+ assertThat(meter.getOneMinuteRate()).isCloseTo(0.1840, offset(0.001));
|
|
|
|
- assertThat(meter.getFiveMinuteRate()).isEqualTo(0.1966, offset(0.001));
|
|
+ assertThat(meter.getFiveMinuteRate()).isCloseTo(0.1966, offset(0.001));
|
|
|
|
- assertThat(meter.getFifteenMinuteRate()).isEqualTo(0.1988, offset(0.001));
|
|
+ assertThat(meter.getFifteenMinuteRate()).isCloseTo(0.1988, offset(0.001));
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MetricFilterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MetricFilterTest.java
|
|
@@ -5,7 +5,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricFilterTest {
|
|
+final class MetricFilterTest {
|
|
@Test
|
|
void theAllFilterMatchesAllMetrics() {
|
|
assertThat(MetricFilter.ALL.matches(MetricName.build(""), mock(Metric.class))).isTrue();
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MetricNameTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MetricNameTest.java
|
|
@@ -1,105 +1,106 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricNameTest {
|
|
+final class MetricNameTest {
|
|
@Test
|
|
- void testEmpty() {
|
|
+ void empty() {
|
|
assertThat(MetricName.EMPTY.getTags()).isEmpty();
|
|
- assertThat(MetricName.EMPTY.getKey()).isEqualTo("");
|
|
+ assertThat(MetricName.EMPTY.getKey()).isEmpty();
|
|
|
|
assertThat(MetricName.build()).isEqualTo(MetricName.EMPTY);
|
|
assertThat(MetricName.EMPTY.resolve((String) null)).isEqualTo(MetricName.EMPTY);
|
|
}
|
|
|
|
@Test
|
|
- void testEmptyResolve() {
|
|
+ void emptyResolve() {
|
|
final MetricName name = MetricName.build();
|
|
assertThat(name.resolve("foo")).isEqualTo(MetricName.build("foo"));
|
|
}
|
|
|
|
@Test
|
|
- void testResolveToEmpty() {
|
|
+ void resolveToEmpty() {
|
|
final MetricName name = MetricName.build("foo");
|
|
assertThat(name.resolve((String) null)).isEqualTo(MetricName.build("foo"));
|
|
}
|
|
|
|
@Test
|
|
- void testResolve() {
|
|
+ void resolve() {
|
|
final MetricName name = MetricName.build("foo");
|
|
assertThat(name.resolve("bar")).isEqualTo(MetricName.build("foo.bar"));
|
|
}
|
|
|
|
@Test
|
|
- void testResolveBothEmpty() {
|
|
+ void resolveBothEmpty() {
|
|
final MetricName name = MetricName.build();
|
|
assertThat(name.resolve((String) null)).isEqualTo(MetricName.EMPTY);
|
|
}
|
|
|
|
@Test
|
|
- void testAddTagsVarious() {
|
|
+ void addTagsVarious() {
|
|
final Map<String, String> refTags = new HashMap<String, String>();
|
|
refTags.put("foo", "bar");
|
|
final MetricName test = MetricName.EMPTY.tagged("foo", "bar");
|
|
final MetricName test2 = MetricName.EMPTY.tagged(refTags);
|
|
|
|
assertThat(test).isEqualTo(new MetricName("", refTags));
|
|
- assertThat(test.getTags()).isEqualTo(refTags);
|
|
+ assertThat(test.getTags()).containsExactlyInAnyOrderEntriesOf(refTags);
|
|
|
|
assertThat(test2).isEqualTo(new MetricName("", refTags));
|
|
- assertThat(test2.getTags()).isEqualTo(refTags);
|
|
+ assertThat(test2.getTags()).containsExactlyInAnyOrderEntriesOf(refTags);
|
|
}
|
|
|
|
@Test
|
|
- void testTaggedMoreArguments() {
|
|
+ void taggedMoreArguments() {
|
|
final Map<String, String> refTags = new HashMap<String, String>();
|
|
refTags.put("foo", "bar");
|
|
refTags.put("baz", "biz");
|
|
- assertThat(MetricName.EMPTY.tagged("foo", "bar", "baz", "biz").getTags()).isEqualTo(refTags);
|
|
+ assertThat(MetricName.EMPTY.tagged("foo", "bar", "baz", "biz").getTags())
|
|
+ .containsExactlyInAnyOrderEntriesOf(refTags);
|
|
}
|
|
|
|
@Test
|
|
- void testTaggedNotPairs() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- MetricName.EMPTY.tagged("foo");
|
|
- });
|
|
+ void taggedNotPairs() {
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ MetricName.EMPTY.tagged("foo");
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
- void testTaggedNotPairs2() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- MetricName.EMPTY.tagged("foo", "bar", "baz");
|
|
- });
|
|
+ void taggedNotPairs2() {
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ MetricName.EMPTY.tagged("foo", "bar", "baz");
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
- void testCompareTo() {
|
|
+ void compareTo() {
|
|
final MetricName a = MetricName.EMPTY.tagged("foo", "bar");
|
|
final MetricName b = MetricName.EMPTY.tagged("foo", "baz");
|
|
|
|
- assertThat(a.compareTo(b)).isLessThan(0);
|
|
- assertThat(b.compareTo(a)).isGreaterThan(0);
|
|
- assertThat(b.resolve("key").compareTo(b)).isGreaterThan(0);
|
|
- assertThat(b.compareTo(b.resolve("key"))).isLessThan(0);
|
|
+ assertThat(a).isLessThan(b);
|
|
+ assertThat(b).isGreaterThan(a);
|
|
+ assertThat(b.resolve("key")).isGreaterThan(b);
|
|
+ assertThat(b).isLessThan(b.resolve("key"));
|
|
}
|
|
|
|
@Test
|
|
- void testCompareTo2() {
|
|
+ void compareTo2() {
|
|
final MetricName a = MetricName.EMPTY.tagged("a", "x");
|
|
final MetricName b = MetricName.EMPTY.tagged("b", "x");
|
|
|
|
- assertThat(MetricName.EMPTY.compareTo(a)).isLessThan(0);
|
|
- assertThat(MetricName.EMPTY.compareTo(b)).isLessThan(0);
|
|
- assertThat(a.compareTo(b)).isLessThan(0);
|
|
- assertThat(b.compareTo(a)).isGreaterThan(0);
|
|
+ assertThat(MetricName.EMPTY).isLessThan(a);
|
|
+ assertThat(MetricName.EMPTY).isLessThan(b);
|
|
+ assertThat(a).isLessThan(b);
|
|
+ assertThat(b).isGreaterThan(a);
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MetricRegistryListenerTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MetricRegistryListenerTest.java
|
|
@@ -5,13 +5,13 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricRegistryListenerTest {
|
|
+final class MetricRegistryListenerTest {
|
|
private static final MetricName BLAH = MetricName.build("blah");
|
|
|
|
- private final Counter counter = mock(Counter.class);
|
|
- private final Histogram histogram = mock(Histogram.class);
|
|
- private final Meter meter = mock(Meter.class);
|
|
- private final Timer timer = mock(Timer.class);
|
|
+ private final Counter counter = mock();
|
|
+ private final Histogram histogram = mock();
|
|
+ private final Meter meter = mock();
|
|
+ private final Timer timer = mock();
|
|
private final MetricRegistryListener listener = new MetricRegistryListener.Base() {};
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/MetricRegistryTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/MetricRegistryTest.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
@@ -11,11 +12,10 @@ import static org.mockito.Mockito.verify;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
-import java.util.stream.Collectors;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricRegistryTest {
|
|
+final class MetricRegistryTest {
|
|
|
|
private static class CustomCounter extends Counter {
|
|
|
|
@@ -37,14 +37,14 @@ class MetricRegistryTest {
|
|
private static final MetricName GAUGE2 = MetricName.build("gauge2");
|
|
private static final MetricName SETTABLE_GAUGE = MetricName.build("settable-gauge");
|
|
private static final MetricName THING = MetricName.build("thing");
|
|
- private final MetricRegistryListener listener = mock(MetricRegistryListener.class);
|
|
+ private final MetricRegistryListener listener = mock();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Gauge<String> gauge = () -> "";
|
|
private final SettableGauge<String> settableGauge = new DefaultSettableGauge<>("");
|
|
- private final Counter counter = mock(Counter.class);
|
|
- private final Histogram histogram = mock(Histogram.class);
|
|
- private final Meter meter = mock(Meter.class);
|
|
- private final Timer timer = mock(Timer.class);
|
|
+ private final Counter counter = mock();
|
|
+ private final Histogram histogram = mock();
|
|
+ private final Meter meter = mock();
|
|
+ private final Timer timer = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
@@ -291,7 +291,7 @@ class MetricRegistryTest {
|
|
registry.register(METER2, meter);
|
|
registry.register(TIMER2, timer);
|
|
|
|
- final MetricRegistryListener other = mock(MetricRegistryListener.class);
|
|
+ final MetricRegistryListener other = mock();
|
|
registry.addListener(other);
|
|
|
|
verify(other).onGaugeAdded(GAUGE2, gauge);
|
|
@@ -425,7 +425,7 @@ class MetricRegistryTest {
|
|
MetricRegistry other = new MetricRegistry();
|
|
other.register(GAUGE, gauge);
|
|
registry.register(MetricName.build("nested"), other);
|
|
- assertThat(registry.getNames()).containsOnly(MetricName.build("nested.gauge"));
|
|
+ assertThat(registry.getNames()).containsExactly(MetricName.build("nested.gauge"));
|
|
}
|
|
|
|
@Test
|
|
@@ -501,10 +501,10 @@ class MetricRegistryTest {
|
|
Set<MetricName> childMetrics = child.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
}
|
|
|
|
@Test
|
|
@@ -522,10 +522,10 @@ class MetricRegistryTest {
|
|
Set<MetricName> childMetrics = child.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
}
|
|
|
|
@Test
|
|
@@ -548,19 +548,19 @@ class MetricRegistryTest {
|
|
Set<MetricName> deepChildMetrics = deepChild.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
assertThat(childMetrics)
|
|
.containsAll(
|
|
deepChildMetrics.stream()
|
|
.map(m -> MetricName.build("deep-child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
- assertThat(deepChildMetrics.size()).isEqualTo(3);
|
|
- assertThat(childMetrics.size()).isEqualTo(5);
|
|
+ assertThat(deepChildMetrics).hasSize(3);
|
|
+ assertThat(childMetrics).hasSize(5);
|
|
}
|
|
|
|
@Test
|
|
@@ -578,10 +578,10 @@ class MetricRegistryTest {
|
|
Set<MetricName> childMetrics = child.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
assertThat(childMetrics).doesNotContain(MetricName.build("test-1"));
|
|
}
|
|
@@ -604,10 +604,10 @@ class MetricRegistryTest {
|
|
Set<MetricName> childMetrics = child.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
assertThat(childMetrics).doesNotContain(MetricName.build("test-1"), MetricName.build("test-3"));
|
|
}
|
|
@@ -633,21 +633,21 @@ class MetricRegistryTest {
|
|
Set<MetricName> deepChildMetrics = deepChild.getMetrics().keySet();
|
|
|
|
assertThat(parentMetrics)
|
|
- .isEqualTo(
|
|
+ .hasSameElementsAs(
|
|
childMetrics.stream()
|
|
.map(m -> MetricName.build("child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
assertThat(childMetrics)
|
|
.containsAll(
|
|
deepChildMetrics.stream()
|
|
.map(m -> MetricName.build("deep-child", m.getKey()))
|
|
- .collect(Collectors.toSet()));
|
|
+ .collect(toImmutableSet()));
|
|
|
|
assertThat(deepChildMetrics).doesNotContain(MetricName.build("test-2"));
|
|
|
|
- assertThat(deepChildMetrics.size()).isEqualTo(1);
|
|
- assertThat(childMetrics.size()).isEqualTo(3);
|
|
+ assertThat(deepChildMetrics).hasSize(1);
|
|
+ assertThat(childMetrics).hasSize(3);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/NoopMetricRegistryTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/NoopMetricRegistryTest.java
|
|
@@ -1,7 +1,7 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
import static org.mockito.Mockito.verify;
|
|
@@ -12,16 +12,16 @@ import java.util.Set;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class NoopMetricRegistryTest {
|
|
+final class NoopMetricRegistryTest {
|
|
private static final MetricName METRIC_THING = MetricName.build("thing");
|
|
|
|
- private final MetricRegistryListener listener = mock(MetricRegistryListener.class);
|
|
+ private final MetricRegistryListener listener = mock();
|
|
private final NoopMetricRegistry registry = new NoopMetricRegistry();
|
|
private final Gauge<String> gauge = () -> "";
|
|
- private final Counter counter = mock(Counter.class);
|
|
- private final Histogram histogram = mock(Histogram.class);
|
|
- private final Meter meter = mock(Meter.class);
|
|
- private final Timer timer = mock(Timer.class);
|
|
+ private final Counter counter = mock();
|
|
+ private final Histogram histogram = mock();
|
|
+ private final Meter meter = mock();
|
|
+ private final Timer timer = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
@@ -220,8 +220,8 @@ class NoopMetricRegistryTest {
|
|
verify(listener, never()).onGaugeAdded(METRIC_THING, gauge1);
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("rawtypes")
|
|
+ @Test
|
|
void accessingACustomGaugeRegistersAndReusesIt() {
|
|
final MetricRegistry.MetricSupplier<Gauge<String>> supplier = () -> gauge;
|
|
final Gauge gauge1 = registry.gauge(METRIC_THING, supplier);
|
|
@@ -242,7 +242,7 @@ class NoopMetricRegistryTest {
|
|
registry.register(MetricName.build("meter"), meter);
|
|
registry.register(MetricName.build("timer"), timer);
|
|
|
|
- final MetricRegistryListener other = mock(MetricRegistryListener.class);
|
|
+ final MetricRegistryListener other = mock();
|
|
registry.addListener(other);
|
|
|
|
verify(other, never()).onGaugeAdded(MetricName.build("gauge"), gauge);
|
|
@@ -491,8 +491,8 @@ class NoopMetricRegistryTest {
|
|
@Test
|
|
void registerNullMetric() {
|
|
MetricRegistry registry = new NoopMetricRegistry();
|
|
- assertThatNullPointerException()
|
|
- .isThrownBy(() -> registry.register(MetricName.build("any_name"), null))
|
|
- .withMessage("metric == null");
|
|
+ assertThatThrownBy(() -> registry.register(MetricName.build("any_name"), null))
|
|
+ .isInstanceOf(NullPointerException.class)
|
|
+ .hasMessage("metric == null");
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/RatioGaugeTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/RatioGaugeTest.java
|
|
@@ -4,12 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class RatioGaugeTest {
|
|
+final class RatioGaugeTest {
|
|
@Test
|
|
void ratiosAreHumanReadable() {
|
|
final RatioGauge.Ratio ratio = RatioGauge.Ratio.of(100, 200);
|
|
|
|
- assertThat(ratio.toString()).isEqualTo("100.0:200.0");
|
|
+ assertThat(ratio).hasToString("100.0:200.0");
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/ScheduledReporterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/ScheduledReporterTest.java
|
|
@@ -1,10 +1,9 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
-import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
import static org.mockito.Mockito.any;
|
|
import static org.mockito.Mockito.eq;
|
|
import static org.mockito.Mockito.mock;
|
|
@@ -25,14 +24,14 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ScheduledReporterTest {
|
|
+final class ScheduledReporterTest {
|
|
private final Gauge<String> gauge = () -> "";
|
|
- private final Counter counter = mock(Counter.class);
|
|
- private final Histogram histogram = mock(Histogram.class);
|
|
- private final Meter meter = mock(Meter.class);
|
|
- private final Timer timer = mock(Timer.class);
|
|
+ private final Counter counter = mock();
|
|
+ private final Histogram histogram = mock();
|
|
+ private final Meter meter = mock();
|
|
+ private final Timer timer = mock();
|
|
|
|
- private final ScheduledExecutorService mockExecutor = mock(ScheduledExecutorService.class);
|
|
+ private final ScheduledExecutorService mockExecutor = mock();
|
|
private final ScheduledExecutorService customExecutor =
|
|
Executors.newSingleThreadScheduledExecutor();
|
|
private final ScheduledExecutorService externalExecutor =
|
|
@@ -145,7 +144,7 @@ class ScheduledReporterTest {
|
|
void shouldUsePeriodAsInitialDelayIfNotSpecifiedOtherwise() throws Exception {
|
|
reporterWithCustomMockExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
|
|
- verify(mockExecutor, times(1))
|
|
+ verify(mockExecutor)
|
|
.scheduleWithFixedDelay(any(Runnable.class), eq(200L), eq(200L), eq(TimeUnit.MILLISECONDS));
|
|
}
|
|
|
|
@@ -182,32 +181,32 @@ class ScheduledReporterTest {
|
|
|
|
@Test
|
|
void shouldDisallowToStartReportingMultiple() throws Exception {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- reporter.start(200, TimeUnit.MILLISECONDS);
|
|
- reporter.start(200, TimeUnit.MILLISECONDS);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ reporter.start(200, TimeUnit.MILLISECONDS);
|
|
+ reporter.start(200, TimeUnit.MILLISECONDS);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void shouldDisallowToStartReportingMultipleTimesOnCustomExecutor() throws Exception {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- reporterWithCustomExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
- reporterWithCustomExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ reporterWithCustomExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
+ reporterWithCustomExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void shouldDisallowToStartReportingMultipleTimesOnExternallyManagedExecutor() throws Exception {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- reporterWithExternallyManagedExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
- reporterWithExternallyManagedExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ reporterWithExternallyManagedExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
+ reporterWithExternallyManagedExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -231,15 +230,15 @@ class ScheduledReporterTest {
|
|
void shouldShutdownExecutorOnStopByDefault() {
|
|
reporterWithCustomExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
reporterWithCustomExecutor.stop();
|
|
- assertTrue(customExecutor.isTerminated());
|
|
+ assertThat(customExecutor.isTerminated()).isTrue();
|
|
}
|
|
|
|
@Test
|
|
void shouldNotShutdownExternallyManagedExecutorOnStop() {
|
|
reporterWithExternallyManagedExecutor.start(200, TimeUnit.MILLISECONDS);
|
|
reporterWithExternallyManagedExecutor.stop();
|
|
- assertFalse(mockExecutor.isTerminated());
|
|
- assertFalse(mockExecutor.isShutdown());
|
|
+ assertThat(mockExecutor.isTerminated()).isFalse();
|
|
+ assertThat(mockExecutor.isShutdown()).isFalse();
|
|
}
|
|
|
|
@Test
|
|
@@ -306,7 +305,7 @@ class ScheduledReporterTest {
|
|
|
|
Thread.sleep(1_000);
|
|
|
|
- verify(reporter, times(1))
|
|
+ verify(reporter)
|
|
.report(
|
|
map(MetricName.build("gauge"), gauge),
|
|
map(MetricName.build("counter"), counter),
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SharedMetricRegistriesTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SharedMetricRegistriesTest.java
|
|
@@ -2,13 +2,12 @@ package io.dropwizard.metrics5;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SharedMetricRegistriesTest {
|
|
+final class SharedMetricRegistriesTest {
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
@@ -28,7 +27,7 @@ class SharedMetricRegistriesTest {
|
|
void hasASetOfNames() {
|
|
SharedMetricRegistries.getOrCreate("one");
|
|
|
|
- assertThat(SharedMetricRegistries.names()).containsOnly("one");
|
|
+ assertThat(SharedMetricRegistries.names()).containsExactly("one");
|
|
}
|
|
|
|
@Test
|
|
@@ -60,7 +59,7 @@ class SharedMetricRegistriesTest {
|
|
() -> {
|
|
SharedMetricRegistries.getDefault();
|
|
});
|
|
- assertTrue(exception.getMessage().contains("Default registry name has not been set."));
|
|
+ assertThat(exception.getMessage()).contains("Default registry name has not been set.");
|
|
}
|
|
|
|
@Test
|
|
@@ -81,7 +80,7 @@ class SharedMetricRegistriesTest {
|
|
SharedMetricRegistries.setDefault("foobah");
|
|
SharedMetricRegistries.setDefault("borg");
|
|
});
|
|
- assertTrue(exception.getMessage().contains("Default metric registry name is already set."));
|
|
+ assertThat(exception.getMessage()).contains("Default metric registry name is already set.");
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SimpleSettableGaugeTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SimpleSettableGaugeTest.java
|
|
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SimpleSettableGaugeTest {
|
|
+final class SimpleSettableGaugeTest {
|
|
|
|
@Test
|
|
void defaultValue() {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/Slf4jReporterTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/Slf4jReporterTest.java
|
|
@@ -3,7 +3,6 @@ package io.dropwizard.metrics5;
|
|
import static io.dropwizard.metrics5.MetricAttribute.COUNT;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M1_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MIN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P50;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P999;
|
|
import static io.dropwizard.metrics5.MetricAttribute.STDDEV;
|
|
@@ -20,11 +19,11 @@ import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Marker;
|
|
|
|
-class Slf4jReporterTest {
|
|
+final class Slf4jReporterTest {
|
|
|
|
- private final Logger logger = mock(Logger.class);
|
|
- private final Marker marker = mock(Marker.class);
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+ private final Logger logger = mock();
|
|
+ private final Marker marker = mock();
|
|
+ private final MetricRegistry registry = mock();
|
|
|
|
/**
|
|
* The set of disabled metric attributes to pass to the Slf4jReporter builder in the default
|
|
@@ -79,7 +78,7 @@ class Slf4jReporterTest {
|
|
}
|
|
|
|
private Timer timer() {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -87,7 +86,7 @@ class Slf4jReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -104,10 +103,10 @@ class Slf4jReporterTest {
|
|
}
|
|
|
|
private Histogram histogram() {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -124,7 +123,7 @@ class Slf4jReporterTest {
|
|
}
|
|
|
|
private Meter meter() {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getMeanRate()).thenReturn(2.0);
|
|
when(meter.getOneMinuteRate()).thenReturn(3.0);
|
|
@@ -134,7 +133,7 @@ class Slf4jReporterTest {
|
|
}
|
|
|
|
private Counter counter() {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
return counter;
|
|
}
|
|
@@ -168,7 +167,7 @@ class Slf4jReporterTest {
|
|
|
|
@Test
|
|
void reportsHistogramValuesAtErrorWithDisabledMetricAttributes() {
|
|
- disabledMetricAttributes = EnumSet.of(COUNT, MIN, P50);
|
|
+ disabledMetricAttributes = EnumSet.of(COUNT, MetricAttribute.MIN, P50);
|
|
reportsHistogramValuesAtError(
|
|
"type=HISTOGRAM, name=test.histogram, max=2, mean=3.0, "
|
|
+ "stddev=5.0, p75=7.0, p95=8.0, p98=9.0, p99=10.0, p999=11.0");
|
|
@@ -192,7 +191,7 @@ class Slf4jReporterTest {
|
|
|
|
@Test
|
|
void reportsMeterValuesAtErrorWithDisabledMetricAttributes() {
|
|
- disabledMetricAttributes = EnumSet.of(MIN, P50, M1_RATE);
|
|
+ disabledMetricAttributes = EnumSet.of(MetricAttribute.MIN, P50, M1_RATE);
|
|
reportsMeterValuesAtError(
|
|
"type=METER, name=test.meter, count=1, m5_rate=4.0, m15_rate=5.0, "
|
|
+ "mean_rate=2.0, rate_unit=events/second");
|
|
@@ -218,7 +217,7 @@ class Slf4jReporterTest {
|
|
|
|
@Test
|
|
void reportsTimerValuesAtErrorWithDisabledMetricAttributes() {
|
|
- disabledMetricAttributes = EnumSet.of(MIN, STDDEV, P999, MEAN_RATE);
|
|
+ disabledMetricAttributes = EnumSet.of(MetricAttribute.MIN, STDDEV, P999, MEAN_RATE);
|
|
reportsTimerValuesAtError(
|
|
"type=TIMER, name=test.another.timer, count=1, max=100.0, mean=200.0, "
|
|
+ "p50=500.0, p75=600.0, p95=700.0, p98=800.0, p99=900.0, m1_rate=3.0, m5_rate=4.0, m15_rate=5.0, "
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowArrayReservoirTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowArrayReservoirTest.java
|
|
@@ -12,11 +12,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("Duplicates")
|
|
-class SlidingTimeWindowArrayReservoirTest {
|
|
+final class SlidingTimeWindowArrayReservoirTest {
|
|
|
|
@Test
|
|
void storesMeasurementsWithDuplicateTicks() {
|
|
- final Clock clock = mock(Clock.class);
|
|
+ final Clock clock = mock();
|
|
final SlidingTimeWindowArrayReservoir reservoir =
|
|
new SlidingTimeWindowArrayReservoir(10, NANOSECONDS, clock);
|
|
|
|
@@ -30,7 +30,7 @@ class SlidingTimeWindowArrayReservoirTest {
|
|
|
|
@Test
|
|
void boundsMeasurementsToATimeWindow() {
|
|
- final Clock clock = mock(Clock.class);
|
|
+ final Clock clock = mock();
|
|
final SlidingTimeWindowArrayReservoir reservoir =
|
|
new SlidingTimeWindowArrayReservoir(10, NANOSECONDS, clock);
|
|
|
|
@@ -82,7 +82,7 @@ class SlidingTimeWindowArrayReservoirTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetTickOverflow() {
|
|
+ void getTickOverflow() {
|
|
final Random random = new Random(0);
|
|
final int window = 128;
|
|
AtomicLong counter = new AtomicLong(0L);
|
|
@@ -99,7 +99,7 @@ class SlidingTimeWindowArrayReservoirTest {
|
|
// Set the clock to overflow in (2*window+1)ns
|
|
final ManualClock clock = new ManualClock();
|
|
clock.addNanos(Long.MAX_VALUE / 256 - 2 * window - clock.getTick());
|
|
- assertThat(clock.getTick() * 256).isGreaterThan(0);
|
|
+ assertThat(clock.getTick() * 256).isPositive();
|
|
|
|
// Create the reservoir
|
|
final SlidingTimeWindowArrayReservoir reservoir =
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowMovingAveragesTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowMovingAveragesTest.java
|
|
@@ -7,7 +7,7 @@ import java.time.Instant;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SlidingTimeWindowMovingAveragesTest {
|
|
+final class SlidingTimeWindowMovingAveragesTest {
|
|
|
|
private ManualClock clock;
|
|
private SlidingTimeWindowMovingAverages movingAverages;
|
|
@@ -42,7 +42,7 @@ class SlidingTimeWindowMovingAveragesTest {
|
|
|
|
SlidingTimeWindowMovingAverages stwm = new SlidingTimeWindowMovingAverages(clock);
|
|
|
|
- assertThat(stwm.calculateIndexOfTick(Instant.ofEpochSecond(0L))).isEqualTo(0);
|
|
+ assertThat(stwm.calculateIndexOfTick(Instant.EPOCH)).isEqualTo(0);
|
|
assertThat(stwm.calculateIndexOfTick(Instant.ofEpochSecond(1L))).isEqualTo(1);
|
|
}
|
|
|
|
@@ -60,7 +60,7 @@ class SlidingTimeWindowMovingAveragesTest {
|
|
}
|
|
|
|
// verify that no cleanup happened yet
|
|
- assertThat(movingAverages.oldestBucketTime).isEqualTo(Instant.ofEpochSecond(0L));
|
|
+ assertThat(movingAverages.oldestBucketTime).isEqualTo(Instant.EPOCH);
|
|
|
|
assertThat(meter.getOneMinuteRate()).isEqualTo(60.0);
|
|
assertThat(meter.getFiveMinuteRate()).isEqualTo(300.0);
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowReservoirTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingTimeWindowReservoirTest.java
|
|
@@ -9,10 +9,10 @@ import java.util.Arrays;
|
|
import java.util.Random;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SlidingTimeWindowReservoirTest {
|
|
+final class SlidingTimeWindowReservoirTest {
|
|
@Test
|
|
void storesMeasurementsWithDuplicateTicks() {
|
|
- final Clock clock = mock(Clock.class);
|
|
+ final Clock clock = mock();
|
|
final SlidingTimeWindowReservoir reservoir =
|
|
new SlidingTimeWindowReservoir(10, NANOSECONDS, clock);
|
|
|
|
@@ -26,7 +26,7 @@ class SlidingTimeWindowReservoirTest {
|
|
|
|
@Test
|
|
void boundsMeasurementsToATimeWindow() {
|
|
- final Clock clock = mock(Clock.class);
|
|
+ final Clock clock = mock();
|
|
when(clock.getTick()).thenReturn(0L);
|
|
|
|
final SlidingTimeWindowReservoir reservoir =
|
|
@@ -51,7 +51,7 @@ class SlidingTimeWindowReservoirTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetTickOverflow() {
|
|
+ void getTickOverflow() {
|
|
final Random random = new Random(0);
|
|
final int window = 128;
|
|
|
|
@@ -72,7 +72,7 @@ class SlidingTimeWindowReservoirTest {
|
|
|
|
// Set the clock to overflow in (2*window+1)ns
|
|
clock.addNanos(Long.MAX_VALUE / 256 - 2 * window - clock.getTick());
|
|
- assertThat(clock.getTick() * 256).isGreaterThan(0);
|
|
+ assertThat(clock.getTick() * 256).isPositive();
|
|
|
|
int updatesAfterThreshold = 0;
|
|
while (true) {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingWindowReservoirTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/SlidingWindowReservoirTest.java
|
|
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SlidingWindowReservoirTest {
|
|
+final class SlidingWindowReservoirTest {
|
|
private final SlidingWindowReservoir reservoir = new SlidingWindowReservoir(3);
|
|
|
|
@Test
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/TimerTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/TimerTest.java
|
|
@@ -12,8 +12,8 @@ import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class TimerTest {
|
|
- private final Reservoir reservoir = mock(Reservoir.class);
|
|
+final class TimerTest {
|
|
+ private final Reservoir reservoir = mock();
|
|
private final Clock clock =
|
|
new Clock() {
|
|
// a mock clock that increments its ticker by 50msec per call
|
|
@@ -28,23 +28,23 @@ class TimerTest {
|
|
|
|
@Test
|
|
void hasRates() {
|
|
- assertThat(timer.getCount()).isZero();
|
|
+ assertThat(timer.getCount()).isEqualTo(0);
|
|
|
|
- assertThat(timer.getSum()).isZero();
|
|
+ assertThat(timer.getSum()).isEqualTo(0);
|
|
|
|
- assertThat(timer.getMeanRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(timer.getMeanRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(timer.getOneMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(timer.getOneMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(timer.getFiveMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(timer.getFiveMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
|
|
- assertThat(timer.getFifteenMinuteRate()).isEqualTo(0.0, offset(0.001));
|
|
+ assertThat(timer.getFifteenMinuteRate()).isCloseTo(0.0, offset(0.001));
|
|
}
|
|
|
|
@Test
|
|
void updatesTheCountAndSumOnUpdates() {
|
|
- assertThat(timer.getCount()).isZero();
|
|
- assertThat(timer.getSum()).isZero();
|
|
+ assertThat(timer.getCount()).isEqualTo(0);
|
|
+ assertThat(timer.getSum()).isEqualTo(0);
|
|
|
|
timer.update(1, TimeUnit.SECONDS);
|
|
timer.update(5, TimeUnit.SECONDS);
|
|
@@ -101,7 +101,7 @@ class TimerTest {
|
|
|
|
@Test
|
|
void returnsTheSnapshotFromTheReservoir() {
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(reservoir.getSnapshot()).thenReturn(snapshot);
|
|
|
|
assertThat(timer.getSnapshot()).isEqualTo(snapshot);
|
|
@@ -111,8 +111,8 @@ class TimerTest {
|
|
void ignoresNegativeValues() {
|
|
timer.update(-1, TimeUnit.SECONDS);
|
|
|
|
- assertThat(timer.getCount()).isZero();
|
|
- assertThat(timer.getSum()).isZero();
|
|
+ assertThat(timer.getCount()).isEqualTo(0);
|
|
+ assertThat(timer.getSum()).isEqualTo(0);
|
|
|
|
verifyNoInteractions(reservoir);
|
|
}
|
|
@@ -130,15 +130,15 @@ class TimerTest {
|
|
void java8NegativeDuration() {
|
|
timer.update(Duration.ofMillis(-5678));
|
|
|
|
- assertThat(timer.getCount()).isZero();
|
|
+ assertThat(timer.getCount()).isEqualTo(0);
|
|
|
|
verifyNoInteractions(reservoir);
|
|
}
|
|
|
|
@Test
|
|
void tryWithResourcesWork() {
|
|
- assertThat(timer.getCount()).isZero();
|
|
- assertThat(timer.getSum()).isZero();
|
|
+ assertThat(timer.getCount()).isEqualTo(0);
|
|
+ assertThat(timer.getSum()).isEqualTo(0);
|
|
|
|
int dummy = 0;
|
|
try (Timer.Context context = timer.time()) {
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/UniformReservoirTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/UniformReservoirTest.java
|
|
@@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class UniformReservoirTest {
|
|
- @Test
|
|
+final class UniformReservoirTest {
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void aReservoirOf100OutOf1000Elements() {
|
|
final UniformReservoir reservoir = new UniformReservoir(100);
|
|
for (int i = 0; i < 1000; i++) {
|
|
@@ -20,7 +20,7 @@ class UniformReservoirTest {
|
|
assertThat(snapshot.size()).isEqualTo(100);
|
|
|
|
for (double i : snapshot.getValues()) {
|
|
- assertThat(i).isLessThan(1000).isGreaterThanOrEqualTo(0);
|
|
+ assertThat(i).isLessThan(1000).isNotNegative();
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/UniformSnapshotTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/UniformSnapshotTest.java
|
|
@@ -2,8 +2,8 @@ package io.dropwizard.metrics5;
|
|
|
|
import static java.util.Arrays.asList;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.assertj.core.api.Assertions.offset;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.util.Random;
|
|
@@ -12,74 +12,74 @@ import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class UniformSnapshotTest {
|
|
+final class UniformSnapshotTest {
|
|
private final Snapshot snapshot = new UniformSnapshot(new long[] {5, 1, 2, 3, 4});
|
|
|
|
@Test
|
|
void smallQuantilesAreTheFirstValue() {
|
|
- assertThat(snapshot.getValue(0.0)).isEqualTo(1, offset(0.1));
|
|
+ assertThat(snapshot.getValue(0.0)).isCloseTo(1, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void bigQuantilesAreTheLastValue() {
|
|
- assertThat(snapshot.getValue(1.0)).isEqualTo(5, offset(0.1));
|
|
+ assertThat(snapshot.getValue(1.0)).isCloseTo(5, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void disallowsNotANumberQuantile() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(Double.NaN);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(Double.NaN);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void disallowsNegativeQuantile() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(-0.5);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(-0.5);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void disallowsQuantileOverOne() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(1.5);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(1.5);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void hasAMedian() {
|
|
- assertThat(snapshot.getMedian()).isEqualTo(3, offset(0.1));
|
|
+ assertThat(snapshot.getMedian()).isCloseTo(3, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp75() {
|
|
- assertThat(snapshot.get75thPercentile()).isEqualTo(4.5, offset(0.1));
|
|
+ assertThat(snapshot.get75thPercentile()).isCloseTo(4.5, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp95() {
|
|
- assertThat(snapshot.get95thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get95thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp98() {
|
|
- assertThat(snapshot.get98thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get98thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp99() {
|
|
- assertThat(snapshot.get99thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get99thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp999() {
|
|
- assertThat(snapshot.get999thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get999thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
@@ -138,7 +138,7 @@ class UniformSnapshotTest {
|
|
|
|
snapshot.dump(output);
|
|
|
|
- assertThat(output.toString()).isEqualTo(String.format("1%n2%n3%n4%n5%n"));
|
|
+ assertThat(output).hasToString(String.format("1%n2%n3%n4%n5%n"));
|
|
}
|
|
|
|
@Test
|
|
@@ -158,41 +158,41 @@ class UniformSnapshotTest {
|
|
|
|
@Test
|
|
void calculatesTheStdDev() {
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(1.5811, offset(0.0001));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(1.5811, offset(0.0001));
|
|
}
|
|
|
|
@Test
|
|
void calculatesAMinOfZeroForAnEmptySnapshot() {
|
|
final Snapshot emptySnapshot = new UniformSnapshot(new long[] {});
|
|
|
|
- assertThat(emptySnapshot.getMin()).isZero();
|
|
+ assertThat(emptySnapshot.getMin()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
void calculatesAMaxOfZeroForAnEmptySnapshot() {
|
|
final Snapshot emptySnapshot = new UniformSnapshot(new long[] {});
|
|
|
|
- assertThat(emptySnapshot.getMax()).isZero();
|
|
+ assertThat(emptySnapshot.getMax()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
void calculatesAMeanOfZeroForAnEmptySnapshot() {
|
|
final Snapshot emptySnapshot = new UniformSnapshot(new long[] {});
|
|
|
|
- assertThat(emptySnapshot.getMean()).isZero();
|
|
+ assertThat(emptySnapshot.getMean()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
void calculatesAStdDevOfZeroForAnEmptySnapshot() {
|
|
final Snapshot emptySnapshot = new UniformSnapshot(new long[] {});
|
|
|
|
- assertThat(emptySnapshot.getStdDev()).isZero();
|
|
+ assertThat(emptySnapshot.getStdDev()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
void calculatesAStdDevOfZeroForASingletonSnapshot() {
|
|
final Snapshot singleItemSnapshot = new UniformSnapshot(new long[] {1});
|
|
|
|
- assertThat(singleItemSnapshot.getStdDev()).isZero();
|
|
+ assertThat(singleItemSnapshot.getStdDev()).isEqualTo(0);
|
|
}
|
|
}
|
|
--- a/metrics-core/src/test/java/io/dropwizard/metrics5/WeightedSnapshotTest.java
|
|
+++ b/metrics-core/src/test/java/io/dropwizard/metrics5/WeightedSnapshotTest.java
|
|
@@ -1,8 +1,10 @@
|
|
package io.dropwizard.metrics5;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.assertj.core.api.Assertions.offset;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.Mockito.doReturn;
|
|
import static org.mockito.Mockito.spy;
|
|
import static org.mockito.Mockito.when;
|
|
@@ -12,16 +14,16 @@ import java.io.ByteArrayOutputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.junit.jupiter.api.Test;
|
|
-import org.mockito.ArgumentMatchers;
|
|
|
|
-class WeightedSnapshotTest {
|
|
+final class WeightedSnapshotTest {
|
|
|
|
private static List<WeightedSnapshot.WeightedSample> weightedArray(
|
|
long[] values, double[] weights) {
|
|
- if (values.length != weights.length) {
|
|
- throw new IllegalArgumentException(
|
|
- "Mismatched lengths: " + values.length + " vs " + weights.length);
|
|
- }
|
|
+ checkArgument(
|
|
+ values.length == weights.length,
|
|
+ "Mismatched lengths: %s vs %s",
|
|
+ values.length,
|
|
+ weights.length);
|
|
|
|
final List<WeightedSnapshot.WeightedSample> samples = new ArrayList<>();
|
|
for (int i = 0; i < values.length; i++) {
|
|
@@ -36,69 +38,69 @@ class WeightedSnapshotTest {
|
|
|
|
@Test
|
|
void smallQuantilesAreTheFirstValue() {
|
|
- assertThat(snapshot.getValue(0.0)).isEqualTo(1.0, offset(0.1));
|
|
+ assertThat(snapshot.getValue(0.0)).isCloseTo(1.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void bigQuantilesAreTheLastValue() {
|
|
- assertThat(snapshot.getValue(1.0)).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.getValue(1.0)).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void disallowsNotANumberQuantile() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(Double.NaN);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(Double.NaN);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void disallowsNegativeQuantile() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(-0.5);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(-0.5);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void disallowsQuantileOverOne() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- snapshot.getValue(1.5);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ snapshot.getValue(1.5);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void hasAMedian() {
|
|
- assertThat(snapshot.getMedian()).isEqualTo(3.0, offset(0.1));
|
|
+ assertThat(snapshot.getMedian()).isCloseTo(3.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp75() {
|
|
- assertThat(snapshot.get75thPercentile()).isEqualTo(4.0, offset(0.1));
|
|
+ assertThat(snapshot.get75thPercentile()).isCloseTo(4.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp95() {
|
|
- assertThat(snapshot.get95thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get95thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp98() {
|
|
- assertThat(snapshot.get98thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get98thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp99() {
|
|
- assertThat(snapshot.get99thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get99thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
void hasAp999() {
|
|
- assertThat(snapshot.get999thPercentile()).isEqualTo(5.0, offset(0.1));
|
|
+ assertThat(snapshot.get999thPercentile()).isCloseTo(5.0, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
@@ -118,7 +120,7 @@ class WeightedSnapshotTest {
|
|
final List<WeightedSample> spyItems = spy(originalItems);
|
|
doReturn(originalItems.toArray(new WeightedSample[] {}))
|
|
.when(spyItems)
|
|
- .toArray(ArgumentMatchers.any(WeightedSample[].class));
|
|
+ .toArray(any(WeightedSample[].class));
|
|
when(spyItems.size()).thenReturn(4, 5);
|
|
|
|
final Snapshot other = new WeightedSnapshot(spyItems);
|
|
@@ -133,7 +135,7 @@ class WeightedSnapshotTest {
|
|
final List<WeightedSample> spyItems = spy(originalItems);
|
|
doReturn(originalItems.toArray(new WeightedSample[] {}))
|
|
.when(spyItems)
|
|
- .toArray(ArgumentMatchers.any(WeightedSample[].class));
|
|
+ .toArray(any(WeightedSample[].class));
|
|
when(spyItems.size()).thenReturn(6, 5);
|
|
|
|
final Snapshot other = new WeightedSnapshot(spyItems);
|
|
@@ -147,7 +149,7 @@ class WeightedSnapshotTest {
|
|
|
|
snapshot.dump(output);
|
|
|
|
- assertThat(output.toString()).isEqualTo(String.format("1%n2%n3%n4%n5%n"));
|
|
+ assertThat(output).hasToString(String.format("1%n2%n3%n4%n5%n"));
|
|
}
|
|
|
|
@Test
|
|
@@ -167,7 +169,7 @@ class WeightedSnapshotTest {
|
|
|
|
@Test
|
|
void calculatesTheStdDev() {
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(1.2688, offset(0.0001));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(1.2688, offset(0.0001));
|
|
}
|
|
|
|
@Test
|
|
@@ -175,7 +177,7 @@ class WeightedSnapshotTest {
|
|
final Snapshot emptySnapshot =
|
|
new WeightedSnapshot(weightedArray(new long[] {}, new double[] {}));
|
|
|
|
- assertThat(emptySnapshot.getMin()).isZero();
|
|
+ assertThat(emptySnapshot.getMin()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
@@ -183,7 +185,7 @@ class WeightedSnapshotTest {
|
|
final Snapshot emptySnapshot =
|
|
new WeightedSnapshot(weightedArray(new long[] {}, new double[] {}));
|
|
|
|
- assertThat(emptySnapshot.getMax()).isZero();
|
|
+ assertThat(emptySnapshot.getMax()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
@@ -191,7 +193,7 @@ class WeightedSnapshotTest {
|
|
final Snapshot emptySnapshot =
|
|
new WeightedSnapshot(weightedArray(new long[] {}, new double[] {}));
|
|
|
|
- assertThat(emptySnapshot.getMean()).isZero();
|
|
+ assertThat(emptySnapshot.getMean()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
@@ -199,7 +201,7 @@ class WeightedSnapshotTest {
|
|
final Snapshot emptySnapshot =
|
|
new WeightedSnapshot(weightedArray(new long[] {}, new double[] {}));
|
|
|
|
- assertThat(emptySnapshot.getStdDev()).isZero();
|
|
+ assertThat(emptySnapshot.getStdDev()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
@@ -207,7 +209,7 @@ class WeightedSnapshotTest {
|
|
final Snapshot singleItemSnapshot =
|
|
new WeightedSnapshot(weightedArray(new long[] {1}, new double[] {1.0}));
|
|
|
|
- assertThat(singleItemSnapshot.getStdDev()).isZero();
|
|
+ assertThat(singleItemSnapshot.getStdDev()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-ehcache/src/test/java/io/dropwizard/metrics5/ehcache/InstrumentedCacheDecoratorFactoryTest.java
|
|
+++ b/metrics-ehcache/src/test/java/io/dropwizard/metrics5/ehcache/InstrumentedCacheDecoratorFactoryTest.java
|
|
@@ -12,7 +12,7 @@ import net.sf.ehcache.Element;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedCacheDecoratorFactoryTest {
|
|
+final class InstrumentedCacheDecoratorFactoryTest {
|
|
private static final CacheManager MANAGER = CacheManager.create();
|
|
|
|
private MetricRegistry registry;
|
|
--- a/metrics-ehcache/src/test/java/io/dropwizard/metrics5/ehcache/InstrumentedEhcacheTest.java
|
|
+++ b/metrics-ehcache/src/test/java/io/dropwizard/metrics5/ehcache/InstrumentedEhcacheTest.java
|
|
@@ -13,7 +13,7 @@ import net.sf.ehcache.config.CacheConfiguration;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedEhcacheTest {
|
|
+final class InstrumentedEhcacheTest {
|
|
private static final CacheManager MANAGER = CacheManager.create();
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
--- a/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/Graphite.java
|
|
+++ b/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/Graphite.java
|
|
@@ -1,8 +1,11 @@
|
|
package io.dropwizard.metrics5.graphite;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
+import com.google.common.base.Strings;
|
|
import java.io.BufferedWriter;
|
|
import java.io.IOException;
|
|
import java.io.OutputStreamWriter;
|
|
@@ -29,7 +32,7 @@ public class Graphite implements GraphiteSender {
|
|
private Writer writer;
|
|
private int failures;
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(Graphite.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(Graphite.class);
|
|
|
|
/**
|
|
* Creates a new client which connects to the given address using the default {@link
|
|
@@ -63,13 +66,9 @@ public class Graphite implements GraphiteSender {
|
|
* @param charset the character set used by the server
|
|
*/
|
|
public Graphite(String hostname, int port, SocketFactory socketFactory, Charset charset) {
|
|
- if (hostname == null || hostname.isEmpty()) {
|
|
- throw new IllegalArgumentException("hostname must not be null or empty");
|
|
- }
|
|
+ checkArgument(!Strings.isNullOrEmpty(hostname), "hostname must not be null or empty");
|
|
|
|
- if (port < 0 || port > 65535) {
|
|
- throw new IllegalArgumentException("port must be a valid IP port (0-65535)");
|
|
- }
|
|
+ checkArgument(port >= 0 && port <= 65535, "port must be a valid IP port (0-65535)");
|
|
|
|
this.hostname = hostname;
|
|
this.port = port;
|
|
@@ -116,9 +115,7 @@ public class Graphite implements GraphiteSender {
|
|
|
|
@Override
|
|
public void connect() throws IllegalStateException, IOException {
|
|
- if (isConnected()) {
|
|
- throw new IllegalStateException("Already connected");
|
|
- }
|
|
+ checkState(!isConnected(), "Already connected");
|
|
InetSocketAddress address = this.address;
|
|
// the previous dns retry logic did not work, as address.getAddress would always return the
|
|
// cached value
|
|
@@ -178,7 +175,7 @@ public class Graphite implements GraphiteSender {
|
|
writer.close();
|
|
}
|
|
} catch (IOException ex) {
|
|
- LOGGER.debug("Error closing writer", ex);
|
|
+ LOG.debug("Error closing writer", ex);
|
|
} finally {
|
|
this.writer = null;
|
|
}
|
|
@@ -188,7 +185,7 @@ public class Graphite implements GraphiteSender {
|
|
socket.close();
|
|
}
|
|
} catch (IOException ex) {
|
|
- LOGGER.debug("Error closing socket", ex);
|
|
+ LOG.debug("Error closing socket", ex);
|
|
} finally {
|
|
this.socket = null;
|
|
}
|
|
--- a/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteRabbitMQ.java
|
|
+++ b/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteRabbitMQ.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.graphite;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
import com.rabbitmq.client.Channel;
|
|
@@ -109,9 +110,7 @@ public class GraphiteRabbitMQ implements GraphiteSender {
|
|
|
|
@Override
|
|
public void connect() throws IllegalStateException, IOException {
|
|
- if (isConnected()) {
|
|
- throw new IllegalStateException("Already connected");
|
|
- }
|
|
+ checkState(!isConnected(), "Already connected");
|
|
|
|
try {
|
|
connection = connectionFactory.newConnection();
|
|
@@ -132,8 +131,7 @@ public class GraphiteRabbitMQ implements GraphiteSender {
|
|
final String sanitizedName = sanitize(name);
|
|
final String sanitizedValue = sanitize(value);
|
|
|
|
- final String message =
|
|
- sanitizedName + ' ' + sanitizedValue + ' ' + Long.toString(timestamp) + '\n';
|
|
+ final String message = sanitizedName + ' ' + sanitizedValue + ' ' + timestamp + '\n';
|
|
channel.basicPublish(exchange, sanitizedName, null, message.getBytes(UTF_8));
|
|
} catch (IOException e) {
|
|
failures++;
|
|
--- a/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteReporter.java
|
|
+++ b/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteReporter.java
|
|
@@ -4,10 +4,8 @@ import static io.dropwizard.metrics5.MetricAttribute.COUNT;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M15_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M1_RATE;
|
|
import static io.dropwizard.metrics5.MetricAttribute.M5_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MAX;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.MEAN_RATE;
|
|
-import static io.dropwizard.metrics5.MetricAttribute.MIN;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P50;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P75;
|
|
import static io.dropwizard.metrics5.MetricAttribute.P95;
|
|
@@ -17,6 +15,7 @@ import static io.dropwizard.metrics5.MetricAttribute.P999;
|
|
import static io.dropwizard.metrics5.MetricAttribute.STDDEV;
|
|
import static io.dropwizard.metrics5.MetricAttribute.SUM;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
@@ -31,7 +30,6 @@ import io.dropwizard.metrics5.ScheduledReporter;
|
|
import io.dropwizard.metrics5.Snapshot;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import java.io.IOException;
|
|
-import java.util.Collections;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
@@ -85,7 +83,7 @@ public class GraphiteReporter extends ScheduledReporter {
|
|
this.filter = MetricFilter.ALL;
|
|
this.executor = null;
|
|
this.shutdownExecutorOnStop = true;
|
|
- this.disabledMetricAttributes = Collections.emptySet();
|
|
+ this.disabledMetricAttributes = ImmutableSet.of();
|
|
this.addMetricAttributesAsTags = false;
|
|
this.floatingPointFormatter = DEFAULT_FP_FORMATTER;
|
|
}
|
|
@@ -249,7 +247,7 @@ public class GraphiteReporter extends ScheduledReporter {
|
|
}
|
|
}
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(GraphiteReporter.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(GraphiteReporter.class);
|
|
// the Carbon plaintext format is pretty underspecified, but it seems like it just wants
|
|
// US-formatted digits
|
|
private static final DoubleFunction<String> DEFAULT_FP_FORMATTER =
|
|
@@ -430,12 +428,12 @@ public class GraphiteReporter extends ScheduledReporter {
|
|
}
|
|
graphite.flush();
|
|
} catch (IOException e) {
|
|
- LOGGER.warn("Unable to report to Graphite", graphite, e);
|
|
+ LOG.warn("Unable to report to Graphite", graphite, e);
|
|
} finally {
|
|
try {
|
|
graphite.close();
|
|
} catch (IOException e1) {
|
|
- LOGGER.warn("Error closing Graphite", graphite, e1);
|
|
+ LOG.warn("Error closing Graphite", graphite, e1);
|
|
}
|
|
}
|
|
}
|
|
@@ -448,16 +446,16 @@ public class GraphiteReporter extends ScheduledReporter {
|
|
try {
|
|
graphite.close();
|
|
} catch (IOException e) {
|
|
- LOGGER.debug("Error disconnecting from Graphite", graphite, e);
|
|
+ LOG.debug("Error disconnecting from Graphite", graphite, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void reportTimer(MetricName name, Timer timer, long timestamp) throws IOException {
|
|
final Snapshot snapshot = timer.getSnapshot();
|
|
- sendIfEnabled(MAX, name, convertDuration(snapshot.getMax()), timestamp);
|
|
+ sendIfEnabled(MetricAttribute.MAX, name, convertDuration(snapshot.getMax()), timestamp);
|
|
sendIfEnabled(MEAN, name, convertDuration(snapshot.getMean()), timestamp);
|
|
- sendIfEnabled(MIN, name, convertDuration(snapshot.getMin()), timestamp);
|
|
+ sendIfEnabled(MetricAttribute.MIN, name, convertDuration(snapshot.getMin()), timestamp);
|
|
sendIfEnabled(STDDEV, name, convertDuration(snapshot.getStdDev()), timestamp);
|
|
sendIfEnabled(P50, name, convertDuration(snapshot.getMedian()), timestamp);
|
|
sendIfEnabled(P75, name, convertDuration(snapshot.get75thPercentile()), timestamp);
|
|
@@ -484,9 +482,9 @@ public class GraphiteReporter extends ScheduledReporter {
|
|
final Snapshot snapshot = histogram.getSnapshot();
|
|
sendIfEnabled(COUNT, name, histogram.getCount(), timestamp);
|
|
sendIfEnabled(SUM, name, histogram.getSum(), timestamp);
|
|
- sendIfEnabled(MAX, name, snapshot.getMax(), timestamp);
|
|
+ sendIfEnabled(MetricAttribute.MAX, name, snapshot.getMax(), timestamp);
|
|
sendIfEnabled(MEAN, name, snapshot.getMean(), timestamp);
|
|
- sendIfEnabled(MIN, name, snapshot.getMin(), timestamp);
|
|
+ sendIfEnabled(MetricAttribute.MIN, name, snapshot.getMin(), timestamp);
|
|
sendIfEnabled(STDDEV, name, snapshot.getStdDev(), timestamp);
|
|
sendIfEnabled(P50, name, snapshot.getMedian(), timestamp);
|
|
sendIfEnabled(P75, name, snapshot.get75thPercentile(), timestamp);
|
|
--- a/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteUDP.java
|
|
+++ b/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/GraphiteUDP.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.graphite;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
import java.io.IOException;
|
|
@@ -43,9 +44,7 @@ public class GraphiteUDP implements GraphiteSender {
|
|
|
|
@Override
|
|
public void connect() throws IllegalStateException, IOException {
|
|
- if (isConnected()) {
|
|
- throw new IllegalStateException("Already connected");
|
|
- }
|
|
+ checkState(!isConnected(), "Already connected");
|
|
|
|
// Resolve hostname
|
|
if (hostname != null) {
|
|
@@ -63,7 +62,7 @@ public class GraphiteUDP implements GraphiteSender {
|
|
@Override
|
|
public void send(String name, String value, long timestamp) throws IOException {
|
|
try {
|
|
- String str = sanitize(name) + ' ' + sanitize(value) + ' ' + Long.toString(timestamp) + '\n';
|
|
+ String str = sanitize(name) + ' ' + sanitize(value) + ' ' + timestamp + '\n';
|
|
ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes(UTF_8));
|
|
datagramChannel.send(byteBuffer, address);
|
|
this.failures = 0;
|
|
--- a/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/PickledGraphite.java
|
|
+++ b/metrics-graphite/src/main/java/io/dropwizard/metrics5/graphite/PickledGraphite.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.graphite;
|
|
|
|
+import static com.google.common.base.Preconditions.checkState;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
import java.io.BufferedWriter;
|
|
@@ -48,7 +49,7 @@ public class PickledGraphite implements GraphiteSender {
|
|
QUOTE = '\'',
|
|
LF = '\n';
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(PickledGraphite.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(PickledGraphite.class);
|
|
private static final int DEFAULT_BATCH_SIZE = 100;
|
|
|
|
private int batchSize;
|
|
@@ -173,9 +174,7 @@ public class PickledGraphite implements GraphiteSender {
|
|
|
|
@Override
|
|
public void connect() throws IllegalStateException, IOException {
|
|
- if (isConnected()) {
|
|
- throw new IllegalStateException("Already connected");
|
|
- }
|
|
+ checkState(!isConnected(), "Already connected");
|
|
InetSocketAddress address = this.address;
|
|
if (address == null) {
|
|
address = new InetSocketAddress(hostname, port);
|
|
@@ -249,7 +248,7 @@ public class PickledGraphite implements GraphiteSender {
|
|
* message to graphite 3. Clear out the list of metrics
|
|
*/
|
|
private void writeMetrics() throws IOException {
|
|
- if (metrics.size() > 0) {
|
|
+ if (!metrics.isEmpty()) {
|
|
try {
|
|
byte[] payload = pickleMetrics(metrics);
|
|
byte[] header = ByteBuffer.allocate(4).putInt(payload.length).array();
|
|
@@ -260,8 +259,8 @@ public class PickledGraphite implements GraphiteSender {
|
|
outputStream.write(payload);
|
|
outputStream.flush();
|
|
|
|
- if (LOGGER.isDebugEnabled()) {
|
|
- LOGGER.debug("Wrote {} metrics", metrics.size());
|
|
+ if (LOG.isDebugEnabled()) {
|
|
+ LOG.debug("Wrote {} metrics", metrics.size());
|
|
}
|
|
} catch (IOException e) {
|
|
this.failures++;
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteRabbitMQTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteRabbitMQTest.java
|
|
@@ -8,7 +8,6 @@ import static org.mockito.Mockito.anyString;
|
|
import static org.mockito.Mockito.atMost;
|
|
import static org.mockito.Mockito.doThrow;
|
|
import static org.mockito.Mockito.mock;
|
|
-import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@@ -20,14 +19,14 @@ import java.net.UnknownHostException;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class GraphiteRabbitMQTest {
|
|
- private final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
|
- private final Connection connection = mock(Connection.class);
|
|
- private final Channel channel = mock(Channel.class);
|
|
+final class GraphiteRabbitMQTest {
|
|
+ private final ConnectionFactory connectionFactory = mock();
|
|
+ private final Connection connection = mock();
|
|
+ private final Channel channel = mock();
|
|
|
|
- private final ConnectionFactory bogusConnectionFactory = mock(ConnectionFactory.class);
|
|
- private final Connection bogusConnection = mock(Connection.class);
|
|
- private final Channel bogusChannel = mock(Channel.class);
|
|
+ private final ConnectionFactory bogusConnectionFactory = mock();
|
|
+ private final Connection bogusConnection = mock();
|
|
+ private final Channel bogusChannel = mock();
|
|
|
|
private final GraphiteRabbitMQ graphite = new GraphiteRabbitMQ(connectionFactory, "graphite");
|
|
|
|
@@ -92,10 +91,9 @@ class GraphiteRabbitMQTest {
|
|
|
|
String expectedMessage = "name value 100\n";
|
|
|
|
- verify(channel, times(1))
|
|
- .basicPublish("graphite", "name", null, expectedMessage.getBytes(UTF_8));
|
|
+ verify(channel).basicPublish("graphite", "name", null, expectedMessage.getBytes(UTF_8));
|
|
|
|
- assertThat(graphite.getFailures()).isZero();
|
|
+ assertThat(graphite.getFailures()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
@@ -105,10 +103,10 @@ class GraphiteRabbitMQTest {
|
|
|
|
String expectedMessage = "name-to-sanitize value-to-sanitize 100\n";
|
|
|
|
- verify(channel, times(1))
|
|
+ verify(channel)
|
|
.basicPublish("graphite", "name-to-sanitize", null, expectedMessage.getBytes(UTF_8));
|
|
|
|
- assertThat(graphite.getFailures()).isZero();
|
|
+ assertThat(graphite.getFailures()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteReporterTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteReporterTest.java
|
|
@@ -8,6 +8,7 @@ import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
@@ -22,7 +23,6 @@ import io.dropwizard.metrics5.Timer;
|
|
import java.net.UnknownHostException;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormatSymbols;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.Locale;
|
|
import java.util.Set;
|
|
@@ -33,15 +33,15 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.InOrder;
|
|
|
|
-class GraphiteReporterTest {
|
|
+final class GraphiteReporterTest {
|
|
private static final MetricName GAUGE = MetricName.build("gauge");
|
|
private static final MetricName METER = MetricName.build("meter");
|
|
private static final MetricName COUNTER = MetricName.build("counter");
|
|
|
|
private final long timestamp = 1000198;
|
|
- private final Clock clock = mock(Clock.class);
|
|
- private final Graphite graphite = mock(Graphite.class);
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+ private final Clock clock = mock();
|
|
+ private final Graphite graphite = mock();
|
|
+ private final MetricRegistry registry = mock();
|
|
private final GraphiteReporter reporter =
|
|
GraphiteReporter.forRegistry(registry)
|
|
.withClock(clock)
|
|
@@ -49,7 +49,7 @@ class GraphiteReporterTest {
|
|
.convertRatesTo(TimeUnit.SECONDS)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.build(graphite);
|
|
|
|
private final GraphiteReporter minuteRateReporter =
|
|
@@ -59,7 +59,7 @@ class GraphiteReporterTest {
|
|
.convertRatesTo(TimeUnit.MINUTES)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.build(graphite);
|
|
|
|
@BeforeEach
|
|
@@ -179,7 +179,7 @@ class GraphiteReporterTest {
|
|
.convertRatesTo(TimeUnit.SECONDS)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.withFloatingPointFormatter(formatter::format)
|
|
.build(graphite)) {
|
|
reportGaugeValue(graphiteReporter, 0.000045322);
|
|
@@ -222,7 +222,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void reportsCounters() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
reporter.report(map(), map(COUNTER, counter), map(), map(), map());
|
|
@@ -238,11 +238,11 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void reportsHistograms() throws Exception {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(12L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -280,7 +280,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void reportsMeters() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -306,7 +306,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void reportsMetersInMinutes() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -333,7 +333,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void reportsTimers() throws Exception {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(6));
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -341,7 +341,7 @@ class GraphiteReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -410,7 +410,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void disabledMetricsAttribute() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -418,7 +418,7 @@ class GraphiteReporterTest {
|
|
when(meter.getFifteenMinuteRate()).thenReturn(4.0);
|
|
when(meter.getMeanRate()).thenReturn(5.0);
|
|
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(11L);
|
|
|
|
Set<MetricAttribute> disabledMetricAttributes =
|
|
@@ -450,7 +450,7 @@ class GraphiteReporterTest {
|
|
|
|
@Test
|
|
void sendsMetricAttributesAsTagsIfEnabled() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
getReporterThatSendsMetricAttributesAsTags()
|
|
@@ -476,7 +476,7 @@ class GraphiteReporterTest {
|
|
MetricFilter.ALL,
|
|
null,
|
|
false,
|
|
- Collections.emptySet(),
|
|
+ ImmutableSet.of(),
|
|
false) {
|
|
@Override
|
|
protected String format(double v) {
|
|
@@ -492,7 +492,7 @@ class GraphiteReporterTest {
|
|
.convertRatesTo(TimeUnit.SECONDS)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.addMetricAttributesAsTags(true)
|
|
.build(graphite);
|
|
}
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteSanitizeTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteSanitizeTest.java
|
|
@@ -3,7 +3,7 @@ package io.dropwizard.metrics5.graphite;
|
|
import org.assertj.core.api.SoftAssertions;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class GraphiteSanitizeTest {
|
|
+final class GraphiteSanitizeTest {
|
|
@Test
|
|
void sanitizeGraphiteValues() {
|
|
SoftAssertions softly = new SoftAssertions();
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteTest.java
|
|
@@ -23,14 +23,14 @@ import javax.net.SocketFactory;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class GraphiteTest {
|
|
+final class GraphiteTest {
|
|
private final String host = "example.com";
|
|
private final int port = 1234;
|
|
- private final SocketFactory socketFactory = mock(SocketFactory.class);
|
|
+ private final SocketFactory socketFactory = mock();
|
|
private final InetSocketAddress address = new InetSocketAddress(host, port);
|
|
|
|
- private final Socket socket = mock(Socket.class);
|
|
- private final ByteArrayOutputStream output = spy(ByteArrayOutputStream.class);
|
|
+ private final Socket socket = mock();
|
|
+ private final ByteArrayOutputStream output = spy();
|
|
|
|
@BeforeEach
|
|
void setUp() throws Exception {
|
|
@@ -84,7 +84,7 @@ class GraphiteTest {
|
|
@Test
|
|
void measuresFailures() throws IOException {
|
|
try (Graphite graphite = new Graphite(address, socketFactory)) {
|
|
- assertThat(graphite.getFailures()).isZero();
|
|
+ assertThat(graphite.getFailures()).isEqualTo(0);
|
|
}
|
|
}
|
|
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteUDPTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/GraphiteUDPTest.java
|
|
@@ -1,15 +1,15 @@
|
|
package io.dropwizard.metrics5.graphite;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.channels.DatagramChannel;
|
|
import org.junit.jupiter.api.Test;
|
|
-import org.mockito.Mockito;
|
|
|
|
-class GraphiteUDPTest {
|
|
+final class GraphiteUDPTest {
|
|
|
|
private final String host = "example.com";
|
|
private final int port = 1234;
|
|
@@ -30,7 +30,7 @@ class GraphiteUDPTest {
|
|
@Test
|
|
void writesValue() throws Exception {
|
|
graphiteUDP = new GraphiteUDP(host, port);
|
|
- DatagramChannel mockDatagramChannel = Mockito.mock(DatagramChannel.class);
|
|
+ DatagramChannel mockDatagramChannel = mock();
|
|
graphiteUDP.setDatagramChannel(mockDatagramChannel);
|
|
graphiteUDP.setAddress(new InetSocketAddress(host, port));
|
|
|
|
--- a/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/PickledGraphiteTest.java
|
|
+++ b/metrics-graphite/src/test/java/io/dropwizard/metrics5/graphite/PickledGraphiteTest.java
|
|
@@ -31,13 +31,13 @@ import org.junit.jupiter.api.Test;
|
|
import org.python.core.PyList;
|
|
import org.python.core.PyTuple;
|
|
|
|
-class PickledGraphiteTest {
|
|
- private final SocketFactory socketFactory = mock(SocketFactory.class);
|
|
+final class PickledGraphiteTest {
|
|
+ private final SocketFactory socketFactory = mock();
|
|
private final InetSocketAddress address = new InetSocketAddress("example.com", 1234);
|
|
private final PickledGraphite graphite = new PickledGraphite(address, socketFactory, UTF_8, 2);
|
|
|
|
- private final Socket socket = mock(Socket.class);
|
|
- private final ByteArrayOutputStream output = spy(ByteArrayOutputStream.class);
|
|
+ private final Socket socket = mock();
|
|
+ private final ByteArrayOutputStream output = spy();
|
|
|
|
private CompiledScript unpickleScript;
|
|
|
|
--- a/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/AsyncHealthCheckDecorator.java
|
|
+++ b/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/AsyncHealthCheckDecorator.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.health;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.health.annotation.Async;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
@@ -29,10 +31,10 @@ public class AsyncHealthCheckDecorator implements HealthCheck, Runnable {
|
|
this.healthyTtl =
|
|
async.unit().toMillis(async.healthyTtl() <= 0 ? 2 * async.period() : async.healthyTtl());
|
|
result =
|
|
- Async.InitialState.HEALTHY.equals(async.initialState())
|
|
+ Async.InitialState.HEALTHY == async.initialState()
|
|
? Result.healthy(NO_RESULT_YET_MESSAGE)
|
|
: Result.unhealthy(NO_RESULT_YET_MESSAGE);
|
|
- if (Async.ScheduleType.FIXED_RATE.equals(async.scheduleType())) {
|
|
+ if (Async.ScheduleType.FIXED_RATE == async.scheduleType()) {
|
|
future =
|
|
executorService.scheduleAtFixedRate(
|
|
this, async.initialDelay(), async.period(), async.unit());
|
|
@@ -77,8 +79,6 @@ public class AsyncHealthCheckDecorator implements HealthCheck, Runnable {
|
|
}
|
|
|
|
private static void check(boolean expression, String message) {
|
|
- if (!expression) {
|
|
- throw new IllegalArgumentException(message);
|
|
- }
|
|
+ checkArgument(expression, message);
|
|
}
|
|
}
|
|
--- a/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/HealthCheck.java
|
|
+++ b/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/HealthCheck.java
|
|
@@ -1,11 +1,12 @@
|
|
package io.dropwizard.metrics5.health;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Clock;
|
|
import java.time.Instant;
|
|
import java.time.ZoneId;
|
|
import java.time.ZonedDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
-import java.util.Collections;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -123,7 +124,7 @@ public interface HealthCheck {
|
|
this.healthy = isHealthy;
|
|
this.message = message;
|
|
this.error = error;
|
|
- this.details = details == null ? null : Collections.unmodifiableMap(details);
|
|
+ this.details = details == null ? null : unmodifiableMap(details);
|
|
this.time = clock.getTime();
|
|
}
|
|
|
|
@@ -162,7 +163,7 @@ public interface HealthCheck {
|
|
*/
|
|
public String getTimestamp() {
|
|
Instant currentInstant = Instant.ofEpochMilli(time);
|
|
- ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(currentInstant, ZoneId.systemDefault());
|
|
+ ZonedDateTime zonedDateTime = currentInstant.atZone(ZoneId.systemDefault());
|
|
return DATE_FORMAT_PATTERN.format(zonedDateTime);
|
|
}
|
|
|
|
@@ -218,8 +219,7 @@ public interface HealthCheck {
|
|
int result = healthy ? 1 : 0;
|
|
result = PRIME * result + (message != null ? message.hashCode() : 0);
|
|
result = PRIME * result + (error != null ? error.hashCode() : 0);
|
|
- result = PRIME * result + (Long.hashCode(time));
|
|
- return result;
|
|
+ return PRIME * result + (Long.hashCode(time));
|
|
}
|
|
|
|
@Override
|
|
@@ -237,7 +237,7 @@ public interface HealthCheck {
|
|
if (details != null) {
|
|
for (Map.Entry<String, Object> e : details.entrySet()) {
|
|
builder.append(", ");
|
|
- builder.append(e.getKey()).append("=").append(String.valueOf(e.getValue()));
|
|
+ builder.append(e.getKey()).append("=").append(e.getValue());
|
|
}
|
|
}
|
|
builder.append('}');
|
|
--- a/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/HealthCheckRegistry.java
|
|
+++ b/metrics-healthchecks/src/main/java/io/dropwizard/metrics5/health/HealthCheckRegistry.java
|
|
@@ -1,9 +1,11 @@
|
|
package io.dropwizard.metrics5.health;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
import static io.dropwizard.metrics5.health.HealthCheck.Result;
|
|
+import static java.util.Collections.unmodifiableSortedMap;
|
|
+import static java.util.Collections.unmodifiableSortedSet;
|
|
|
|
import io.dropwizard.metrics5.health.annotation.Async;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -27,7 +29,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
/** A registry for health checks. */
|
|
public class HealthCheckRegistry {
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckRegistry.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(HealthCheckRegistry.class);
|
|
private static final int ASYNC_EXECUTOR_POOL_SIZE = 2;
|
|
|
|
private final ConcurrentMap<String, HealthCheck> healthChecks;
|
|
@@ -92,9 +94,8 @@ public class HealthCheckRegistry {
|
|
public void register(String name, HealthCheck healthCheck) {
|
|
HealthCheck registered;
|
|
synchronized (lock) {
|
|
- if (healthChecks.containsKey(name)) {
|
|
- throw new IllegalArgumentException("A health check named " + name + " already exists");
|
|
- }
|
|
+ checkArgument(
|
|
+ !healthChecks.containsKey(name), "A health check named %s already exists", name);
|
|
registered = healthCheck;
|
|
if (healthCheck.getClass().isAnnotationPresent(Async.class)) {
|
|
registered = new AsyncHealthCheckDecorator(healthCheck, asyncExecutorService);
|
|
@@ -128,7 +129,7 @@ public class HealthCheckRegistry {
|
|
* @return the names of all registered health checks
|
|
*/
|
|
public SortedSet<String> getNames() {
|
|
- return Collections.unmodifiableSortedSet(new TreeSet<>(healthChecks.keySet()));
|
|
+ return unmodifiableSortedSet(new TreeSet<>(healthChecks.keySet()));
|
|
}
|
|
|
|
/**
|
|
@@ -180,7 +181,7 @@ public class HealthCheckRegistry {
|
|
results.put(entry.getKey(), result);
|
|
}
|
|
}
|
|
- return Collections.unmodifiableSortedMap(results);
|
|
+ return unmodifiableSortedMap(results);
|
|
}
|
|
|
|
/**
|
|
@@ -217,12 +218,12 @@ public class HealthCheckRegistry {
|
|
try {
|
|
results.put(entry.getKey(), entry.getValue().get());
|
|
} catch (Exception e) {
|
|
- LOGGER.warn("Error executing health check {}", entry.getKey(), e);
|
|
+ LOG.warn("Error executing health check {}", entry.getKey(), e);
|
|
results.put(entry.getKey(), HealthCheck.Result.unhealthy(e));
|
|
}
|
|
}
|
|
|
|
- return Collections.unmodifiableSortedMap(results);
|
|
+ return unmodifiableSortedMap(results);
|
|
}
|
|
|
|
private void onHealthCheckAdded(String name, HealthCheck healthCheck) {
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/AsyncHealthCheckDecoratorTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/AsyncHealthCheckDecoratorTest.java
|
|
@@ -1,11 +1,12 @@
|
|
package io.dropwizard.metrics5.health;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.ArgumentCaptor.forClass;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.*;
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.health.annotation.Async;
|
|
@@ -16,7 +17,7 @@ import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
/** Unit tests for {@link AsyncHealthCheckDecorator}. */
|
|
-class AsyncHealthCheckDecoratorTest {
|
|
+final class AsyncHealthCheckDecoratorTest {
|
|
|
|
private static final long CURRENT_TIME = 1551002401000L;
|
|
|
|
@@ -29,65 +30,66 @@ class AsyncHealthCheckDecoratorTest {
|
|
.withMessage("Result was healthy but it expired 1 milliseconds ago")
|
|
.build();
|
|
|
|
- private final HealthCheck mockHealthCheck = mock(HealthCheck.class);
|
|
- private final ScheduledExecutorService mockExecutorService = mock(ScheduledExecutorService.class);
|
|
+ private final HealthCheck mockHealthCheck = mock();
|
|
+ private final ScheduledExecutorService mockExecutorService = mock();
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
- private final ScheduledFuture mockFuture = mock(ScheduledFuture.class);
|
|
+ private final ScheduledFuture mockFuture = mock();
|
|
|
|
@Test
|
|
void nullHealthCheckTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(null, mockExecutorService);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(null, mockExecutorService);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void nullExecutorServiceTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(mockHealthCheck, null);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(mockHealthCheck, null);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void nonAsyncHealthCheckTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(mockHealthCheck, mockExecutorService);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(mockHealthCheck, mockExecutorService);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void negativePeriodTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(new NegativePeriodAsyncHealthCheck(), mockExecutorService);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(
|
|
+ new NegativePeriodAsyncHealthCheck(), mockExecutorService);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void zeroPeriodTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(new ZeroPeriodAsyncHealthCheck(), mockExecutorService);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(new ZeroPeriodAsyncHealthCheck(), mockExecutorService);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
void negativeInitialValueTriggersInstantiationFailure() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- new AsyncHealthCheckDecorator(
|
|
- new NegativeInitialDelayAsyncHealthCheck(), mockExecutorService);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ new AsyncHealthCheckDecorator(
|
|
+ new NegativeInitialDelayAsyncHealthCheck(), mockExecutorService);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -97,7 +99,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
AsyncHealthCheckDecorator asyncDecorator =
|
|
new AsyncHealthCheckDecorator(asyncHealthCheck, mockExecutorService);
|
|
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
assertThat(asyncDecorator.getHealthCheck()).isEqualTo(asyncHealthCheck);
|
|
assertThat(asyncDecorator.check().isHealthy()).isTrue();
|
|
@@ -109,7 +111,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
AsyncHealthCheckDecorator asyncDecorator =
|
|
new AsyncHealthCheckDecorator(asyncHealthCheck, mockExecutorService);
|
|
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleWithFixedDelay(any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
assertThat(asyncDecorator.getHealthCheck()).isEqualTo(asyncHealthCheck);
|
|
}
|
|
@@ -124,8 +126,8 @@ class AsyncHealthCheckDecoratorTest {
|
|
assertThat(asyncDecorator.check().isHealthy()).isFalse();
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void tearDownTriggersCancellation() throws Exception {
|
|
when(mockExecutorService.scheduleAtFixedRate(
|
|
any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS)))
|
|
@@ -136,13 +138,13 @@ class AsyncHealthCheckDecoratorTest {
|
|
new AsyncHealthCheckDecorator(new DefaultAsyncHealthCheck(), mockExecutorService);
|
|
asyncDecorator.tearDown();
|
|
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
- verify(mockFuture, times(1)).cancel(eq(true));
|
|
+ verify(mockFuture).cancel(true);
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void afterFirstExecutionDecoratedHealthCheckResultIsProvided() throws Exception {
|
|
HealthCheck.Result expectedResult = HealthCheck.Result.healthy("AsyncHealthCheckTest");
|
|
when(mockExecutorService.scheduleAtFixedRate(
|
|
@@ -155,7 +157,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
HealthCheck.Result initialResult = asyncDecorator.check();
|
|
|
|
ArgumentCaptor<Runnable> runnableCaptor = forClass(Runnable.class);
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(runnableCaptor.capture(), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
Runnable capturedRunnable = runnableCaptor.getValue();
|
|
capturedRunnable.run();
|
|
@@ -165,8 +167,8 @@ class AsyncHealthCheckDecoratorTest {
|
|
assertThat(actualResult).isNotEqualTo(initialResult);
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void exceptionInDecoratedHealthCheckWontAffectAsyncDecorator() throws Exception {
|
|
Exception exception = new Exception("TestException");
|
|
when(mockExecutorService.scheduleAtFixedRate(
|
|
@@ -178,7 +180,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
new ConfigurableAsyncHealthCheck(exception), mockExecutorService);
|
|
|
|
ArgumentCaptor<Runnable> runnableCaptor = forClass(Runnable.class);
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(runnableCaptor.capture(), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
Runnable capturedRunnable = runnableCaptor.getValue();
|
|
capturedRunnable.run();
|
|
@@ -195,7 +197,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
new AsyncHealthCheckDecorator(healthCheck, mockExecutorService, FIXED_CLOCK);
|
|
|
|
ArgumentCaptor<Runnable> runnableCaptor = forClass(Runnable.class);
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(
|
|
runnableCaptor.capture(), eq(0L), eq(1000L), eq(TimeUnit.MILLISECONDS));
|
|
Runnable capturedRunnable = runnableCaptor.getValue();
|
|
@@ -214,7 +216,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
new AsyncHealthCheckDecorator(healthCheck, mockExecutorService, FIXED_CLOCK);
|
|
|
|
ArgumentCaptor<Runnable> runnableCaptor = forClass(Runnable.class);
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(
|
|
runnableCaptor.capture(), eq(0L), eq(1000L), eq(TimeUnit.MILLISECONDS));
|
|
Runnable capturedRunnable = runnableCaptor.getValue();
|
|
@@ -232,7 +234,7 @@ class AsyncHealthCheckDecoratorTest {
|
|
new AsyncHealthCheckDecorator(healthCheck, mockExecutorService, FIXED_CLOCK);
|
|
|
|
ArgumentCaptor<Runnable> runnableCaptor = forClass(Runnable.class);
|
|
- verify(mockExecutorService, times(1))
|
|
+ verify(mockExecutorService)
|
|
.scheduleAtFixedRate(runnableCaptor.capture(), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
|
Runnable capturedRunnable = runnableCaptor.getValue();
|
|
capturedRunnable.run();
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckFilterTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckFilterTest.java
|
|
@@ -5,7 +5,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HealthCheckFilterTest {
|
|
+final class HealthCheckFilterTest {
|
|
|
|
@Test
|
|
void theAllFilterMatchesAllHealthChecks() {
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckRegistryTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckRegistryTest.java
|
|
@@ -1,9 +1,9 @@
|
|
package io.dropwizard.metrics5.health;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.mockito.ArgumentCaptor.forClass;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
@@ -23,22 +23,22 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
-class HealthCheckRegistryTest {
|
|
- private final ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
|
|
+final class HealthCheckRegistryTest {
|
|
+ private final ScheduledExecutorService executorService = mock();
|
|
private final HealthCheckRegistry registry = new HealthCheckRegistry(executorService);
|
|
- private final HealthCheckRegistryListener listener = mock(HealthCheckRegistryListener.class);
|
|
+ private final HealthCheckRegistryListener listener = mock();
|
|
|
|
- private final HealthCheck hc1 = mock(HealthCheck.class);
|
|
- private final HealthCheck hc2 = mock(HealthCheck.class);
|
|
+ private final HealthCheck hc1 = mock();
|
|
+ private final HealthCheck hc2 = mock();
|
|
|
|
- private final HealthCheck.Result r1 = mock(HealthCheck.Result.class);
|
|
- private final HealthCheck.Result r2 = mock(HealthCheck.Result.class);
|
|
+ private final HealthCheck.Result r1 = mock();
|
|
+ private final HealthCheck.Result r2 = mock();
|
|
|
|
- private final HealthCheck.Result ar = mock(HealthCheck.Result.class);
|
|
+ private final HealthCheck.Result ar = mock();
|
|
private final HealthCheck ahc = new TestAsyncHealthCheck(ar);
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
- private final ScheduledFuture af = mock(ScheduledFuture.class);
|
|
+ private final ScheduledFuture af = mock();
|
|
|
|
@BeforeEach
|
|
@SuppressWarnings("unchecked")
|
|
@@ -74,11 +74,11 @@ class HealthCheckRegistryTest {
|
|
|
|
@Test
|
|
void registeringHealthCheckTwiceThrowsException() {
|
|
- assertThrows(
|
|
- IllegalArgumentException.class,
|
|
- () -> {
|
|
- registry.register("hc1", hc1);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ registry.register("hc1", hc1);
|
|
+ })
|
|
+ .isInstanceOf(IllegalArgumentException.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -101,7 +101,7 @@ class HealthCheckRegistryTest {
|
|
|
|
@Test
|
|
void addingListenerCatchesExistingHealthChecks() {
|
|
- HealthCheckRegistryListener listener = mock(HealthCheckRegistryListener.class);
|
|
+ HealthCheckRegistryListener listener = mock();
|
|
HealthCheckRegistry registry = new HealthCheckRegistry();
|
|
registry.register("hc1", hc1);
|
|
registry.register("hc2", hc2);
|
|
@@ -115,7 +115,7 @@ class HealthCheckRegistryTest {
|
|
|
|
@Test
|
|
void removedListenerDoesNotReceiveUpdates() {
|
|
- HealthCheckRegistryListener listener = mock(HealthCheckRegistryListener.class);
|
|
+ HealthCheckRegistryListener listener = mock();
|
|
HealthCheckRegistry registry = new HealthCheckRegistry();
|
|
registry.addListener(listener);
|
|
registry.register("hc1", hc1);
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/HealthCheckTest.java
|
|
@@ -11,7 +11,7 @@ import java.time.ZonedDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HealthCheckTest {
|
|
+final class HealthCheckTest {
|
|
|
|
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
|
@@ -29,7 +29,7 @@ class HealthCheckTest {
|
|
}
|
|
}
|
|
|
|
- private final HealthCheck underlying = mock(HealthCheck.class);
|
|
+ private final HealthCheck underlying = mock();
|
|
private final HealthCheck healthCheck = new ExampleHealthCheck(underlying);
|
|
|
|
@Test
|
|
@@ -89,7 +89,7 @@ class HealthCheckTest {
|
|
|
|
@Test
|
|
void canHaveUnhealthyResultsWithExceptions() {
|
|
- final RuntimeException e = mock(RuntimeException.class);
|
|
+ final RuntimeException e = mock();
|
|
when(e.getMessage()).thenReturn("oh noes");
|
|
|
|
final HealthCheck.Result result = HealthCheck.Result.unhealthy(e);
|
|
@@ -144,7 +144,7 @@ class HealthCheckTest {
|
|
|
|
@Test
|
|
void canHaveUnHealthyBuilderWithDetailAndError() {
|
|
- final RuntimeException e = mock(RuntimeException.class);
|
|
+ final RuntimeException e = mock();
|
|
when(e.getMessage()).thenReturn("oh noes");
|
|
|
|
final HealthCheck.Result result =
|
|
@@ -161,7 +161,7 @@ class HealthCheckTest {
|
|
|
|
@Test
|
|
void returnsResultsWhenExecuted() {
|
|
- final HealthCheck.Result result = mock(HealthCheck.Result.class);
|
|
+ final HealthCheck.Result result = mock();
|
|
when(underlying.execute()).thenReturn(result);
|
|
|
|
assertThat(healthCheck.execute()).isEqualTo(result);
|
|
@@ -171,7 +171,7 @@ class HealthCheckTest {
|
|
|
|
@Test
|
|
void wrapsExceptionsWhenExecuted() {
|
|
- final RuntimeException e = mock(RuntimeException.class);
|
|
+ final RuntimeException e = mock();
|
|
when(e.getMessage()).thenReturn("oh noes");
|
|
|
|
when(underlying.execute()).thenThrow(e);
|
|
@@ -181,7 +181,7 @@ class HealthCheckTest {
|
|
assertThat(actual.getMessage()).isEqualTo("oh noes");
|
|
assertThat(actual.getError()).isEqualTo(e);
|
|
assertThat(actual.getDetails()).isNull();
|
|
- assertThat(actual.getDuration()).isGreaterThanOrEqualTo(0);
|
|
+ assertThat(actual.getDuration()).isNotNegative();
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/SharedHealthCheckRegistriesTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/SharedHealthCheckRegistriesTest.java
|
|
@@ -2,13 +2,12 @@ package io.dropwizard.metrics5.health;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SharedHealthCheckRegistriesTest {
|
|
+final class SharedHealthCheckRegistriesTest {
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
@@ -28,7 +27,7 @@ class SharedHealthCheckRegistriesTest {
|
|
void returnsSetOfCreatedRegistries() {
|
|
SharedHealthCheckRegistries.getOrCreate("db");
|
|
|
|
- assertThat(SharedHealthCheckRegistries.names()).containsOnly("db");
|
|
+ assertThat(SharedHealthCheckRegistries.names()).containsExactly("db");
|
|
}
|
|
|
|
@Test
|
|
@@ -58,7 +57,7 @@ class SharedHealthCheckRegistriesTest {
|
|
() -> {
|
|
SharedHealthCheckRegistries.getDefault();
|
|
});
|
|
- assertTrue(exception.getMessage().contains("Default registry name has not been set."));
|
|
+ assertThat(exception.getMessage()).contains("Default registry name has not been set.");
|
|
}
|
|
|
|
@Test
|
|
@@ -85,7 +84,7 @@ class SharedHealthCheckRegistriesTest {
|
|
SharedHealthCheckRegistries.setDefault("default");
|
|
SharedHealthCheckRegistries.setDefault("default");
|
|
});
|
|
- assertTrue(exception.getMessage().contains("Default health check registry is already set."));
|
|
+ assertThat(exception.getMessage()).contains("Default health check registry is already set.");
|
|
}
|
|
|
|
@Test
|
|
@@ -97,6 +96,6 @@ class SharedHealthCheckRegistriesTest {
|
|
SharedHealthCheckRegistries.setDefault("default", new HealthCheckRegistry());
|
|
SharedHealthCheckRegistries.setDefault("default", new HealthCheckRegistry());
|
|
});
|
|
- assertTrue(exception.getMessage().contains("Default health check registry is already set."));
|
|
+ assertThat(exception.getMessage()).contains("Default health check registry is already set.");
|
|
}
|
|
}
|
|
--- a/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/jvm/ThreadDeadlockHealthCheckTest.java
|
|
+++ b/metrics-healthchecks/src/test/java/io/dropwizard/metrics5/health/jvm/ThreadDeadlockHealthCheckTest.java
|
|
@@ -4,23 +4,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.health.HealthCheck;
|
|
import io.dropwizard.metrics5.jvm.ThreadDeadlockDetector;
|
|
-import java.util.Collections;
|
|
import java.util.Set;
|
|
import java.util.TreeSet;
|
|
-import org.assertj.core.api.Assertions;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ThreadDeadlockHealthCheckTest {
|
|
+final class ThreadDeadlockHealthCheckTest {
|
|
@Test
|
|
void isHealthyIfNoThreadsAreDeadlocked() {
|
|
- final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
|
|
+ final ThreadDeadlockDetector detector = mock();
|
|
final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck(detector);
|
|
|
|
- when(detector.getDeadlockedThreads()).thenReturn(Collections.emptySet());
|
|
+ when(detector.getDeadlockedThreads()).thenReturn(ImmutableSet.of());
|
|
|
|
- Assertions.assertThat(healthCheck.execute().isHealthy()).isTrue();
|
|
+ assertThat(healthCheck.execute().isHealthy()).isTrue();
|
|
}
|
|
|
|
@Test
|
|
@@ -29,7 +28,7 @@ class ThreadDeadlockHealthCheckTest {
|
|
threads.add("one");
|
|
threads.add("two");
|
|
|
|
- final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
|
|
+ final ThreadDeadlockDetector detector = mock();
|
|
final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck(detector);
|
|
|
|
when(detector.getDeadlockedThreads()).thenReturn(threads);
|
|
@@ -44,6 +43,6 @@ class ThreadDeadlockHealthCheckTest {
|
|
@Test
|
|
void automaticallyUsesThePlatformThreadBeans() {
|
|
final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck();
|
|
- Assertions.assertThat(healthCheck.execute().isHealthy()).isTrue();
|
|
+ assertThat(healthCheck.execute().isHealthy()).isTrue();
|
|
}
|
|
}
|
|
--- a/metrics-httpasyncclient/src/test/java/io/dropwizard/metrics5/httpasyncclient/InstrumentedHttpClientsTest.java
|
|
+++ b/metrics-httpasyncclient/src/test/java/io/dropwizard/metrics5/httpasyncclient/InstrumentedHttpClientsTest.java
|
|
@@ -22,7 +22,7 @@ import org.mockito.Mock;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
-class InstrumentedHttpClientsTest extends HttpClientTestBase {
|
|
+final class InstrumentedHttpClientsTest extends HttpClientTestBase {
|
|
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
|
|
--- a/metrics-httpasyncclient/src/test/java/io/dropwizard/metrics5/httpasyncclient/InstrumentedHttpClientsTimerTest.java
|
|
+++ b/metrics-httpasyncclient/src/test/java/io/dropwizard/metrics5/httpasyncclient/InstrumentedHttpClientsTimerTest.java
|
|
@@ -1,7 +1,7 @@
|
|
package io.dropwizard.metrics5.httpasyncclient;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
@@ -29,7 +29,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
@Disabled("The tests are flaky")
|
|
-class InstrumentedHttpClientsTimerTest extends HttpClientTestBase {
|
|
+final class InstrumentedHttpClientsTimerTest extends HttpClientTestBase {
|
|
|
|
private HttpAsyncClient asyncHttpClient;
|
|
|
|
@@ -46,7 +46,7 @@ class InstrumentedHttpClientsTimerTest extends HttpClientTestBase {
|
|
chac.start();
|
|
asyncHttpClient = chac;
|
|
|
|
- Timer timer = mock(Timer.class);
|
|
+ Timer timer = mock();
|
|
when(timer.time()).thenReturn(context);
|
|
when(metricRegistry.timer(MetricName.build("test"))).thenReturn(timer);
|
|
}
|
|
@@ -72,13 +72,13 @@ class InstrumentedHttpClientsTimerTest extends HttpClientTestBase {
|
|
verify(context, timeout(200).times(1)).stop();
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void timerIsStoppedCorrectlyWithProvidedFutureCallbackCompleted() throws Exception {
|
|
HttpHost host = startServerWithGlobalRequestHandler(STATUS_OK);
|
|
HttpGet get = new HttpGet("/?q=something");
|
|
|
|
- FutureCallback<HttpResponse> futureCallback = mock(FutureCallback.class);
|
|
+ FutureCallback<HttpResponse> futureCallback = mock();
|
|
|
|
// Timer hasn't been stopped prior to executing the request
|
|
verify(context, never()).stop();
|
|
@@ -99,14 +99,14 @@ class InstrumentedHttpClientsTimerTest extends HttpClientTestBase {
|
|
verify(context, timeout(200).times(1)).stop();
|
|
}
|
|
|
|
- @Test
|
|
@SuppressWarnings("unchecked")
|
|
+ @Test
|
|
void timerIsStoppedCorrectlyWithProvidedFutureCallbackFailed() throws Exception {
|
|
// There should be nothing listening on this port
|
|
HttpHost host = HttpHost.create(String.format("http://127.0.0.1:%d", findAvailableLocalPort()));
|
|
HttpGet get = new HttpGet("/?q=something");
|
|
|
|
- FutureCallback<HttpResponse> futureCallback = mock(FutureCallback.class);
|
|
+ FutureCallback<HttpResponse> futureCallback = mock();
|
|
|
|
// Timer hasn't been stopped prior to executing the request
|
|
verify(context, never()).stop();
|
|
--- a/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/HttpClientMetricNameStrategiesTest.java
|
|
+++ b/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/HttpClientMetricNameStrategiesTest.java
|
|
@@ -17,7 +17,7 @@ import org.apache.http.client.methods.HttpRequestWrapper;
|
|
import org.apache.http.client.utils.URIUtils;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HttpClientMetricNameStrategiesTest {
|
|
+final class HttpClientMetricNameStrategiesTest {
|
|
|
|
@Test
|
|
void methodOnlyWithName() {
|
|
--- a/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/InstrumentedHttpClientConnectionManagerTest.java
|
|
+++ b/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/InstrumentedHttpClientConnectionManagerTest.java
|
|
@@ -3,16 +3,17 @@ package io.dropwizard.metrics5.httpclient;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
+import static org.mockito.Mockito.atLeast;
|
|
+import static org.mockito.Mockito.mock;
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
-import org.mockito.Mockito;
|
|
|
|
-class InstrumentedHttpClientConnectionManagerTest {
|
|
+final class InstrumentedHttpClientConnectionManagerTest {
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
|
|
@Test
|
|
@@ -37,7 +38,7 @@ class InstrumentedHttpClientConnectionManagerTest {
|
|
|
|
@Test
|
|
void configurableViaBuilder() {
|
|
- final MetricRegistry registry = Mockito.mock(MetricRegistry.class);
|
|
+ final MetricRegistry registry = mock();
|
|
|
|
InstrumentedHttpClientConnectionManager.builder(registry)
|
|
.name("some-name")
|
|
@@ -46,7 +47,7 @@ class InstrumentedHttpClientConnectionManagerTest {
|
|
.close();
|
|
|
|
ArgumentCaptor<MetricName> argumentCaptor = ArgumentCaptor.forClass(MetricName.class);
|
|
- Mockito.verify(registry, Mockito.atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
- assertTrue(argumentCaptor.getValue().getKey().contains("some-other-name"));
|
|
+ verify(registry, atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
+ assertThat(argumentCaptor.getValue().getKey()).contains("some-other-name");
|
|
}
|
|
}
|
|
--- a/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/InstrumentedHttpClientsTest.java
|
|
+++ b/metrics-httpclient/src/test/java/io/dropwizard/metrics5/httpclient/InstrumentedHttpClientsTest.java
|
|
@@ -1,7 +1,7 @@
|
|
package io.dropwizard.metrics5.httpclient;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.mock;
|
|
@@ -22,10 +22,9 @@ import org.apache.http.client.methods.HttpGet;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHttpClientsTest {
|
|
- private final HttpClientMetricNameStrategy metricNameStrategy =
|
|
- mock(HttpClientMetricNameStrategy.class);
|
|
- private final MetricRegistryListener registryListener = mock(MetricRegistryListener.class);
|
|
+final class InstrumentedHttpClientsTest {
|
|
+ private final HttpClientMetricNameStrategy metricNameStrategy = mock();
|
|
+ private final MetricRegistryListener registryListener = mock();
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
private final HttpClient client =
|
|
InstrumentedHttpClients.custom(metricRegistry, metricNameStrategy)
|
|
--- a/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/HttpClientMetricNameStrategiesTest.java
|
|
+++ b/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/HttpClientMetricNameStrategiesTest.java
|
|
@@ -16,7 +16,7 @@ import org.apache.hc.core5.http.message.HttpRequestWrapper;
|
|
import org.apache.hc.core5.net.URIBuilder;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HttpClientMetricNameStrategiesTest {
|
|
+final class HttpClientMetricNameStrategiesTest {
|
|
|
|
@Test
|
|
void methodOnlyWithName() {
|
|
--- a/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedAsyncClientConnectionManagerTest.java
|
|
+++ b/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedAsyncClientConnectionManagerTest.java
|
|
@@ -3,16 +3,17 @@ package io.dropwizard.metrics5.httpclient5;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
+import static org.mockito.Mockito.atLeast;
|
|
+import static org.mockito.Mockito.mock;
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
-import org.mockito.Mockito;
|
|
|
|
-class InstrumentedAsyncClientConnectionManagerTest {
|
|
+final class InstrumentedAsyncClientConnectionManagerTest {
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
|
|
@Test
|
|
@@ -44,7 +45,7 @@ class InstrumentedAsyncClientConnectionManagerTest {
|
|
|
|
@Test
|
|
void configurableViaBuilder() {
|
|
- final MetricRegistry registry = Mockito.mock(MetricRegistry.class);
|
|
+ final MetricRegistry registry = mock();
|
|
|
|
InstrumentedAsyncClientConnectionManager.builder(registry)
|
|
.name("some-name")
|
|
@@ -53,7 +54,7 @@ class InstrumentedAsyncClientConnectionManagerTest {
|
|
.close();
|
|
|
|
ArgumentCaptor<MetricName> argumentCaptor = ArgumentCaptor.forClass(MetricName.class);
|
|
- Mockito.verify(registry, Mockito.atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
- assertTrue(argumentCaptor.getValue().getKey().contains("some-other-name"));
|
|
+ verify(registry, atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
+ assertThat(argumentCaptor.getValue().getKey()).contains("some-other-name");
|
|
}
|
|
}
|
|
--- a/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpAsyncClientsTest.java
|
|
+++ b/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpAsyncClientsTest.java
|
|
@@ -1,8 +1,9 @@
|
|
package io.dropwizard.metrics5.httpclient5;
|
|
|
|
+import static java.nio.charset.StandardCharsets.US_ASCII;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
import static org.awaitility.Awaitility.await;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.atLeastOnce;
|
|
@@ -18,7 +19,6 @@ import io.dropwizard.metrics5.MetricRegistryListener;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Future;
|
|
@@ -39,7 +39,7 @@ import org.mockito.Mock;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
-class InstrumentedHttpAsyncClientsTest {
|
|
+final class InstrumentedHttpAsyncClientsTest {
|
|
|
|
@Mock private HttpClientMetricNameStrategy metricNameStrategy;
|
|
@Mock private MetricRegistryListener registryListener;
|
|
@@ -83,7 +83,7 @@ class InstrumentedHttpAsyncClientsTest {
|
|
exchange -> {
|
|
exchange.sendResponseHeaders(200, 0L);
|
|
exchange.setStreams(null, null);
|
|
- exchange.getResponseBody().write("TEST".getBytes(StandardCharsets.US_ASCII));
|
|
+ exchange.getResponseBody().write("TEST".getBytes(US_ASCII));
|
|
exchange.close();
|
|
});
|
|
httpServer.start();
|
|
@@ -193,7 +193,7 @@ class InstrumentedHttpAsyncClientsTest {
|
|
exchange -> {
|
|
exchange.sendResponseHeaders(200, 0L);
|
|
exchange.setStreams(null, null);
|
|
- exchange.getResponseBody().write("TEST".getBytes(StandardCharsets.US_ASCII));
|
|
+ exchange.getResponseBody().write("TEST".getBytes(US_ASCII));
|
|
exchange.close();
|
|
});
|
|
httpServer.start();
|
|
--- a/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpClientConnectionManagerTest.java
|
|
+++ b/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpClientConnectionManagerTest.java
|
|
@@ -3,16 +3,17 @@ package io.dropwizard.metrics5.httpclient5;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
+import static org.mockito.Mockito.atLeast;
|
|
+import static org.mockito.Mockito.mock;
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
-import org.mockito.Mockito;
|
|
|
|
-class InstrumentedHttpClientConnectionManagerTest {
|
|
+final class InstrumentedHttpClientConnectionManagerTest {
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
|
|
@Test
|
|
@@ -42,7 +43,7 @@ class InstrumentedHttpClientConnectionManagerTest {
|
|
|
|
@Test
|
|
void configurableViaBuilder() {
|
|
- final MetricRegistry registry = Mockito.mock(MetricRegistry.class);
|
|
+ final MetricRegistry registry = mock();
|
|
|
|
InstrumentedHttpClientConnectionManager.builder(registry)
|
|
.name("some-name")
|
|
@@ -51,7 +52,7 @@ class InstrumentedHttpClientConnectionManagerTest {
|
|
.close();
|
|
|
|
ArgumentCaptor<MetricName> argumentCaptor = ArgumentCaptor.forClass(MetricName.class);
|
|
- Mockito.verify(registry, Mockito.atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
- assertTrue(argumentCaptor.getValue().getKey().contains("some-other-name"));
|
|
+ verify(registry, atLeast(1)).registerGauge(argumentCaptor.capture(), any());
|
|
+ assertThat(argumentCaptor.getValue().getKey()).contains("some-other-name");
|
|
}
|
|
}
|
|
--- a/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpClientsTest.java
|
|
+++ b/metrics-httpclient5/src/test/java/io/dropwizard/metrics5/httpclient5/InstrumentedHttpClientsTest.java
|
|
@@ -1,7 +1,7 @@
|
|
package io.dropwizard.metrics5.httpclient5;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.mock;
|
|
@@ -22,10 +22,9 @@ import org.apache.hc.core5.http.NoHttpResponseException;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHttpClientsTest {
|
|
- private final HttpClientMetricNameStrategy metricNameStrategy =
|
|
- mock(HttpClientMetricNameStrategy.class);
|
|
- private final MetricRegistryListener registryListener = mock(MetricRegistryListener.class);
|
|
+final class InstrumentedHttpClientsTest {
|
|
+ private final HttpClientMetricNameStrategy metricNameStrategy = mock();
|
|
+ private final MetricRegistryListener registryListener = mock();
|
|
private final MetricRegistry metricRegistry = new MetricRegistry();
|
|
private final HttpClient client =
|
|
InstrumentedHttpClients.custom(metricRegistry, metricNameStrategy)
|
|
--- a/metrics-influxdb/src/main/java/io/dropwizard/metrics5/influxdb/InfluxDbReporter.java
|
|
+++ b/metrics-influxdb/src/main/java/io/dropwizard/metrics5/influxdb/InfluxDbReporter.java
|
|
@@ -2,6 +2,7 @@ package io.dropwizard.metrics5.influxdb;
|
|
|
|
import static io.dropwizard.metrics5.MetricAttribute.*;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
@@ -15,7 +16,6 @@ import io.dropwizard.metrics5.MetricRegistry;
|
|
import io.dropwizard.metrics5.Snapshot;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import java.io.IOException;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -78,7 +78,7 @@ public class InfluxDbReporter extends GarbageFreeScheduledReporter {
|
|
this.filter = MetricFilter.ALL;
|
|
this.executor = null;
|
|
this.shutdownExecutorOnStop = true;
|
|
- this.disabledMetricAttributes = Collections.emptySet();
|
|
+ this.disabledMetricAttributes = ImmutableSet.of();
|
|
}
|
|
|
|
/**
|
|
@@ -196,7 +196,7 @@ public class InfluxDbReporter extends GarbageFreeScheduledReporter {
|
|
}
|
|
}
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(InfluxDbReporter.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(InfluxDbReporter.class);
|
|
private static final String VALUE = "value";
|
|
|
|
private final Clock clock;
|
|
@@ -279,12 +279,12 @@ public class InfluxDbReporter extends GarbageFreeScheduledReporter {
|
|
}
|
|
sender.flush();
|
|
} catch (IOException e) {
|
|
- LOGGER.warn("Unable to report to InfluxDb", sender, e);
|
|
+ LOG.warn("Unable to report to InfluxDb", sender, e);
|
|
} finally {
|
|
try {
|
|
sender.disconnect();
|
|
} catch (IOException e) {
|
|
- LOGGER.warn("Error disconnecting InfluxDb", sender, e);
|
|
+ LOG.warn("Error disconnecting InfluxDb", sender, e);
|
|
}
|
|
}
|
|
}
|
|
@@ -297,7 +297,7 @@ public class InfluxDbReporter extends GarbageFreeScheduledReporter {
|
|
try {
|
|
sender.close();
|
|
} catch (IOException e) {
|
|
- LOGGER.debug("Error disconnecting from InfluxDb", e);
|
|
+ LOG.debug("Error disconnecting from InfluxDb", e);
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-influxdb/src/main/java/io/dropwizard/metrics5/influxdb/InfluxDbUdpSender.java
|
|
+++ b/metrics-influxdb/src/main/java/io/dropwizard/metrics5/influxdb/InfluxDbUdpSender.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.influxdb;
|
|
|
|
+import static java.util.Objects.requireNonNull;
|
|
+
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.ByteBuffer;
|
|
@@ -9,7 +11,6 @@ import java.nio.charset.Charset;
|
|
import java.nio.charset.CharsetEncoder;
|
|
import java.nio.charset.CoderResult;
|
|
import java.nio.charset.CodingErrorAction;
|
|
-import java.util.Objects;
|
|
|
|
public class InfluxDbUdpSender implements InfluxDbSender {
|
|
|
|
@@ -42,7 +43,7 @@ public class InfluxDbUdpSender implements InfluxDbSender {
|
|
* @param address the address of the InfluxDb server
|
|
*/
|
|
public InfluxDbUdpSender(InetSocketAddress address) {
|
|
- this.address = Objects.requireNonNull(address);
|
|
+ this.address = requireNonNull(address);
|
|
charBuf = CharBuffer.allocate(mtu * 2);
|
|
byteBuf = ByteBuffer.allocate(mtu * 2);
|
|
}
|
|
--- a/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbLineBuilderAssumptionsTest.java
|
|
+++ b/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbLineBuilderAssumptionsTest.java
|
|
@@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import io.dropwizard.metrics5.MetricAttribute;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InfluxDbLineBuilderAssumptionsTest {
|
|
+final class InfluxDbLineBuilderAssumptionsTest {
|
|
|
|
@Test
|
|
void ensureMetricAttributeCodesAreSafeFieldKeys() {
|
|
--- a/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbReporterTest.java
|
|
+++ b/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbReporterTest.java
|
|
@@ -11,6 +11,7 @@ import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
@@ -25,7 +26,6 @@ import io.dropwizard.metrics5.Timer;
|
|
import java.io.IOException;
|
|
import java.net.UnknownHostException;
|
|
import java.util.ArrayList;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
@@ -36,16 +36,16 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.InOrder;
|
|
|
|
-class InfluxDbReporterTest {
|
|
+final class InfluxDbReporterTest {
|
|
private static final MetricName GAUGE = MetricName.build("gauge");
|
|
private static final MetricName METER = MetricName.build("meter");
|
|
private static final MetricName COUNTER = MetricName.build("counter");
|
|
|
|
private final long timestamp = 1000198;
|
|
- private final Clock clock = mock(Clock.class);
|
|
- private final InfluxDbSender sender = mock(InfluxDbSender.class);
|
|
+ private final Clock clock = mock();
|
|
+ private final InfluxDbSender sender = mock();
|
|
private final List<String> send = new ArrayList<>();
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+ private final MetricRegistry registry = mock();
|
|
private final InfluxDbReporter reporter =
|
|
InfluxDbReporter.forRegistry(registry)
|
|
.withClock(clock)
|
|
@@ -53,7 +53,7 @@ class InfluxDbReporterTest {
|
|
.convertRatesTo(TimeUnit.SECONDS)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.build(sender);
|
|
|
|
private final InfluxDbReporter minuteRateReporter =
|
|
@@ -63,7 +63,7 @@ class InfluxDbReporterTest {
|
|
.convertRatesTo(TimeUnit.MINUTES)
|
|
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
|
.filter(MetricFilter.ALL)
|
|
- .disabledMetricAttributes(Collections.emptySet())
|
|
+ .disabledMetricAttributes(ImmutableSet.of())
|
|
.build(sender);
|
|
|
|
@BeforeEach
|
|
@@ -197,7 +197,7 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void reportsCounters() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
reporter.report(map(), map(COUNTER, counter), map(), map(), map());
|
|
@@ -214,11 +214,11 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void reportsHistograms() throws Exception {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(12L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -249,7 +249,7 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void reportsMeters() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -274,7 +274,7 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void reportsMetersInMinutes() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -300,7 +300,7 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void reportsTimers() throws Exception {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getSum()).thenReturn(6L);
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
@@ -308,7 +308,7 @@ class InfluxDbReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -360,7 +360,7 @@ class InfluxDbReporterTest {
|
|
|
|
@Test
|
|
void disabledMetricsAttribute() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getSum()).thenReturn(6L);
|
|
when(meter.getOneMinuteRate()).thenReturn(2.0);
|
|
@@ -368,7 +368,7 @@ class InfluxDbReporterTest {
|
|
when(meter.getFifteenMinuteRate()).thenReturn(4.0);
|
|
when(meter.getMeanRate()).thenReturn(5.0);
|
|
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(11L);
|
|
|
|
Set<MetricAttribute> disabledMetricAttributes =
|
|
--- a/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbUdpTest.java
|
|
+++ b/metrics-influxdb/src/test/java/io/dropwizard/metrics5/influxdb/InfluxDbUdpTest.java
|
|
@@ -3,6 +3,7 @@ package io.dropwizard.metrics5.influxdb;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.mockito.Mockito.any;
|
|
import static org.mockito.Mockito.doAnswer;
|
|
+import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
@@ -14,15 +15,14 @@ import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
-import org.mockito.Mockito;
|
|
|
|
-class InfluxDbUdpTest {
|
|
+final class InfluxDbUdpTest {
|
|
|
|
private final String host = "example.com";
|
|
private final int port = 1234;
|
|
|
|
private InfluxDbUdpSender influxdbUdp;
|
|
- private final DatagramChannel datagramChannel = Mockito.mock(DatagramChannel.class);
|
|
+ private final DatagramChannel datagramChannel = mock();
|
|
private final List<byte[]> sent = new ArrayList<>();
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jakarta-servlet/src/main/java/io/dropwizard/metrics5/servlet/AbstractInstrumentedFilter.java
|
|
+++ b/metrics-jakarta-servlet/src/main/java/io/dropwizard/metrics5/servlet/AbstractInstrumentedFilter.java
|
|
@@ -2,6 +2,7 @@ package io.dropwizard.metrics5.servlet;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
|
|
+import com.google.common.base.Strings;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -64,7 +65,7 @@ public abstract class AbstractInstrumentedFilter implements Filter {
|
|
final MetricRegistry metricsRegistry = getMetricsFactory(filterConfig);
|
|
|
|
String metricName = filterConfig.getInitParameter(METRIC_PREFIX);
|
|
- if (metricName == null || metricName.isEmpty()) {
|
|
+ if (Strings.isNullOrEmpty(metricName)) {
|
|
metricName = getClass().getName();
|
|
}
|
|
|
|
--- a/metrics-jakarta-servlet/src/test/java/io/dropwizard/metrics5/servlet/InstrumentedFilterContextListenerTest.java
|
|
+++ b/metrics-jakarta-servlet/src/test/java/io/dropwizard/metrics5/servlet/InstrumentedFilterContextListenerTest.java
|
|
@@ -9,8 +9,8 @@ import jakarta.servlet.ServletContext;
|
|
import jakarta.servlet.ServletContextEvent;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedFilterContextListenerTest {
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+final class InstrumentedFilterContextListenerTest {
|
|
+ private final MetricRegistry registry = mock();
|
|
private final InstrumentedFilterContextListener listener =
|
|
new InstrumentedFilterContextListener() {
|
|
@Override
|
|
@@ -21,9 +21,9 @@ class InstrumentedFilterContextListenerTest {
|
|
|
|
@Test
|
|
void injectsTheMetricRegistryIntoTheServletContext() {
|
|
- final ServletContext context = mock(ServletContext.class);
|
|
+ final ServletContext context = mock();
|
|
|
|
- final ServletContextEvent event = mock(ServletContextEvent.class);
|
|
+ final ServletContextEvent event = mock();
|
|
when(event.getServletContext()).thenReturn(context);
|
|
|
|
listener.contextInitialized(event);
|
|
--- a/metrics-jakarta-servlet6/src/main/java/io/dropwizard/metrics5/servlet6/AbstractInstrumentedFilter.java
|
|
+++ b/metrics-jakarta-servlet6/src/main/java/io/dropwizard/metrics5/servlet6/AbstractInstrumentedFilter.java
|
|
@@ -2,6 +2,7 @@ package io.dropwizard.metrics5.servlet6;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
|
|
+import com.google.common.base.Strings;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -64,7 +65,7 @@ public abstract class AbstractInstrumentedFilter implements Filter {
|
|
final MetricRegistry metricsRegistry = getMetricsFactory(filterConfig);
|
|
|
|
String metricName = filterConfig.getInitParameter(METRIC_PREFIX);
|
|
- if (metricName == null || metricName.isEmpty()) {
|
|
+ if (Strings.isNullOrEmpty(metricName)) {
|
|
metricName = getClass().getName();
|
|
}
|
|
|
|
--- a/metrics-jakarta-servlet6/src/test/java/io/dropwizard/metrics5/servlet6/InstrumentedFilterContextListenerTest.java
|
|
+++ b/metrics-jakarta-servlet6/src/test/java/io/dropwizard/metrics5/servlet6/InstrumentedFilterContextListenerTest.java
|
|
@@ -9,8 +9,8 @@ import jakarta.servlet.ServletContext;
|
|
import jakarta.servlet.ServletContextEvent;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedFilterContextListenerTest {
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+final class InstrumentedFilterContextListenerTest {
|
|
+ private final MetricRegistry registry = mock();
|
|
private final InstrumentedFilterContextListener listener =
|
|
new InstrumentedFilterContextListener() {
|
|
@Override
|
|
@@ -21,9 +21,9 @@ class InstrumentedFilterContextListenerTest {
|
|
|
|
@Test
|
|
void injectsTheMetricRegistryIntoTheServletContext() {
|
|
- final ServletContext context = mock(ServletContext.class);
|
|
+ final ServletContext context = mock();
|
|
|
|
- final ServletContextEvent event = mock(ServletContextEvent.class);
|
|
+ final ServletContextEvent event = mock();
|
|
when(event.getServletContext()).thenReturn(context);
|
|
|
|
listener.contextInitialized(event);
|
|
--- a/metrics-jakarta-servlets/src/main/java/io/dropwizard/metrics5/servlets/HealthCheckServlet.java
|
|
+++ b/metrics-jakarta-servlets/src/main/java/io/dropwizard/metrics5/servlets/HealthCheckServlet.java
|
|
@@ -99,7 +99,7 @@ public class HealthCheckServlet extends HttpServlet {
|
|
super.init(config);
|
|
|
|
final ServletContext context = config.getServletContext();
|
|
- if (null == registry) {
|
|
+ if (registry == null) {
|
|
final Object registryAttr = context.getAttribute(HEALTH_CHECK_REGISTRY);
|
|
if (registryAttr instanceof HealthCheckRegistry) {
|
|
this.registry = (HealthCheckRegistry) registryAttr;
|
|
--- a/metrics-jakarta-servlets/src/main/java/io/dropwizard/metrics5/servlets/MetricsServlet.java
|
|
+++ b/metrics-jakarta-servlets/src/main/java/io/dropwizard/metrics5/servlets/MetricsServlet.java
|
|
@@ -131,7 +131,7 @@ public class MetricsServlet extends HttpServlet {
|
|
super.init(config);
|
|
|
|
final ServletContext context = config.getServletContext();
|
|
- if (null == registry) {
|
|
+ if (registry == null) {
|
|
final Object registryAttr = context.getAttribute(METRICS_REGISTRY);
|
|
if (registryAttr instanceof MetricRegistry) {
|
|
this.registry = (MetricRegistry) registryAttr;
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletExclusionTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletExclusionTest.java
|
|
@@ -9,7 +9,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class AdminServletExclusionTest extends AbstractServletTest {
|
|
+final class AdminServletExclusionTest extends AbstractServletTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
|
|
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletTest.java
|
|
@@ -9,7 +9,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class AdminServletTest extends AbstractServletTest {
|
|
+final class AdminServletTest extends AbstractServletTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
|
|
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletUriTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletUriTest.java
|
|
@@ -9,7 +9,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class AdminServletUriTest extends AbstractServletTest {
|
|
+final class AdminServletUriTest extends AbstractServletTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
|
|
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/CpuProfileServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/CpuProfileServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CpuProfileServletTest extends AbstractServletTest {
|
|
+final class CpuProfileServletTest extends AbstractServletTest {
|
|
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/HealthCheckServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/HealthCheckServletTest.java
|
|
@@ -1,10 +1,9 @@
|
|
package io.dropwizard.metrics5.servlets;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
-import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@@ -27,7 +26,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HealthCheckServletTest extends AbstractServletTest {
|
|
+final class HealthCheckServletTest extends AbstractServletTest {
|
|
|
|
private static final ZonedDateTime FIXED_TIME = ZonedDateTime.now();
|
|
|
|
@@ -95,9 +94,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\"}}");
|
|
+ "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"%s\"}}",
|
|
+ EXPECTED_TIMESTAMP);
|
|
}
|
|
|
|
@Test
|
|
@@ -111,9 +109,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\"}}");
|
|
+ "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"%s\"}}",
|
|
+ EXPECTED_TIMESTAMP);
|
|
}
|
|
|
|
@Test
|
|
@@ -168,15 +165,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
String.format(
|
|
- "{%n"
|
|
- + " \"fun\" : {%n"
|
|
- + " \"healthy\" : true,%n"
|
|
- + " \"message\" : \"foo bar 123\",%n"
|
|
- + " \"duration\" : 0,%n"
|
|
- + " \"timestamp\" : \""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\""
|
|
- + "%n }%n}"));
|
|
+ "{%n \"fun\" : {%n \"healthy\" : true,%n \"message\" : \"foo bar 123\",%n \"duration\" : 0,%n \"timestamp\" : \"%s\"%n }%n}",
|
|
+ EXPECTED_TIMESTAMP));
|
|
}
|
|
|
|
private static HealthCheck.Result healthyResultWithMessage(String message) {
|
|
@@ -197,23 +187,23 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
|
|
- final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final HealthCheckRegistry healthCheckRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
|
|
final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(healthCheckRegistry);
|
|
healthCheckServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
+ verify(servletConfig).getServletContext();
|
|
verify(servletContext, never()).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
|
|
- final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final HealthCheckRegistry healthCheckRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
.thenReturn(healthCheckRegistry);
|
|
@@ -221,32 +211,32 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
healthCheckServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, times(1)).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- assertThrows(
|
|
- ServletException.class,
|
|
- () -> {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
- when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
- .thenReturn("IRELLEVANT_STRING");
|
|
-
|
|
- final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
- healthCheckServlet.init(servletConfig);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
+ when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
+ when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
+ .thenReturn("IRELLEVANT_STRING");
|
|
+
|
|
+ final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
+ healthCheckServlet.init(servletConfig);
|
|
+ })
|
|
+ .isInstanceOf(ServletException.class);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithObjectMapperAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
.thenReturn(registry);
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletContextListenerTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletContextListenerTest.java
|
|
@@ -17,8 +17,8 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricsServletContextListenerTest extends AbstractServletTest {
|
|
- private final Clock clock = mock(Clock.class);
|
|
+final class MetricsServletContextListenerTest extends AbstractServletTest {
|
|
+ private final Clock clock = mock();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final String allowedOrigin = "some.other.origin";
|
|
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletTest.java
|
|
@@ -1,11 +1,9 @@
|
|
package io.dropwizard.metrics5.servlets;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
-import static org.mockito.ArgumentMatchers.eq;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
-import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@@ -25,8 +23,8 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricsServletTest extends AbstractServletTest {
|
|
- private final Clock clock = mock(Clock.class);
|
|
+final class MetricsServletTest extends AbstractServletTest {
|
|
+ private final Clock clock = mock();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private ServletTester tester;
|
|
|
|
@@ -130,22 +128,8 @@ class MetricsServletTest extends AbstractServletTest {
|
|
assertThat(response.get("Access-Control-Allow-Origin")).isEqualTo("*");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- callbackParamVal
|
|
- + "({"
|
|
- + "\"version\":\"5.0.0\","
|
|
- + "\"gauges\":{"
|
|
- + "\"g1\":{\"value\":100}"
|
|
- + "},"
|
|
- + "\"counters\":{"
|
|
- + "\"c\":{\"count\":1}"
|
|
- + "},"
|
|
- + "\"histograms\":{"
|
|
- + "\"h\":{\"count\":1,\"max\":1,\"mean\":1.0,\"min\":1,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0}"
|
|
- + "},"
|
|
- + "\"meters\":{"
|
|
- + "\"m\":{\"count\":1,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":3333333.3333333335,\"units\":\"events/second\"}},\"timers\":{\"t\":{\"count\":1,\"max\":1.0,\"mean\":1.0,\"min\":1.0,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":1.0E7,\"duration_units\":\"seconds\",\"rate_units\":\"calls/second\"}"
|
|
- + "}"
|
|
- + "})");
|
|
+ "%s({\"version\":\"5.0.0\",\"gauges\":{\"g1\":{\"value\":100}},\"counters\":{\"c\":{\"count\":1}},\"histograms\":{\"h\":{\"count\":1,\"max\":1,\"mean\":1.0,\"min\":1,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0}},\"meters\":{\"m\":{\"count\":1,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":3333333.3333333335,\"units\":\"events/second\"}},\"timers\":{\"t\":{\"count\":1,\"max\":1.0,\"mean\":1.0,\"min\":1.0,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":1.0E7,\"duration_units\":\"seconds\",\"rate_units\":\"calls/second\"}}})",
|
|
+ callbackParamVal);
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
}
|
|
|
|
@@ -224,48 +208,47 @@ class MetricsServletTest extends AbstractServletTest {
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
|
|
- final MetricRegistry metricRegistry = mock(MetricRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final MetricRegistry metricRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
|
|
final MetricsServlet metricsServlet = new MetricsServlet(metricRegistry);
|
|
metricsServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, never()).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext, never()).getAttribute(MetricsServlet.METRICS_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
|
|
- final MetricRegistry metricRegistry = mock(MetricRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final MetricRegistry metricRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(eq(MetricsServlet.METRICS_REGISTRY)))
|
|
- .thenReturn(metricRegistry);
|
|
+ when(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).thenReturn(metricRegistry);
|
|
|
|
final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
metricsServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, times(1)).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext).getAttribute(MetricsServlet.METRICS_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- assertThrows(
|
|
- ServletException.class,
|
|
- () -> {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
- when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(eq(MetricsServlet.METRICS_REGISTRY)))
|
|
- .thenReturn("IRELLEVANT_STRING");
|
|
-
|
|
- final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
- metricsServlet.init(servletConfig);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
+ when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
+ when(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY))
|
|
+ .thenReturn("IRELLEVANT_STRING");
|
|
+
|
|
+ final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
+ metricsServlet.init(servletConfig);
|
|
+ })
|
|
+ .isInstanceOf(ServletException.class);
|
|
}
|
|
}
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/PingServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/PingServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class PingServletTest extends AbstractServletTest {
|
|
+final class PingServletTest extends AbstractServletTest {
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
tester.addServlet(PingServlet.class, "/ping");
|
|
--- a/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/ThreadDumpServletTest.java
|
|
+++ b/metrics-jakarta-servlets/src/test/java/io/dropwizard/metrics5/servlets/ThreadDumpServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ThreadDumpServletTest extends AbstractServletTest {
|
|
+final class ThreadDumpServletTest extends AbstractServletTest {
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
tester.addServlet(ThreadDumpServlet.class, "/threads");
|
|
--- a/metrics-jcache/src/main/java/io/dropwizard/metrics5/jcache/JCacheGaugeSet.java
|
|
+++ b/metrics-jcache/src/main/java/io/dropwizard/metrics5/jcache/JCacheGaugeSet.java
|
|
@@ -1,6 +1,7 @@
|
|
package io.dropwizard.metrics5.jcache;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -9,7 +10,6 @@ import io.dropwizard.metrics5.jvm.JmxAttributeGauge;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
@@ -33,7 +33,7 @@ public class JCacheGaugeSet implements MetricSet {
|
|
private static final String M_BEAN_COORDINATES =
|
|
"javax.cache:type=CacheStatistics,CacheManager=*,Cache=*";
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(JCacheGaugeSet.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(JCacheGaugeSet.class);
|
|
|
|
@Override
|
|
public Map<MetricName, Metric> getMetrics() {
|
|
@@ -52,7 +52,7 @@ public class JCacheGaugeSet implements MetricSet {
|
|
}
|
|
}
|
|
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
|
|
private Set<ObjectInstance> getCacheBeans() {
|
|
@@ -60,7 +60,7 @@ public class JCacheGaugeSet implements MetricSet {
|
|
return ManagementFactory.getPlatformMBeanServer()
|
|
.queryMBeans(ObjectName.getInstance(M_BEAN_COORDINATES), null);
|
|
} catch (MalformedObjectNameException e) {
|
|
- LOGGER.error("Unable to retrieve {}. Are JCache statistics enabled?", M_BEAN_COORDINATES);
|
|
+ LOG.error("Unable to retrieve {}. Are JCache statistics enabled?", M_BEAN_COORDINATES);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
--- a/metrics-jcache/src/test/java/JCacheGaugeSetTest.java
|
|
+++ b/metrics-jcache/src/test/java/JCacheGaugeSetTest.java
|
|
@@ -11,7 +11,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class JCacheGaugeSetTest {
|
|
+final class JCacheGaugeSetTest {
|
|
|
|
private MetricRegistry registry;
|
|
private Cache<Object, Object> myCache;
|
|
@@ -67,11 +67,11 @@ class JCacheGaugeSetTest {
|
|
|
|
this.myCache.remove("woo2");
|
|
assertThat((Float) registry.getGauges().get(myCache.resolve("average-get-time")).getValue())
|
|
- .isGreaterThan(0.0f);
|
|
+ .isPositive();
|
|
assertThat((Float) registry.getGauges().get(myCache.resolve("average-put-time")).getValue())
|
|
- .isGreaterThan(0.0f);
|
|
+ .isPositive();
|
|
assertThat((Float) registry.getGauges().get(myCache.resolve("average-remove-time")).getValue())
|
|
- .isGreaterThan(0.0f);
|
|
+ .isPositive();
|
|
}
|
|
|
|
@AfterEach
|
|
--- a/metrics-jdbi3/src/main/java/io/dropwizard/metrics5/jdbi3/strategies/DefaultNameStrategy.java
|
|
+++ b/metrics-jdbi3/src/main/java/io/dropwizard/metrics5/jdbi3/strategies/DefaultNameStrategy.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.jdbi3.strategies;
|
|
|
|
+import com.google.common.base.Strings;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import org.jdbi.v3.core.extension.ExtensionMethod;
|
|
@@ -13,7 +14,7 @@ public enum DefaultNameStrategy implements StatementNameStrategy {
|
|
@Override
|
|
public MetricName getStatementName(StatementContext statementContext) {
|
|
final String rawSql = statementContext.getRawSql();
|
|
- return rawSql == null || rawSql.isEmpty() ? MetricName.build("sql.empty") : null;
|
|
+ return Strings.isNullOrEmpty(rawSql) ? MetricName.build("sql.empty") : null;
|
|
}
|
|
},
|
|
|
|
--- a/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/BasicSqlNameStrategyTest.java
|
|
+++ b/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/BasicSqlNameStrategyTest.java
|
|
@@ -8,7 +8,7 @@ import io.dropwizard.metrics5.MetricName;
|
|
import org.jdbi.v3.core.extension.ExtensionMethod;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class BasicSqlNameStrategyTest extends AbstractStrategyTest {
|
|
+final class BasicSqlNameStrategyTest extends AbstractStrategyTest {
|
|
|
|
private final BasicSqlNameStrategy basicSqlNameStrategy = new BasicSqlNameStrategy();
|
|
|
|
--- a/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/InstrumentedSqlLoggerTest.java
|
|
+++ b/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/InstrumentedSqlLoggerTest.java
|
|
@@ -12,15 +12,15 @@ import java.util.concurrent.TimeUnit;
|
|
import org.jdbi.v3.core.statement.StatementContext;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedSqlLoggerTest {
|
|
+final class InstrumentedSqlLoggerTest {
|
|
@Test
|
|
void logsExecutionTime() {
|
|
- final MetricRegistry mockRegistry = mock(MetricRegistry.class);
|
|
- final StatementNameStrategy mockNameStrategy = mock(StatementNameStrategy.class);
|
|
+ final MetricRegistry mockRegistry = mock();
|
|
+ final StatementNameStrategy mockNameStrategy = mock();
|
|
final InstrumentedSqlLogger logger = new InstrumentedSqlLogger(mockRegistry, mockNameStrategy);
|
|
|
|
- final StatementContext mockContext = mock(StatementContext.class);
|
|
- final Timer mockTimer = mock(Timer.class);
|
|
+ final StatementContext mockContext = mock();
|
|
+ final Timer mockTimer = mock();
|
|
|
|
final MetricName statementName = MetricName.build("my-fake-name");
|
|
final long fakeElapsed = 1234L;
|
|
@@ -37,12 +37,12 @@ class InstrumentedSqlLoggerTest {
|
|
|
|
@Test
|
|
void logsExceptionTime() {
|
|
- final MetricRegistry mockRegistry = mock(MetricRegistry.class);
|
|
- final StatementNameStrategy mockNameStrategy = mock(StatementNameStrategy.class);
|
|
+ final MetricRegistry mockRegistry = mock();
|
|
+ final StatementNameStrategy mockNameStrategy = mock();
|
|
final InstrumentedSqlLogger logger = new InstrumentedSqlLogger(mockRegistry, mockNameStrategy);
|
|
|
|
- final StatementContext mockContext = mock(StatementContext.class);
|
|
- final Timer mockTimer = mock(Timer.class);
|
|
+ final StatementContext mockContext = mock();
|
|
+ final Timer mockTimer = mock();
|
|
|
|
final MetricName statementName = MetricName.build("my-fake-name");
|
|
final long fakeElapsed = 1234L;
|
|
--- a/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/NaiveNameStrategyTest.java
|
|
+++ b/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/NaiveNameStrategyTest.java
|
|
@@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class NaiveNameStrategyTest extends AbstractStrategyTest {
|
|
+final class NaiveNameStrategyTest extends AbstractStrategyTest {
|
|
|
|
private final NaiveNameStrategy naiveNameStrategy = new NaiveNameStrategy();
|
|
|
|
--- a/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/SmartNameStrategyTest.java
|
|
+++ b/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/SmartNameStrategyTest.java
|
|
@@ -12,7 +12,7 @@ import org.jdbi.v3.core.extension.ExtensionMethod;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class SmartNameStrategyTest extends AbstractStrategyTest {
|
|
+final class SmartNameStrategyTest extends AbstractStrategyTest {
|
|
|
|
private final StatementNameStrategy smartNameStrategy = new SmartNameStrategy();
|
|
private InstrumentedTimingCollector collector;
|
|
--- a/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/TimedAnnotationNameStrategyTest.java
|
|
+++ b/metrics-jdbi3/src/test/java/io/dropwizard/metrics5/jdbi3/strategies/TimedAnnotationNameStrategyTest.java
|
|
@@ -8,7 +8,7 @@ import io.dropwizard.metrics5.annotation.Timed;
|
|
import org.jdbi.v3.core.extension.ExtensionMethod;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
+final class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
|
|
private final TimedAnnotationNameStrategy timedAnnotationNameStrategy =
|
|
new TimedAnnotationNameStrategy();
|
|
@@ -44,7 +44,7 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAnnotationOnMethod() throws Exception {
|
|
+ void annotationOnMethod() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("update")));
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx))
|
|
@@ -54,7 +54,7 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAnnotationOnMethodWithCustomName() throws Exception {
|
|
+ void annotationOnMethodWithCustomName() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("customUpdate")));
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx))
|
|
@@ -64,7 +64,7 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAnnotationOnMethodWithCustomAbsoluteName() throws Exception {
|
|
+ void annotationOnMethodWithCustomAbsoluteName() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("absoluteUpdate")));
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx))
|
|
@@ -72,7 +72,7 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAnnotationOnClass() throws Exception {
|
|
+ void annotationOnClass() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(new ExtensionMethod(Bar.class, Bar.class.getMethod("update")));
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx))
|
|
@@ -82,7 +82,7 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAnnotationOnMethodAndClassWithCustomNames() throws Exception {
|
|
+ void annotationOnMethodAndClassWithCustomNames() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(
|
|
new ExtensionMethod(CustomBar.class, CustomBar.class.getMethod("find", String.class)));
|
|
@@ -91,14 +91,14 @@ class TimedAnnotationNameStrategyTest extends AbstractStrategyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testNoAnnotations() throws Exception {
|
|
+ void noAnnotations() throws Exception {
|
|
when(ctx.getExtensionMethod())
|
|
.thenReturn(new ExtensionMethod(Dummy.class, Dummy.class.getMethod("show")));
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isNull();
|
|
}
|
|
|
|
@Test
|
|
- void testNoMethod() {
|
|
+ void noMethod() {
|
|
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isNull();
|
|
}
|
|
}
|
|
--- a/metrics-jersey2/src/main/java/io/dropwizard/metrics5/jersey2/InstrumentedResourceMethodApplicationListener.java
|
|
+++ b/metrics-jersey2/src/main/java/io/dropwizard/metrics5/jersey2/InstrumentedResourceMethodApplicationListener.java
|
|
@@ -3,7 +3,11 @@ package io.dropwizard.metrics5.jersey2;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.base.Strings;
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.ExponentiallyDecayingReservoir;
|
|
import io.dropwizard.metrics5.Meter;
|
|
@@ -19,7 +23,6 @@ import io.dropwizard.metrics5.annotation.Timed;
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -159,7 +162,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
this.level = responseMetered.level();
|
|
this.meters =
|
|
COARSE_METER_LEVELS.contains(level)
|
|
- ? Collections.unmodifiableList(
|
|
+ ? unmodifiableList(
|
|
Arrays.asList(
|
|
registry.meter(metricName.resolve("1xx-responses")), // 1xx
|
|
registry.meter(metricName.resolve("2xx-responses")), // 2xx
|
|
@@ -167,11 +170,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
registry.meter(metricName.resolve("4xx-responses")), // 4xx
|
|
registry.meter(metricName.resolve("5xx-responses")) // 5xx
|
|
))
|
|
- : Collections.emptyList();
|
|
+ : ImmutableList.of();
|
|
this.responseCodeMeters =
|
|
- DETAILED_METER_LEVELS.contains(level)
|
|
- ? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ DETAILED_METER_LEVELS.contains(level) ? new ConcurrentHashMap<>() : ImmutableMap.of();
|
|
this.metricRegistry = registry;
|
|
}
|
|
|
|
@@ -305,9 +306,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
: null;
|
|
|
|
if (metric != null) {
|
|
- if (metric.cause.isAssignableFrom(event.getException().getClass())
|
|
+ if (metric.cause.isInstance(event.getException())
|
|
|| (event.getException().getCause() != null
|
|
- && metric.cause.isAssignableFrom(event.getException().getCause().getClass()))) {
|
|
+ && metric.cause.isInstance(event.getException().getCause()))) {
|
|
metric.meter.mark();
|
|
}
|
|
}
|
|
@@ -418,14 +419,11 @@ public class InstrumentedResourceMethodApplicationListener
|
|
|
|
@Override
|
|
public RequestEventListener onRequest(final RequestEvent event) {
|
|
- final RequestEventListener listener =
|
|
- new ChainedRequestEventListener(
|
|
- new TimerRequestEventListener(timers, clock),
|
|
- new MeterRequestEventListener(meters),
|
|
- new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
- new ResponseMeterRequestEventListener(responseMeters));
|
|
-
|
|
- return listener;
|
|
+ return new ChainedRequestEventListener(
|
|
+ new TimerRequestEventListener(timers, clock),
|
|
+ new MeterRequestEventListener(meters),
|
|
+ new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
+ new ResponseMeterRequestEventListener(responseMeters));
|
|
}
|
|
|
|
private <T extends Annotation> T getClassLevelAnnotation(
|
|
@@ -543,7 +541,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
final String... suffixes) {
|
|
final Method definitionMethod = method.getInvocable().getDefinitionMethod();
|
|
MetricName metricName;
|
|
- if (explicitName != null && !explicitName.isEmpty()) {
|
|
+ if (!Strings.isNullOrEmpty(explicitName)) {
|
|
metricName =
|
|
absolute
|
|
? MetricRegistry.name(explicitName)
|
|
@@ -604,8 +602,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
@Override
|
|
public int hashCode() {
|
|
int result = type.hashCode();
|
|
- result = 31 * result + method.hashCode();
|
|
- return result;
|
|
+ return 31 * result + method.hashCode();
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/CustomReservoirImplementationTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/CustomReservoirImplementationTest.java
|
|
@@ -14,7 +14,7 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|
import org.glassfish.jersey.test.JerseyTest;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CustomReservoirImplementationTest extends JerseyTest {
|
|
+final class CustomReservoirImplementationTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonFilterMetricsJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonFilterMetricsJerseyTest.java
|
|
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig} with filter tracking
|
|
*/
|
|
-class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -34,8 +34,7 @@ class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry, testClock, true));
|
|
config = config.register(new TestRequestFilter(testClock));
|
|
- config = config.register(new InstrumentedFilteredResource(testClock));
|
|
- return config;
|
|
+ return config.register(new InstrumentedFilteredResource(testClock));
|
|
}
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -34,9 +34,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -50,7 +48,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -75,7 +73,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
assertThat(target("subresource/exception-metered").request().get(String.class))
|
|
.isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("subresource/exception-metered")
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsJerseyTest.java
|
|
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link org.glassfish.jersey.server.ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -37,9 +37,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResource.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResource.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -67,7 +65,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -92,13 +90,13 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
registry.meter(
|
|
MetricRegistry.name(InstrumentedResource.class, "response5xxMetered", "5xx-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-2xx-metered").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter4xx.getCount()).isZero();
|
|
+ assertThat(meter4xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-4xx-metered").request().get().getStatus()).isEqualTo(400);
|
|
|
|
- assertThat(meter5xx.getCount()).isZero();
|
|
+ assertThat(meter5xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-5xx-metered").request().get().getStatus()).isEqualTo(500);
|
|
|
|
assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
@@ -107,7 +105,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
}
|
|
|
|
@Test
|
|
- void testResourceNotFound() {
|
|
+ void resourceNotFound() {
|
|
final Response response = target().path("not-found").request().get();
|
|
assertThat(response.getStatus()).isEqualTo(404);
|
|
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
@@ -17,7 +17,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -31,9 +31,7 @@ class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
@@ -1,7 +1,7 @@
|
|
package io.dropwizard.metrics5.jersey2;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -34,9 +34,7 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
config = config.register(InstrumentedResourceResponseMeteredPerClass.class);
|
|
- config = config.register(new TestExceptionMapper());
|
|
-
|
|
- return config;
|
|
+ return config.register(new TestExceptionMapper());
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsTimedPerClassJerseyTest.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/SingletonMetricsTimedPerClassJerseyTest.java
|
|
@@ -17,7 +17,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -31,9 +31,7 @@ class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceTimedPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceTimedPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedFilteredResource.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedFilteredResource.java
|
|
@@ -18,24 +18,24 @@ public class InstrumentedFilteredResource {
|
|
}
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick++;
|
|
return "yay";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "fancyName")
|
|
@Path("/named")
|
|
+ @Timed(name = "fancyName")
|
|
public String named() {
|
|
testClock.tick++;
|
|
return "fancy";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "absolutelyFancy", absolute = true)
|
|
@Path("/absolute")
|
|
+ @Timed(name = "absolutelyFancy", absolute = true)
|
|
public String absolute() {
|
|
testClock.tick++;
|
|
return "absolute";
|
|
@@ -50,8 +50,8 @@ public class InstrumentedFilteredResource {
|
|
public class InstrumentedFilteredSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick += 2;
|
|
return "yay";
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedResource.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedResource.java
|
|
@@ -21,8 +21,8 @@ import javax.ws.rs.core.Response;
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
public class InstrumentedResource {
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
@@ -34,8 +34,8 @@ public class InstrumentedResource {
|
|
return "woo";
|
|
}
|
|
|
|
- @GET
|
|
@ExceptionMetered(cause = IOException.class)
|
|
+ @GET
|
|
@Path("/exception-metered")
|
|
public String exceptionMetered(@QueryParam("splode") @DefaultValue("false") boolean splode)
|
|
throws IOException {
|
|
@@ -46,46 +46,46 @@ public class InstrumentedResource {
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = DETAILED)
|
|
@Path("/response-metered-detailed")
|
|
+ @ResponseMetered(level = DETAILED)
|
|
public Response responseMeteredDetailed(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = COARSE)
|
|
@Path("/response-metered-coarse")
|
|
+ @ResponseMetered(level = COARSE)
|
|
public Response responseMeteredCoarse(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = ALL)
|
|
@Path("/response-metered-all")
|
|
+ @ResponseMetered(level = ALL)
|
|
public Response responseMeteredAll(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-2xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response2xxMetered() {
|
|
return Response.ok().build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-4xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response4xxMetered() {
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-5xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response5xxMetered() {
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
}
|
|
--- a/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedSubResource.java
|
|
+++ b/metrics-jersey2/src/test/java/io/dropwizard/metrics5/jersey2/resources/InstrumentedSubResource.java
|
|
@@ -10,8 +10,8 @@ import javax.ws.rs.core.MediaType;
|
|
public class InstrumentedSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
--- a/metrics-jersey3/src/main/java/io/dropwizard/metrics5/jersey3/InstrumentedResourceMethodApplicationListener.java
|
|
+++ b/metrics-jersey3/src/main/java/io/dropwizard/metrics5/jersey3/InstrumentedResourceMethodApplicationListener.java
|
|
@@ -4,7 +4,11 @@ import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.base.Strings;
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.ExponentiallyDecayingReservoir;
|
|
import io.dropwizard.metrics5.Meter;
|
|
@@ -22,7 +26,6 @@ import jakarta.ws.rs.ext.Provider;
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -160,7 +163,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
this.level = responseMetered.level();
|
|
this.meters =
|
|
COARSE_METER_LEVELS.contains(level)
|
|
- ? Collections.unmodifiableList(
|
|
+ ? unmodifiableList(
|
|
Arrays.asList(
|
|
registry.meter(metricName.resolve("1xx-responses")), // 1xx
|
|
registry.meter(metricName.resolve("2xx-responses")), // 2xx
|
|
@@ -168,11 +171,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
registry.meter(metricName.resolve("4xx-responses")), // 4xx
|
|
registry.meter(metricName.resolve("5xx-responses")) // 5xx
|
|
))
|
|
- : Collections.emptyList();
|
|
+ : ImmutableList.of();
|
|
this.responseCodeMeters =
|
|
- DETAILED_METER_LEVELS.contains(level)
|
|
- ? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ DETAILED_METER_LEVELS.contains(level) ? new ConcurrentHashMap<>() : ImmutableMap.of();
|
|
this.metricRegistry = registry;
|
|
}
|
|
|
|
@@ -306,9 +307,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
: null;
|
|
|
|
if (metric != null) {
|
|
- if (metric.cause.isAssignableFrom(event.getException().getClass())
|
|
+ if (metric.cause.isInstance(event.getException())
|
|
|| (event.getException().getCause() != null
|
|
- && metric.cause.isAssignableFrom(event.getException().getCause().getClass()))) {
|
|
+ && metric.cause.isInstance(event.getException().getCause()))) {
|
|
metric.meter.mark();
|
|
}
|
|
}
|
|
@@ -419,14 +420,11 @@ public class InstrumentedResourceMethodApplicationListener
|
|
|
|
@Override
|
|
public RequestEventListener onRequest(final RequestEvent event) {
|
|
- final RequestEventListener listener =
|
|
- new ChainedRequestEventListener(
|
|
- new TimerRequestEventListener(timers, clock),
|
|
- new MeterRequestEventListener(meters),
|
|
- new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
- new ResponseMeterRequestEventListener(responseMeters));
|
|
-
|
|
- return listener;
|
|
+ return new ChainedRequestEventListener(
|
|
+ new TimerRequestEventListener(timers, clock),
|
|
+ new MeterRequestEventListener(meters),
|
|
+ new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
+ new ResponseMeterRequestEventListener(responseMeters));
|
|
}
|
|
|
|
private <T extends Annotation> T getClassLevelAnnotation(
|
|
@@ -544,7 +542,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
final String... suffixes) {
|
|
final Method definitionMethod = method.getInvocable().getDefinitionMethod();
|
|
MetricName metricName;
|
|
- if (explicitName != null && !explicitName.isEmpty()) {
|
|
+ if (!Strings.isNullOrEmpty(explicitName)) {
|
|
metricName =
|
|
absolute ? name(explicitName) : name(definitionMethod.getDeclaringClass(), explicitName);
|
|
} else {
|
|
@@ -602,8 +600,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
@Override
|
|
public int hashCode() {
|
|
int result = type.hashCode();
|
|
- result = 31 * result + method.hashCode();
|
|
- return result;
|
|
+ return 31 * result + method.hashCode();
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/CustomReservoirImplementationTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/CustomReservoirImplementationTest.java
|
|
@@ -14,7 +14,7 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|
import org.glassfish.jersey.test.JerseyTest;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CustomReservoirImplementationTest extends JerseyTest {
|
|
+final class CustomReservoirImplementationTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonFilterMetricsJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonFilterMetricsJerseyTest.java
|
|
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig} with filter tracking
|
|
*/
|
|
-class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,8 +35,7 @@ class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry, testClock, true));
|
|
config = config.register(new TestRequestFilter(testClock));
|
|
- config = config.register(new InstrumentedFilteredResource(testClock));
|
|
- return config;
|
|
+ return config.register(new InstrumentedFilteredResource(testClock));
|
|
}
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,9 +35,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -51,7 +49,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -76,7 +74,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
assertThat(target("subresource/exception-metered").request().get(String.class))
|
|
.isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("subresource/exception-metered")
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsJerseyTest.java
|
|
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link org.glassfish.jersey.server.ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -38,9 +38,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResource.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResource.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -67,7 +65,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -89,13 +87,13 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
final Meter meter5xx =
|
|
registry.meter(name(InstrumentedResource.class, "response5xxMetered", "5xx-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-2xx-metered").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter4xx.getCount()).isZero();
|
|
+ assertThat(meter4xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-4xx-metered").request().get().getStatus()).isEqualTo(400);
|
|
|
|
- assertThat(meter5xx.getCount()).isZero();
|
|
+ assertThat(meter5xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-5xx-metered").request().get().getStatus()).isEqualTo(500);
|
|
|
|
assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
@@ -115,9 +113,9 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
registry.meter(
|
|
name(InstrumentedResource.class, "responseMeteredDetailed", "201-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
- assertThat(meter201.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
+ assertThat(meter201.getCount()).isEqualTo(0);
|
|
assertThat(target("response-metered-detailed").request().get().getStatus()).isEqualTo(200);
|
|
assertThat(
|
|
target("response-metered-detailed")
|
|
@@ -127,28 +125,28 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
.getStatus())
|
|
.isEqualTo(201);
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
- assertThat(meter201.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
+ assertThat(meter201.getCount()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- public void responseMeteredMethodsAreMeteredWithAllLevel() {
|
|
+ void responseMeteredMethodsAreMeteredWithAllLevel() {
|
|
final Meter meter2xx =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredAll", "2xx-responses"));
|
|
final Meter meter200 =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredAll", "200-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
assertThat(target("response-metered-all").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter2xx.getCount()).isOne();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- void testResourceNotFound() {
|
|
+ void resourceNotFound() {
|
|
final Response response = target().path("not-found").request().get();
|
|
assertThat(response.getStatus()).isEqualTo(404);
|
|
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -32,9 +32,7 @@ class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
@@ -2,7 +2,7 @@ package io.dropwizard.metrics5.jersey3;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,9 +35,7 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
config = config.register(InstrumentedResourceResponseMeteredPerClass.class);
|
|
- config = config.register(new TestExceptionMapper());
|
|
-
|
|
- return config;
|
|
+ return config.register(new TestExceptionMapper());
|
|
}
|
|
|
|
@Test
|
|
@@ -140,8 +138,8 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
"responseMeteredPerClass",
|
|
"200-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
|
|
assertThat(target("subresource/responseMeteredPerClass").request().get().getStatus())
|
|
.isEqualTo(200);
|
|
@@ -154,7 +152,7 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
"2xx-responses"));
|
|
assertThat(meter.getCount()).isEqualTo(1);
|
|
|
|
- assertThat(meter2xx.getCount()).isOne();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
}
|
|
}
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsTimedPerClassJerseyTest.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/SingletonMetricsTimedPerClassJerseyTest.java
|
|
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -32,9 +32,7 @@ class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceTimedPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceTimedPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedFilteredResource.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedFilteredResource.java
|
|
@@ -18,24 +18,24 @@ public class InstrumentedFilteredResource {
|
|
}
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick++;
|
|
return "yay";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "fancyName")
|
|
@Path("/named")
|
|
+ @Timed(name = "fancyName")
|
|
public String named() {
|
|
testClock.tick++;
|
|
return "fancy";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "absolutelyFancy", absolute = true)
|
|
@Path("/absolute")
|
|
+ @Timed(name = "absolutelyFancy", absolute = true)
|
|
public String absolute() {
|
|
testClock.tick++;
|
|
return "absolute";
|
|
@@ -50,8 +50,8 @@ public class InstrumentedFilteredResource {
|
|
public class InstrumentedFilteredSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick += 2;
|
|
return "yay";
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedResource.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedResource.java
|
|
@@ -21,8 +21,8 @@ import java.io.IOException;
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
public class InstrumentedResource {
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
@@ -34,8 +34,8 @@ public class InstrumentedResource {
|
|
return "woo";
|
|
}
|
|
|
|
- @GET
|
|
@ExceptionMetered(cause = IOException.class)
|
|
+ @GET
|
|
@Path("/exception-metered")
|
|
public String exceptionMetered(@QueryParam("splode") @DefaultValue("false") boolean splode)
|
|
throws IOException {
|
|
@@ -46,46 +46,46 @@ public class InstrumentedResource {
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = DETAILED)
|
|
@Path("/response-metered-detailed")
|
|
+ @ResponseMetered(level = DETAILED)
|
|
public Response responseMeteredDetailed(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = COARSE)
|
|
@Path("/response-metered-coarse")
|
|
+ @ResponseMetered(level = COARSE)
|
|
public Response responseMeteredCoarse(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = ALL)
|
|
@Path("/response-metered-all")
|
|
+ @ResponseMetered(level = ALL)
|
|
public Response responseMeteredAll(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-2xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response2xxMetered() {
|
|
return Response.ok().build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-4xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response4xxMetered() {
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-5xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response5xxMetered() {
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
}
|
|
--- a/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedSubResource.java
|
|
+++ b/metrics-jersey3/src/test/java/io/dropwizard/metrics5/jersey3/resources/InstrumentedSubResource.java
|
|
@@ -10,8 +10,8 @@ import jakarta.ws.rs.core.MediaType;
|
|
public class InstrumentedSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
--- a/metrics-jersey31/src/main/java/io/dropwizard/metrics5/jersey31/InstrumentedResourceMethodApplicationListener.java
|
|
+++ b/metrics-jersey31/src/main/java/io/dropwizard/metrics5/jersey31/InstrumentedResourceMethodApplicationListener.java
|
|
@@ -4,7 +4,11 @@ import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.base.Strings;
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Clock;
|
|
import io.dropwizard.metrics5.ExponentiallyDecayingReservoir;
|
|
import io.dropwizard.metrics5.Meter;
|
|
@@ -22,7 +26,6 @@ import jakarta.ws.rs.ext.Provider;
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -160,7 +163,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
this.level = responseMetered.level();
|
|
this.meters =
|
|
COARSE_METER_LEVELS.contains(level)
|
|
- ? Collections.unmodifiableList(
|
|
+ ? unmodifiableList(
|
|
Arrays.asList(
|
|
registry.meter(metricName.resolve("1xx-responses")), // 1xx
|
|
registry.meter(metricName.resolve("2xx-responses")), // 2xx
|
|
@@ -168,11 +171,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
registry.meter(metricName.resolve("4xx-responses")), // 4xx
|
|
registry.meter(metricName.resolve("5xx-responses")) // 5xx
|
|
))
|
|
- : Collections.emptyList();
|
|
+ : ImmutableList.of();
|
|
this.responseCodeMeters =
|
|
- DETAILED_METER_LEVELS.contains(level)
|
|
- ? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ DETAILED_METER_LEVELS.contains(level) ? new ConcurrentHashMap<>() : ImmutableMap.of();
|
|
this.metricRegistry = registry;
|
|
}
|
|
|
|
@@ -306,9 +307,9 @@ public class InstrumentedResourceMethodApplicationListener
|
|
: null;
|
|
|
|
if (metric != null) {
|
|
- if (metric.cause.isAssignableFrom(event.getException().getClass())
|
|
+ if (metric.cause.isInstance(event.getException())
|
|
|| (event.getException().getCause() != null
|
|
- && metric.cause.isAssignableFrom(event.getException().getCause().getClass()))) {
|
|
+ && metric.cause.isInstance(event.getException().getCause()))) {
|
|
metric.meter.mark();
|
|
}
|
|
}
|
|
@@ -419,14 +420,11 @@ public class InstrumentedResourceMethodApplicationListener
|
|
|
|
@Override
|
|
public RequestEventListener onRequest(final RequestEvent event) {
|
|
- final RequestEventListener listener =
|
|
- new ChainedRequestEventListener(
|
|
- new TimerRequestEventListener(timers, clock),
|
|
- new MeterRequestEventListener(meters),
|
|
- new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
- new ResponseMeterRequestEventListener(responseMeters));
|
|
-
|
|
- return listener;
|
|
+ return new ChainedRequestEventListener(
|
|
+ new TimerRequestEventListener(timers, clock),
|
|
+ new MeterRequestEventListener(meters),
|
|
+ new ExceptionMeterRequestEventListener(exceptionMeters),
|
|
+ new ResponseMeterRequestEventListener(responseMeters));
|
|
}
|
|
|
|
private <T extends Annotation> T getClassLevelAnnotation(
|
|
@@ -544,7 +542,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
final String... suffixes) {
|
|
final Method definitionMethod = method.getInvocable().getDefinitionMethod();
|
|
MetricName metricName;
|
|
- if (explicitName != null && !explicitName.isEmpty()) {
|
|
+ if (!Strings.isNullOrEmpty(explicitName)) {
|
|
metricName =
|
|
absolute ? name(explicitName) : name(definitionMethod.getDeclaringClass(), explicitName);
|
|
} else {
|
|
@@ -602,8 +600,7 @@ public class InstrumentedResourceMethodApplicationListener
|
|
@Override
|
|
public int hashCode() {
|
|
int result = type.hashCode();
|
|
- result = 31 * result + method.hashCode();
|
|
- return result;
|
|
+ return 31 * result + method.hashCode();
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/CustomReservoirImplementationTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/CustomReservoirImplementationTest.java
|
|
@@ -14,7 +14,7 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|
import org.glassfish.jersey.test.JerseyTest;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CustomReservoirImplementationTest extends JerseyTest {
|
|
+final class CustomReservoirImplementationTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonFilterMetricsJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonFilterMetricsJerseyTest.java
|
|
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig} with filter tracking
|
|
*/
|
|
-class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,8 +35,7 @@ class SingletonFilterMetricsJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry, testClock, true));
|
|
config = config.register(new TestRequestFilter(testClock));
|
|
- config = config.register(new InstrumentedFilteredResource(testClock));
|
|
- return config;
|
|
+ return config.register(new InstrumentedFilteredResource(testClock));
|
|
}
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsExceptionMeteredPerClassJerseyTest.java
|
|
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,9 +35,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceExceptionMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -51,7 +49,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -76,7 +74,7 @@ class SingletonMetricsExceptionMeteredPerClassJerseyTest extends JerseyTest {
|
|
assertThat(target("subresource/exception-metered").request().get(String.class))
|
|
.isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("subresource/exception-metered")
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsJerseyTest.java
|
|
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -38,9 +38,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
ResourceConfig config = new ResourceConfig();
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResource.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResource.class);
|
|
}
|
|
|
|
@Test
|
|
@@ -67,7 +65,7 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
|
|
assertThat(target("exception-metered").request().get(String.class)).isEqualTo("fuh");
|
|
|
|
- assertThat(meter.getCount()).isZero();
|
|
+ assertThat(meter.getCount()).isEqualTo(0);
|
|
|
|
try {
|
|
target("exception-metered").queryParam("splode", true).request().get(String.class);
|
|
@@ -89,33 +87,33 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
final Meter meter5xx =
|
|
registry.meter(name(InstrumentedResource.class, "response5xxMetered", "5xx-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-2xx-metered").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter4xx.getCount()).isZero();
|
|
+ assertThat(meter4xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-4xx-metered").request().get().getStatus()).isEqualTo(400);
|
|
|
|
- assertThat(meter5xx.getCount()).isZero();
|
|
+ assertThat(meter5xx.getCount()).isEqualTo(0);
|
|
assertThat(target("response-5xx-metered").request().get().getStatus()).isEqualTo(500);
|
|
}
|
|
|
|
@Test
|
|
- public void responseMeteredMethodsAreMeteredWithCoarseLevel() {
|
|
+ void responseMeteredMethodsAreMeteredWithCoarseLevel() {
|
|
final Meter meter2xx =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredCoarse", "2xx-responses"));
|
|
final Meter meter200 =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredCoarse", "200-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
assertThat(target("response-metered-coarse").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter2xx.getCount()).isOne();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- public void responseMeteredMethodsAreMeteredWithDetailedLevel() {
|
|
+ void responseMeteredMethodsAreMeteredWithDetailedLevel() {
|
|
final Meter meter2xx =
|
|
registry.meter(
|
|
name(InstrumentedResource.class, "responseMeteredDetailed", "2xx-responses"));
|
|
@@ -126,9 +124,9 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
registry.meter(
|
|
name(InstrumentedResource.class, "responseMeteredDetailed", "201-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
- assertThat(meter201.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
+ assertThat(meter201.getCount()).isEqualTo(0);
|
|
assertThat(target("response-metered-detailed").request().get().getStatus()).isEqualTo(200);
|
|
assertThat(
|
|
target("response-metered-detailed")
|
|
@@ -138,28 +136,28 @@ class SingletonMetricsJerseyTest extends JerseyTest {
|
|
.getStatus())
|
|
.isEqualTo(201);
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
- assertThat(meter201.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
+ assertThat(meter201.getCount()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- public void responseMeteredMethodsAreMeteredWithAllLevel() {
|
|
+ void responseMeteredMethodsAreMeteredWithAllLevel() {
|
|
final Meter meter2xx =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredAll", "2xx-responses"));
|
|
final Meter meter200 =
|
|
registry.meter(name(InstrumentedResource.class, "responseMeteredAll", "200-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
assertThat(target("response-metered-all").request().get().getStatus()).isEqualTo(200);
|
|
|
|
- assertThat(meter2xx.getCount()).isOne();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- void testResourceNotFound() {
|
|
+ void resourceNotFound() {
|
|
final Response response = target().path("not-found").request().get();
|
|
assertThat(response.getStatus()).isEqualTo(404);
|
|
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsMeteredPerClassJerseyTest.java
|
|
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -32,9 +32,7 @@ class SingletonMetricsMeteredPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceMeteredPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceMeteredPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsResponseMeteredPerClassJerseyTest.java
|
|
@@ -2,7 +2,7 @@ package io.dropwizard.metrics5.jersey31;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -35,9 +35,7 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
config = config.register(InstrumentedResourceResponseMeteredPerClass.class);
|
|
- config = config.register(new TestExceptionMapper());
|
|
-
|
|
- return config;
|
|
+ return config.register(new TestExceptionMapper());
|
|
}
|
|
|
|
@Test
|
|
@@ -140,13 +138,13 @@ class SingletonMetricsResponseMeteredPerClassJerseyTest extends JerseyTest {
|
|
"responseMeteredPerClass",
|
|
"200-responses"));
|
|
|
|
- assertThat(meter2xx.getCount()).isZero();
|
|
- assertThat(meter200.getCount()).isZero();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(0);
|
|
+ assertThat(meter200.getCount()).isEqualTo(0);
|
|
|
|
assertThat(target("subresource/responseMeteredPerClass").request().get().getStatus())
|
|
.isEqualTo(200);
|
|
|
|
- assertThat(meter2xx.getCount()).isOne();
|
|
- assertThat(meter200.getCount()).isOne();
|
|
+ assertThat(meter2xx.getCount()).isEqualTo(1);
|
|
+ assertThat(meter200.getCount()).isEqualTo(1);
|
|
}
|
|
}
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsTimedPerClassJerseyTest.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/SingletonMetricsTimedPerClassJerseyTest.java
|
|
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
|
|
* Tests registering {@link InstrumentedResourceMethodApplicationListener} as a singleton in a
|
|
* Jersey {@link ResourceConfig}
|
|
*/
|
|
-class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
+final class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
static {
|
|
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
|
|
}
|
|
@@ -32,9 +32,7 @@ class SingletonMetricsTimedPerClassJerseyTest extends JerseyTest {
|
|
ResourceConfig config = new ResourceConfig();
|
|
|
|
config = config.register(new MetricsFeature(this.registry));
|
|
- config = config.register(InstrumentedResourceTimedPerClass.class);
|
|
-
|
|
- return config;
|
|
+ return config.register(InstrumentedResourceTimedPerClass.class);
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedFilteredResource.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedFilteredResource.java
|
|
@@ -18,24 +18,24 @@ public class InstrumentedFilteredResource {
|
|
}
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick++;
|
|
return "yay";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "fancyName")
|
|
@Path("/named")
|
|
+ @Timed(name = "fancyName")
|
|
public String named() {
|
|
testClock.tick++;
|
|
return "fancy";
|
|
}
|
|
|
|
@GET
|
|
- @Timed(name = "absolutelyFancy", absolute = true)
|
|
@Path("/absolute")
|
|
+ @Timed(name = "absolutelyFancy", absolute = true)
|
|
public String absolute() {
|
|
testClock.tick++;
|
|
return "absolute";
|
|
@@ -50,8 +50,8 @@ public class InstrumentedFilteredResource {
|
|
public class InstrumentedFilteredSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
testClock.tick += 2;
|
|
return "yay";
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedResource.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedResource.java
|
|
@@ -21,8 +21,8 @@ import java.io.IOException;
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
public class InstrumentedResource {
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
@@ -34,8 +34,8 @@ public class InstrumentedResource {
|
|
return "woo";
|
|
}
|
|
|
|
- @GET
|
|
@ExceptionMetered(cause = IOException.class)
|
|
+ @GET
|
|
@Path("/exception-metered")
|
|
public String exceptionMetered(@QueryParam("splode") @DefaultValue("false") boolean splode)
|
|
throws IOException {
|
|
@@ -46,46 +46,46 @@ public class InstrumentedResource {
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = DETAILED)
|
|
@Path("/response-metered-detailed")
|
|
+ @ResponseMetered(level = DETAILED)
|
|
public Response responseMeteredDetailed(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = COARSE)
|
|
@Path("/response-metered-coarse")
|
|
+ @ResponseMetered(level = COARSE)
|
|
public Response responseMeteredCoarse(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered(level = ALL)
|
|
@Path("/response-metered-all")
|
|
+ @ResponseMetered(level = ALL)
|
|
public Response responseMeteredAll(
|
|
@QueryParam("status_code") @DefaultValue("200") int statusCode) {
|
|
return Response.status(Response.Status.fromStatusCode(statusCode)).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-2xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response2xxMetered() {
|
|
return Response.ok().build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-4xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response4xxMetered() {
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
}
|
|
|
|
@GET
|
|
- @ResponseMetered
|
|
@Path("/response-5xx-metered")
|
|
+ @ResponseMetered
|
|
public Response response5xxMetered() {
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
}
|
|
--- a/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedSubResource.java
|
|
+++ b/metrics-jersey31/src/test/java/io/dropwizard/metrics5/jersey31/resources/InstrumentedSubResource.java
|
|
@@ -10,8 +10,8 @@ import jakarta.ws.rs.core.MediaType;
|
|
public class InstrumentedSubResource {
|
|
|
|
@GET
|
|
- @Timed
|
|
@Path("/timed")
|
|
+ @Timed
|
|
public String timed() {
|
|
return "yay";
|
|
}
|
|
--- a/metrics-jetty10/src/main/java/io/dropwizard/metrics5/jetty10/InstrumentedHandler.java
|
|
+++ b/metrics-jetty10/src/main/java/io/dropwizard/metrics5/jetty10/InstrumentedHandler.java
|
|
@@ -4,7 +4,10 @@ import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -14,7 +17,6 @@ import io.dropwizard.metrics5.Timer;
|
|
import io.dropwizard.metrics5.annotation.ResponseMeteredLevel;
|
|
import java.io.IOException;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -173,7 +175,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
this.responseCodeMeters =
|
|
DETAILED_METER_LEVELS.contains(responseMeteredLevel)
|
|
? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ : ImmutableMap.of();
|
|
|
|
this.getRequests = metricRegistry.timer(prefix.resolve(NAME_GET_REQUESTS));
|
|
this.postRequests = metricRegistry.timer(prefix.resolve(NAME_POST_REQUESTS));
|
|
@@ -188,7 +190,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
|
|
if (COARSE_METER_LEVELS.contains(responseMeteredLevel)) {
|
|
this.responses =
|
|
- Collections.unmodifiableList(
|
|
+ unmodifiableList(
|
|
Arrays.asList(
|
|
metricRegistry.meter(prefix.resolve(NAME_1XX_RESPONSES)), // 1xx
|
|
metricRegistry.meter(prefix.resolve(NAME_2XX_RESPONSES)), // 2xx
|
|
@@ -253,7 +255,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
}
|
|
});
|
|
} else {
|
|
- this.responses = Collections.emptyList();
|
|
+ this.responses = ImmutableList.of();
|
|
}
|
|
|
|
this.listener = new AsyncAttachingListener();
|
|
--- a/metrics-jetty10/src/main/java/io/dropwizard/metrics5/jetty10/InstrumentedHttpChannelListener.java
|
|
+++ b/metrics-jetty10/src/main/java/io/dropwizard/metrics5/jetty10/InstrumentedHttpChannelListener.java
|
|
@@ -3,7 +3,10 @@ package io.dropwizard.metrics5.jetty10;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -14,7 +17,6 @@ import io.dropwizard.metrics5.annotation.ResponseMeteredLevel;
|
|
import java.io.IOException;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -132,10 +134,10 @@ public class InstrumentedHttpChannelListener implements Listener {
|
|
this.responseCodeMeters =
|
|
DETAILED_METER_LEVELS.contains(responseMeteredLevel)
|
|
? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ : ImmutableMap.of();
|
|
this.responses =
|
|
COARSE_METER_LEVELS.contains(responseMeteredLevel)
|
|
- ? Collections.unmodifiableList(
|
|
+ ? unmodifiableList(
|
|
Arrays.asList(
|
|
registry.meter(prefix.resolve("1xx-responses")), // 1xx
|
|
registry.meter(prefix.resolve("2xx-responses")), // 2xx
|
|
@@ -143,7 +145,7 @@ public class InstrumentedHttpChannelListener implements Listener {
|
|
registry.meter(prefix.resolve("4xx-responses")), // 4xx
|
|
registry.meter(prefix.resolve("5xx-responses")) // 5xx
|
|
))
|
|
- : Collections.emptyList();
|
|
+ : ImmutableList.of();
|
|
|
|
this.getRequests = metricRegistry.timer(prefix.resolve("get-requests"));
|
|
this.postRequests = metricRegistry.timer(prefix.resolve("post-requests"));
|
|
--- a/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedConnectionFactoryTest.java
|
|
+++ b/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedConnectionFactoryTest.java
|
|
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedConnectionFactoryTest {
|
|
+final class InstrumentedConnectionFactoryTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
private final ServerConnector connector =
|
|
--- a/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedHandlerTest.java
|
|
+++ b/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedHandlerTest.java
|
|
@@ -3,13 +3,13 @@ package io.dropwizard.metrics5.jetty10;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.util.concurrent.TimeUnit;
|
|
import javax.servlet.AsyncContext;
|
|
import javax.servlet.ServletException;
|
|
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHandlerTest {
|
|
+final class InstrumentedHandlerTest {
|
|
private final HttpClient client = new HttpClient();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
@@ -118,7 +118,7 @@ class InstrumentedHandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
+ void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
InstrumentedHandler handler = new InstrumentedHandler(registry, "coarse", COARSE);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -128,7 +128,7 @@ class InstrumentedHandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
+ void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
InstrumentedHandler handler = new InstrumentedHandler(registry, "detailed", DETAILED);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -137,8 +137,8 @@ class InstrumentedHandlerTest {
|
|
.doesNotContainKey(MetricName.build("detailed", "handler", "percent-4xx-1m"));
|
|
}
|
|
|
|
- @Test
|
|
@Disabled("flaky on virtual machines")
|
|
+ @Test
|
|
void responseTimesAreRecordedForAsyncResponses() throws Exception {
|
|
|
|
final ContentResponse response = client.GET(uri("/async"));
|
|
@@ -150,7 +150,7 @@ class InstrumentedHandlerTest {
|
|
|
|
private void assertResponseTimesValid() {
|
|
assertThat(registry.getMeters().get(metricName().resolve("200-responses")).getCount())
|
|
- .isGreaterThan(0L);
|
|
+ .isPositive();
|
|
|
|
assertThat(
|
|
registry
|
|
@@ -158,11 +158,11 @@ class InstrumentedHandlerTest {
|
|
.get(metricName().resolve("get-requests"))
|
|
.getSnapshot()
|
|
.getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
|
|
assertThat(registry.getTimers().get(metricName().resolve("requests")).getSnapshot().getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
}
|
|
|
|
@@ -225,7 +225,7 @@ class InstrumentedHandlerTest {
|
|
@Override
|
|
public void onWritePossible() throws IOException {
|
|
servletOutputStream.write(
|
|
- "some content from the async\n".getBytes(StandardCharsets.UTF_8));
|
|
+ "some content from the async\n".getBytes(UTF_8));
|
|
context.complete();
|
|
}
|
|
|
|
--- a/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedHttpChannelListenerTest.java
|
|
+++ b/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedHttpChannelListenerTest.java
|
|
@@ -1,12 +1,12 @@
|
|
package io.dropwizard.metrics5.jetty10;
|
|
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import javax.servlet.AsyncContext;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.WriteListener;
|
|
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHttpChannelListenerTest {
|
|
+final class InstrumentedHttpChannelListenerTest {
|
|
private final HttpClient client = new HttpClient();
|
|
private final Server server = new Server();
|
|
private final ServerConnector connector = new ServerConnector(server);
|
|
@@ -188,7 +188,7 @@ class InstrumentedHttpChannelListenerTest {
|
|
@Override
|
|
public void onWritePossible() throws IOException {
|
|
servletOutputStream.write(
|
|
- "some content from the async".getBytes(StandardCharsets.UTF_8));
|
|
+ "some content from the async".getBytes(UTF_8));
|
|
context.complete();
|
|
}
|
|
|
|
--- a/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedQueuedThreadPoolTest.java
|
|
+++ b/metrics-jetty10/src/test/java/io/dropwizard/metrics5/jetty10/InstrumentedQueuedThreadPoolTest.java
|
|
@@ -8,7 +8,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedQueuedThreadPoolTest {
|
|
+final class InstrumentedQueuedThreadPoolTest {
|
|
private static final String PREFIX = "prefix";
|
|
|
|
private MetricRegistry metricRegistry;
|
|
--- a/metrics-jetty11/src/main/java/io/dropwizard/metrics5/jetty11/InstrumentedHandler.java
|
|
+++ b/metrics-jetty11/src/main/java/io/dropwizard/metrics5/jetty11/InstrumentedHandler.java
|
|
@@ -4,7 +4,10 @@ import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -19,7 +22,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -173,7 +175,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
this.responseCodeMeters =
|
|
DETAILED_METER_LEVELS.contains(responseMeteredLevel)
|
|
? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ : ImmutableMap.of();
|
|
|
|
this.getRequests = metricRegistry.timer(prefix.resolve(NAME_GET_REQUESTS));
|
|
this.postRequests = metricRegistry.timer(prefix.resolve(NAME_POST_REQUESTS));
|
|
@@ -188,7 +190,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
|
|
if (COARSE_METER_LEVELS.contains(responseMeteredLevel)) {
|
|
this.responses =
|
|
- Collections.unmodifiableList(
|
|
+ unmodifiableList(
|
|
Arrays.asList(
|
|
metricRegistry.meter(prefix.resolve(NAME_1XX_RESPONSES)), // 1xx
|
|
metricRegistry.meter(prefix.resolve(NAME_2XX_RESPONSES)), // 2xx
|
|
@@ -253,7 +255,7 @@ public class InstrumentedHandler extends HandlerWrapper {
|
|
}
|
|
});
|
|
} else {
|
|
- this.responses = Collections.emptyList();
|
|
+ this.responses = ImmutableList.of();
|
|
}
|
|
|
|
this.listener = new AsyncAttachingListener();
|
|
--- a/metrics-jetty11/src/main/java/io/dropwizard/metrics5/jetty11/InstrumentedHttpChannelListener.java
|
|
+++ b/metrics-jetty11/src/main/java/io/dropwizard/metrics5/jetty11/InstrumentedHttpChannelListener.java
|
|
@@ -3,7 +3,10 @@ package io.dropwizard.metrics5.jetty11;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -18,7 +21,6 @@ import jakarta.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -132,10 +134,10 @@ public class InstrumentedHttpChannelListener implements Listener {
|
|
this.responseCodeMeters =
|
|
DETAILED_METER_LEVELS.contains(responseMeteredLevel)
|
|
? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ : ImmutableMap.of();
|
|
this.responses =
|
|
COARSE_METER_LEVELS.contains(responseMeteredLevel)
|
|
- ? Collections.unmodifiableList(
|
|
+ ? unmodifiableList(
|
|
Arrays.asList(
|
|
registry.meter(prefix.resolve("1xx-responses")), // 1xx
|
|
registry.meter(prefix.resolve("2xx-responses")), // 2xx
|
|
@@ -143,7 +145,7 @@ public class InstrumentedHttpChannelListener implements Listener {
|
|
registry.meter(prefix.resolve("4xx-responses")), // 4xx
|
|
registry.meter(prefix.resolve("5xx-responses")) // 5xx
|
|
))
|
|
- : Collections.emptyList();
|
|
+ : ImmutableList.of();
|
|
|
|
this.getRequests = metricRegistry.timer(prefix.resolve("get-requests"));
|
|
this.postRequests = metricRegistry.timer(prefix.resolve("post-requests"));
|
|
--- a/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedConnectionFactoryTest.java
|
|
+++ b/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedConnectionFactoryTest.java
|
|
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedConnectionFactoryTest {
|
|
+final class InstrumentedConnectionFactoryTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
private final ServerConnector connector =
|
|
--- a/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedHandlerTest.java
|
|
+++ b/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedHandlerTest.java
|
|
@@ -3,6 +3,7 @@ package io.dropwizard.metrics5.jetty11;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
|
|
|
|
@@ -15,7 +16,6 @@ import jakarta.servlet.WriteListener;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.eclipse.jetty.client.HttpClient;
|
|
import org.eclipse.jetty.client.api.ContentResponse;
|
|
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHandlerTest {
|
|
+final class InstrumentedHandlerTest {
|
|
private final HttpClient client = new HttpClient();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
@@ -118,7 +118,7 @@ class InstrumentedHandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
+ void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
InstrumentedHandler handler = new InstrumentedHandler(registry, "coarse", COARSE);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -128,7 +128,7 @@ class InstrumentedHandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
+ void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
InstrumentedHandler handler = new InstrumentedHandler(registry, "detailed", DETAILED);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -137,8 +137,8 @@ class InstrumentedHandlerTest {
|
|
.doesNotContainKey(MetricName.build("detailed", "handler", "percent-4xx-1m"));
|
|
}
|
|
|
|
- @Test
|
|
@Disabled("flaky on virtual machines")
|
|
+ @Test
|
|
void responseTimesAreRecordedForAsyncResponses() throws Exception {
|
|
|
|
final ContentResponse response = client.GET(uri("/async"));
|
|
@@ -150,7 +150,7 @@ class InstrumentedHandlerTest {
|
|
|
|
private void assertResponseTimesValid() {
|
|
assertThat(registry.getMeters().get(metricName().resolve("200-responses")).getCount())
|
|
- .isGreaterThan(0L);
|
|
+ .isPositive();
|
|
|
|
assertThat(
|
|
registry
|
|
@@ -158,11 +158,11 @@ class InstrumentedHandlerTest {
|
|
.get(metricName().resolve("get-requests"))
|
|
.getSnapshot()
|
|
.getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
|
|
assertThat(registry.getTimers().get(metricName().resolve("requests")).getSnapshot().getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
}
|
|
|
|
@@ -225,7 +225,7 @@ class InstrumentedHandlerTest {
|
|
@Override
|
|
public void onWritePossible() throws IOException {
|
|
servletOutputStream.write(
|
|
- "some content from the async\n".getBytes(StandardCharsets.UTF_8));
|
|
+ "some content from the async\n".getBytes(UTF_8));
|
|
context.complete();
|
|
}
|
|
|
|
--- a/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedHttpChannelListenerTest.java
|
|
+++ b/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedHttpChannelListenerTest.java
|
|
@@ -1,6 +1,7 @@
|
|
package io.dropwizard.metrics5.jetty11;
|
|
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -11,7 +12,6 @@ import jakarta.servlet.WriteListener;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import org.eclipse.jetty.client.HttpClient;
|
|
import org.eclipse.jetty.client.api.ContentResponse;
|
|
import org.eclipse.jetty.server.Request;
|
|
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedHttpChannelListenerTest {
|
|
+final class InstrumentedHttpChannelListenerTest {
|
|
private final HttpClient client = new HttpClient();
|
|
private final Server server = new Server();
|
|
private final ServerConnector connector = new ServerConnector(server);
|
|
@@ -188,7 +188,7 @@ class InstrumentedHttpChannelListenerTest {
|
|
@Override
|
|
public void onWritePossible() throws IOException {
|
|
servletOutputStream.write(
|
|
- "some content from the async".getBytes(StandardCharsets.UTF_8));
|
|
+ "some content from the async".getBytes(UTF_8));
|
|
context.complete();
|
|
}
|
|
|
|
--- a/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedQueuedThreadPoolTest.java
|
|
+++ b/metrics-jetty11/src/test/java/io/dropwizard/metrics5/jetty11/InstrumentedQueuedThreadPoolTest.java
|
|
@@ -8,7 +8,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedQueuedThreadPoolTest {
|
|
+final class InstrumentedQueuedThreadPoolTest {
|
|
private static final String PREFIX = "prefix";
|
|
|
|
private MetricRegistry metricRegistry;
|
|
--- a/metrics-jetty12-ee10/src/test/java/io/dropwizard/metrics/jetty12/ee10/InstrumentedEE10HandlerTest.java
|
|
+++ b/metrics-jetty12-ee10/src/test/java/io/dropwizard/metrics/jetty12/ee10/InstrumentedEE10HandlerTest.java
|
|
@@ -3,6 +3,7 @@ package io.dropwizard.metrics.jetty12.ee10;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
|
|
|
@@ -14,7 +15,6 @@ import jakarta.servlet.WriteListener;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.eclipse.jetty.client.ContentResponse;
|
|
import org.eclipse.jetty.client.HttpClient;
|
|
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedEE10HandlerTest {
|
|
+final class InstrumentedEE10HandlerTest {
|
|
private final HttpClient client = new HttpClient();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
@@ -40,7 +40,7 @@ public class InstrumentedEE10HandlerTest {
|
|
private final InstrumentedEE10Handler handler = new InstrumentedEE10Handler(registry, null, ALL);
|
|
|
|
@BeforeEach
|
|
- public void setUp() throws Exception {
|
|
+ void setUp() throws Exception {
|
|
handler.setName("handler");
|
|
|
|
TestHandler testHandler = new TestHandler();
|
|
@@ -62,18 +62,18 @@ public class InstrumentedEE10HandlerTest {
|
|
}
|
|
|
|
@AfterEach
|
|
- public void tearDown() throws Exception {
|
|
+ void tearDown() throws Exception {
|
|
server.stop();
|
|
client.stop();
|
|
}
|
|
|
|
@Test
|
|
- public void hasAName() throws Exception {
|
|
+ void hasAName() throws Exception {
|
|
assertThat(handler.getName()).isEqualTo("handler");
|
|
}
|
|
|
|
@Test
|
|
- public void createsAndRemovesMetricsForTheHandler() throws Exception {
|
|
+ void createsAndRemovesMetricsForTheHandler() throws Exception {
|
|
final ContentResponse response = client.GET(uri("/hello"));
|
|
|
|
assertThat(response.getStatus()).isEqualTo(404);
|
|
@@ -115,9 +115,9 @@ public class InstrumentedEE10HandlerTest {
|
|
assertThat(registry.getNames()).isEmpty();
|
|
}
|
|
|
|
- @Test
|
|
@Disabled("flaky on virtual machines")
|
|
- public void responseTimesAreRecordedForBlockingResponses() throws Exception {
|
|
+ @Test
|
|
+ void responseTimesAreRecordedForBlockingResponses() throws Exception {
|
|
|
|
final ContentResponse response = client.GET(uri("/blocking"));
|
|
|
|
@@ -127,7 +127,7 @@ public class InstrumentedEE10HandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void doStopDoesNotThrowNPE() throws Exception {
|
|
+ void doStopDoesNotThrowNPE() throws Exception {
|
|
InstrumentedEE10Handler handler = new InstrumentedEE10Handler(registry, null, ALL);
|
|
handler.setHandler(new TestHandler());
|
|
|
|
@@ -135,7 +135,7 @@ public class InstrumentedEE10HandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
+ void gaugesAreRegisteredWithResponseMeteredLevelCoarse() throws Exception {
|
|
InstrumentedEE10Handler handler = new InstrumentedEE10Handler(registry, "coarse", COARSE);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -145,7 +145,7 @@ public class InstrumentedEE10HandlerTest {
|
|
}
|
|
|
|
@Test
|
|
- public void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
+ void gaugesAreNotRegisteredWithResponseMeteredLevelDetailed() throws Exception {
|
|
InstrumentedEE10Handler handler = new InstrumentedEE10Handler(registry, "detailed", DETAILED);
|
|
handler.setHandler(new TestHandler());
|
|
handler.setName("handler");
|
|
@@ -154,9 +154,9 @@ public class InstrumentedEE10HandlerTest {
|
|
.doesNotContainKey(MetricName.build("detailed", "handler", "percent-4xx-1m"));
|
|
}
|
|
|
|
- @Test
|
|
@Disabled("flaky on virtual machines")
|
|
- public void responseTimesAreRecordedForAsyncResponses() throws Exception {
|
|
+ @Test
|
|
+ void responseTimesAreRecordedForAsyncResponses() throws Exception {
|
|
|
|
final ContentResponse response = client.GET(uri("/async"));
|
|
|
|
@@ -167,9 +167,9 @@ public class InstrumentedEE10HandlerTest {
|
|
|
|
private void assertResponseTimesValid() {
|
|
assertThat(registry.getMeters().get(metricName().resolve("2xx-responses")).getCount())
|
|
- .isGreaterThan(0L);
|
|
+ .isPositive();
|
|
assertThat(registry.getMeters().get(metricName().resolve(".200-responses")).getCount())
|
|
- .isGreaterThan(0L);
|
|
+ .isPositive();
|
|
|
|
assertThat(
|
|
registry
|
|
@@ -177,12 +177,12 @@ public class InstrumentedEE10HandlerTest {
|
|
.get(metricName().resolve(".get-requests"))
|
|
.getSnapshot()
|
|
.getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
|
|
assertThat(
|
|
registry.getTimers().get(metricName().resolve(".requests")).getSnapshot().getMedian())
|
|
- .isGreaterThan(0.0)
|
|
+ .isPositive()
|
|
.isLessThan(TimeUnit.SECONDS.toNanos(1));
|
|
}
|
|
|
|
@@ -250,7 +250,7 @@ public class InstrumentedEE10HandlerTest {
|
|
@Override
|
|
public void onWritePossible() throws IOException {
|
|
servletOutputStream.write(
|
|
- "some content from the async\n".getBytes(StandardCharsets.UTF_8));
|
|
+ "some content from the async\n".getBytes(UTF_8));
|
|
context.complete();
|
|
servletContextRequest.getServletChannel().handle();
|
|
}
|
|
--- a/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/AbstractInstrumentedHandler.java
|
|
+++ b/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/AbstractInstrumentedHandler.java
|
|
@@ -4,7 +4,10 @@ import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.ALL;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.COARSE;
|
|
import static io.dropwizard.metrics5.annotation.ResponseMeteredLevel.DETAILED;
|
|
+import static java.util.Collections.unmodifiableList;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -13,7 +16,6 @@ import io.dropwizard.metrics5.RatioGauge;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import io.dropwizard.metrics5.annotation.ResponseMeteredLevel;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -164,7 +166,7 @@ public abstract class AbstractInstrumentedHandler extends Handler.Wrapper {
|
|
this.responseCodeMeters =
|
|
DETAILED_METER_LEVELS.contains(responseMeteredLevel)
|
|
? new ConcurrentHashMap<>()
|
|
- : Collections.emptyMap();
|
|
+ : ImmutableMap.of();
|
|
|
|
this.getRequests = metricRegistry.timer(prefix.resolve(NAME_GET_REQUESTS));
|
|
this.postRequests = metricRegistry.timer(prefix.resolve(NAME_POST_REQUESTS));
|
|
@@ -179,7 +181,7 @@ public abstract class AbstractInstrumentedHandler extends Handler.Wrapper {
|
|
|
|
if (COARSE_METER_LEVELS.contains(responseMeteredLevel)) {
|
|
this.responses =
|
|
- Collections.unmodifiableList(
|
|
+ unmodifiableList(
|
|
Arrays.asList(
|
|
metricRegistry.meter(prefix.resolve(NAME_1XX_RESPONSES)), // 1xx
|
|
metricRegistry.meter(prefix.resolve(NAME_2XX_RESPONSES)), // 2xx
|
|
@@ -244,7 +246,7 @@ public abstract class AbstractInstrumentedHandler extends Handler.Wrapper {
|
|
}
|
|
});
|
|
} else {
|
|
- this.responses = Collections.emptyList();
|
|
+ this.responses = ImmutableList.of();
|
|
}
|
|
}
|
|
|
|
--- a/metrics-jetty12/src/test/java/io/dropwizard/metrics/jetty12/InstrumentedConnectionFactoryTest.java
|
|
+++ b/metrics-jetty12/src/test/java/io/dropwizard/metrics/jetty12/InstrumentedConnectionFactoryTest.java
|
|
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedConnectionFactoryTest {
|
|
+final class InstrumentedConnectionFactoryTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final Server server = new Server();
|
|
private final ServerConnector connector =
|
|
@@ -32,7 +32,7 @@ public class InstrumentedConnectionFactoryTest {
|
|
private final HttpClient client = new HttpClient();
|
|
|
|
@BeforeEach
|
|
- public void setUp() throws Exception {
|
|
+ void setUp() throws Exception {
|
|
server.setHandler(
|
|
new Handler.Abstract() {
|
|
@Override
|
|
@@ -50,13 +50,13 @@ public class InstrumentedConnectionFactoryTest {
|
|
}
|
|
|
|
@AfterEach
|
|
- public void tearDown() throws Exception {
|
|
+ void tearDown() throws Exception {
|
|
server.stop();
|
|
client.stop();
|
|
}
|
|
|
|
@Test
|
|
- public void instrumentsConnectionTimes() throws Exception {
|
|
+ void instrumentsConnectionTimes() throws Exception {
|
|
final ContentResponse response =
|
|
client.GET("http://localhost:" + connector.getLocalPort() + "/hello");
|
|
assertThat(response.getStatus()).isEqualTo(200);
|
|
@@ -70,7 +70,7 @@ public class InstrumentedConnectionFactoryTest {
|
|
}
|
|
|
|
@Test
|
|
- public void instrumentsActiveConnections() throws Exception {
|
|
+ void instrumentsActiveConnections() throws Exception {
|
|
final Counter counter = registry.counter("http.active-connections");
|
|
|
|
final ContentResponse response =
|
|
--- a/metrics-jetty12/src/test/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPoolTest.java
|
|
+++ b/metrics-jetty12/src/test/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPoolTest.java
|
|
@@ -7,20 +7,20 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedQueuedThreadPoolTest {
|
|
+final class InstrumentedQueuedThreadPoolTest {
|
|
private static final String PREFIX = "prefix";
|
|
|
|
private MetricRegistry metricRegistry;
|
|
private InstrumentedQueuedThreadPool iqtp;
|
|
|
|
@BeforeEach
|
|
- public void setUp() {
|
|
+ void setUp() {
|
|
metricRegistry = new MetricRegistry();
|
|
iqtp = new InstrumentedQueuedThreadPool(metricRegistry);
|
|
}
|
|
|
|
@Test
|
|
- public void customMetricsPrefix() throws Exception {
|
|
+ void customMetricsPrefix() throws Exception {
|
|
iqtp.setPrefix(PREFIX);
|
|
iqtp.start();
|
|
|
|
@@ -35,7 +35,7 @@ public class InstrumentedQueuedThreadPoolTest {
|
|
}
|
|
|
|
@Test
|
|
- public void metricsPrefixBackwardCompatible() throws Exception {
|
|
+ void metricsPrefixBackwardCompatible() throws Exception {
|
|
iqtp.start();
|
|
assertThat(metricRegistry.getNames())
|
|
.overridingErrorMessage("The default metrics prefix was changed")
|
|
--- a/metrics-jmx/src/main/java/io/dropwizard/metrics5/jmx/DefaultObjectNameFactory.java
|
|
+++ b/metrics-jmx/src/main/java/io/dropwizard/metrics5/jmx/DefaultObjectNameFactory.java
|
|
@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
|
public class DefaultObjectNameFactory implements ObjectNameFactory {
|
|
|
|
private static final char[] QUOTABLE_CHARS = new char[] {',', '=', ':', '"'};
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(JmxReporter.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultObjectNameFactory.class);
|
|
|
|
@Override
|
|
public ObjectName createName(String type, String domain, MetricName name) {
|
|
@@ -38,14 +38,13 @@ public class DefaultObjectNameFactory implements ObjectNameFactory {
|
|
|| shouldQuote(objectName.getKeyProperty("type"))) {
|
|
properties.put("type", ObjectName.quote(type));
|
|
}
|
|
- objectName = new ObjectName(domain, properties);
|
|
+ return new ObjectName(domain, properties);
|
|
|
|
- return objectName;
|
|
} catch (MalformedObjectNameException e) {
|
|
try {
|
|
return new ObjectName(domain, "name", ObjectName.quote(name.getKey()));
|
|
} catch (MalformedObjectNameException e1) {
|
|
- LOGGER.warn("Unable to register {} {}", type, name, e1);
|
|
+ LOG.warn("Unable to register {} {}", type, name, e1);
|
|
throw new RuntimeException(e1);
|
|
}
|
|
}
|
|
--- a/metrics-jmx/src/main/java/io/dropwizard/metrics5/jmx/JmxReporter.java
|
|
+++ b/metrics-jmx/src/main/java/io/dropwizard/metrics5/jmx/JmxReporter.java
|
|
@@ -1,5 +1,9 @@
|
|
package io.dropwizard.metrics5.jmx;
|
|
|
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.Histogram;
|
|
@@ -13,7 +17,6 @@ import io.dropwizard.metrics5.Reporter;
|
|
import io.dropwizard.metrics5.Timer;
|
|
import java.io.Closeable;
|
|
import java.lang.management.ManagementFactory;
|
|
-import java.util.Collections;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
@@ -61,8 +64,8 @@ public class JmxReporter implements Reporter, Closeable {
|
|
this.durationUnit = TimeUnit.MILLISECONDS;
|
|
this.domain = "metrics";
|
|
this.objectNameFactory = new DefaultObjectNameFactory();
|
|
- this.specificDurationUnits = Collections.emptyMap();
|
|
- this.specificRateUnits = Collections.emptyMap();
|
|
+ this.specificDurationUnits = ImmutableMap.of();
|
|
+ this.specificRateUnits = ImmutableMap.of();
|
|
}
|
|
|
|
/**
|
|
@@ -88,9 +91,7 @@ public class JmxReporter implements Reporter, Closeable {
|
|
}
|
|
|
|
public Builder createsObjectNamesWith(ObjectNameFactory onFactory) {
|
|
- if (onFactory == null) {
|
|
- throw new IllegalArgumentException("null objectNameFactory");
|
|
- }
|
|
+ checkArgument(onFactory != null, "null objectNameFactory");
|
|
this.objectNameFactory = onFactory;
|
|
return this;
|
|
}
|
|
@@ -129,7 +130,7 @@ public class JmxReporter implements Reporter, Closeable {
|
|
* @return {@code this}
|
|
*/
|
|
public Builder specificDurationUnits(Map<String, TimeUnit> specificDurationUnits) {
|
|
- this.specificDurationUnits = Collections.unmodifiableMap(specificDurationUnits);
|
|
+ this.specificDurationUnits = unmodifiableMap(specificDurationUnits);
|
|
return this;
|
|
}
|
|
|
|
@@ -140,7 +141,7 @@ public class JmxReporter implements Reporter, Closeable {
|
|
* @return {@code this}
|
|
*/
|
|
public Builder specificRateUnits(Map<String, TimeUnit> specificRateUnits) {
|
|
- this.specificRateUnits = Collections.unmodifiableMap(specificRateUnits);
|
|
+ this.specificRateUnits = unmodifiableMap(specificRateUnits);
|
|
return this;
|
|
}
|
|
|
|
@@ -159,7 +160,7 @@ public class JmxReporter implements Reporter, Closeable {
|
|
}
|
|
}
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(JmxReporter.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(JmxReporter.class);
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
public interface MetricMBean {
|
|
@@ -570,9 +571,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
registerMBean(new JmxGauge(gauge, objectName), objectName);
|
|
}
|
|
} catch (InstanceAlreadyExistsException e) {
|
|
- LOGGER.debug("Unable to register gauge", e);
|
|
+ LOG.debug("Unable to register gauge", e);
|
|
} catch (JMException e) {
|
|
- LOGGER.warn("Unable to register gauge", e);
|
|
+ LOG.warn("Unable to register gauge", e);
|
|
}
|
|
}
|
|
|
|
@@ -582,9 +583,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
final ObjectName objectName = createName("gauges", name);
|
|
unregisterMBean(objectName);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister gauge", e);
|
|
+ LOG.debug("Unable to unregister gauge", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister gauge", e);
|
|
+ LOG.warn("Unable to unregister gauge", e);
|
|
}
|
|
}
|
|
|
|
@@ -596,9 +597,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
registerMBean(new JmxCounter(counter, objectName), objectName);
|
|
}
|
|
} catch (InstanceAlreadyExistsException e) {
|
|
- LOGGER.debug("Unable to register counter", e);
|
|
+ LOG.debug("Unable to register counter", e);
|
|
} catch (JMException e) {
|
|
- LOGGER.warn("Unable to register counter", e);
|
|
+ LOG.warn("Unable to register counter", e);
|
|
}
|
|
}
|
|
|
|
@@ -608,9 +609,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
final ObjectName objectName = createName("counters", name);
|
|
unregisterMBean(objectName);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister counter", e);
|
|
+ LOG.debug("Unable to unregister counter", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister counter", e);
|
|
+ LOG.warn("Unable to unregister counter", e);
|
|
}
|
|
}
|
|
|
|
@@ -622,9 +623,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
registerMBean(new JmxHistogram(histogram, objectName), objectName);
|
|
}
|
|
} catch (InstanceAlreadyExistsException e) {
|
|
- LOGGER.debug("Unable to register histogram", e);
|
|
+ LOG.debug("Unable to register histogram", e);
|
|
} catch (JMException e) {
|
|
- LOGGER.warn("Unable to register histogram", e);
|
|
+ LOG.warn("Unable to register histogram", e);
|
|
}
|
|
}
|
|
|
|
@@ -634,9 +635,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
final ObjectName objectName = createName("histograms", name);
|
|
unregisterMBean(objectName);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister histogram", e);
|
|
+ LOG.debug("Unable to unregister histogram", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister histogram", e);
|
|
+ LOG.warn("Unable to unregister histogram", e);
|
|
}
|
|
}
|
|
|
|
@@ -649,9 +650,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
new JmxMeter(meter, objectName, timeUnits.rateFor(name.getKey())), objectName);
|
|
}
|
|
} catch (InstanceAlreadyExistsException e) {
|
|
- LOGGER.debug("Unable to register meter", e);
|
|
+ LOG.debug("Unable to register meter", e);
|
|
} catch (JMException e) {
|
|
- LOGGER.warn("Unable to register meter", e);
|
|
+ LOG.warn("Unable to register meter", e);
|
|
}
|
|
}
|
|
|
|
@@ -661,9 +662,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
final ObjectName objectName = createName("meters", name);
|
|
unregisterMBean(objectName);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister meter", e);
|
|
+ LOG.debug("Unable to unregister meter", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister meter", e);
|
|
+ LOG.warn("Unable to unregister meter", e);
|
|
}
|
|
}
|
|
|
|
@@ -681,9 +682,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
objectName);
|
|
}
|
|
} catch (InstanceAlreadyExistsException e) {
|
|
- LOGGER.debug("Unable to register timer", e);
|
|
+ LOG.debug("Unable to register timer", e);
|
|
} catch (JMException e) {
|
|
- LOGGER.warn("Unable to register timer", e);
|
|
+ LOG.warn("Unable to register timer", e);
|
|
}
|
|
}
|
|
|
|
@@ -693,9 +694,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
final ObjectName objectName = createName("timers", name);
|
|
unregisterMBean(objectName);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister timer", e);
|
|
+ LOG.debug("Unable to unregister timer", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister timer", e);
|
|
+ LOG.warn("Unable to unregister timer", e);
|
|
}
|
|
}
|
|
|
|
@@ -708,9 +709,9 @@ public class JmxReporter implements Reporter, Closeable {
|
|
try {
|
|
unregisterMBean(name);
|
|
} catch (InstanceNotFoundException e) {
|
|
- LOGGER.debug("Unable to unregister metric", e);
|
|
+ LOG.debug("Unable to unregister metric", e);
|
|
} catch (MBeanRegistrationException e) {
|
|
- LOGGER.warn("Unable to unregister metric", e);
|
|
+ LOG.warn("Unable to unregister metric", e);
|
|
}
|
|
}
|
|
registered.clear();
|
|
--- a/metrics-jmx/src/test/java/io/dropwizard/metrics5/jmx/DefaultObjectNameFactoryTest.java
|
|
+++ b/metrics-jmx/src/test/java/io/dropwizard/metrics5/jmx/DefaultObjectNameFactoryTest.java
|
|
@@ -7,7 +7,7 @@ import io.dropwizard.metrics5.MetricName;
|
|
import javax.management.ObjectName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class DefaultObjectNameFactoryTest {
|
|
+final class DefaultObjectNameFactoryTest {
|
|
|
|
@Test
|
|
void createsObjectNameWithDomainInInput() {
|
|
--- a/metrics-jmx/src/test/java/io/dropwizard/metrics5/jmx/JmxReporterTest.java
|
|
+++ b/metrics-jmx/src/test/java/io/dropwizard/metrics5/jmx/JmxReporterTest.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.jmx;
|
|
|
|
+import static java.util.UUID.randomUUID;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
|
@@ -21,7 +22,6 @@ import io.dropwizard.metrics5.Timer;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.util.SortedMap;
|
|
import java.util.TreeMap;
|
|
-import java.util.UUID;
|
|
import java.util.concurrent.TimeUnit;
|
|
import javax.management.Attribute;
|
|
import javax.management.AttributeList;
|
|
@@ -35,9 +35,9 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
-class JmxReporterTest {
|
|
+final class JmxReporterTest {
|
|
private final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
|
- private final String name = UUID.randomUUID().toString().replaceAll("[{\\-}]", "");
|
|
+ private final String name = randomUUID().toString().replaceAll("[{\\-}]", "");
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
|
|
private final JmxReporter reporter =
|
|
@@ -49,12 +49,12 @@ class JmxReporterTest {
|
|
.filter(MetricFilter.ALL)
|
|
.build();
|
|
|
|
- private final Gauge gauge = mock(Gauge.class);
|
|
- private final Counter counter = mock(Counter.class);
|
|
- private final Histogram histogram = mock(Histogram.class);
|
|
- private final Meter meter = mock(Meter.class);
|
|
- private final Timer timer = mock(Timer.class);
|
|
- private final ObjectNameFactory mockObjectNameFactory = mock(ObjectNameFactory.class);
|
|
+ private final Gauge gauge = mock();
|
|
+ private final Counter counter = mock();
|
|
+ private final Histogram histogram = mock();
|
|
+ private final Meter meter = mock();
|
|
+ private final Timer timer = mock();
|
|
+ private final ObjectNameFactory mockObjectNameFactory = mock();
|
|
private final ObjectNameFactory concreteObjectNameFactory = reporter.getObjectNameFactory();
|
|
|
|
@BeforeEach
|
|
@@ -66,7 +66,7 @@ class JmxReporterTest {
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
when(histogram.getSum()).thenReturn(12L);
|
|
|
|
- final Snapshot hSnapshot = mock(Snapshot.class);
|
|
+ final Snapshot hSnapshot = mock();
|
|
when(hSnapshot.getMax()).thenReturn(2L);
|
|
when(hSnapshot.getMean()).thenReturn(3.0);
|
|
when(hSnapshot.getMin()).thenReturn(4L);
|
|
@@ -95,7 +95,7 @@ class JmxReporterTest {
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot tSnapshot = mock(Snapshot.class);
|
|
+ final Snapshot tSnapshot = mock();
|
|
when(tSnapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(tSnapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(tSnapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
@@ -285,7 +285,7 @@ class JmxReporterTest {
|
|
|
|
@Test
|
|
void objectNameModifyingMBeanServer() throws Exception {
|
|
- MBeanServer mockedMBeanServer = mock(MBeanServer.class);
|
|
+ MBeanServer mockedMBeanServer = mock();
|
|
|
|
// overwrite the objectName
|
|
when(mockedMBeanServer.registerMBean(any(Object.class), any(ObjectName.class)))
|
|
@@ -310,7 +310,7 @@ class JmxReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testJmxMetricNameWithAsterisk() {
|
|
+ void jmxMetricNameWithAsterisk() {
|
|
MetricRegistry metricRegistry = new MetricRegistry();
|
|
JmxReporter.forRegistry(metricRegistry).build().start();
|
|
metricRegistry.counter("test*");
|
|
--- a/metrics-json/src/main/java/io/dropwizard/metrics5/json/HealthCheckModule.java
|
|
+++ b/metrics-json/src/main/java/io/dropwizard/metrics5/json/HealthCheckModule.java
|
|
@@ -6,9 +6,9 @@ import com.fasterxml.jackson.databind.Module;
|
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
import com.fasterxml.jackson.databind.module.SimpleSerializers;
|
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|
+import com.google.common.collect.ImmutableList;
|
|
import io.dropwizard.metrics5.health.HealthCheck;
|
|
import java.io.IOException;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
|
|
public class HealthCheckModule extends Module {
|
|
@@ -80,6 +80,6 @@ public class HealthCheckModule extends Module {
|
|
@Override
|
|
public void setupModule(SetupContext context) {
|
|
context.addSerializers(
|
|
- new SimpleSerializers(Collections.singletonList(new HealthCheckResultSerializer())));
|
|
+ new SimpleSerializers(ImmutableList.of(new HealthCheckResultSerializer())));
|
|
}
|
|
}
|
|
--- a/metrics-json/src/test/java/io/dropwizard/metrics5/json/HealthCheckModuleTest.java
|
|
+++ b/metrics-json/src/test/java/io/dropwizard/metrics5/json/HealthCheckModuleTest.java
|
|
@@ -10,15 +10,14 @@ import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HealthCheckModuleTest {
|
|
+final class HealthCheckModuleTest {
|
|
private final ObjectMapper mapper = new ObjectMapper().registerModule(new HealthCheckModule());
|
|
|
|
@Test
|
|
void serializesAHealthyResult() throws Exception {
|
|
HealthCheck.Result result = HealthCheck.Result.healthy();
|
|
assertThat(mapper.writeValueAsString(result))
|
|
- .isEqualTo(
|
|
- "{\"healthy\":true,\"duration\":0,\"timestamp\":\"" + result.getTimestamp() + "\"}");
|
|
+ .isEqualTo("{\"healthy\":true,\"duration\":0,\"timestamp\":\"%s\"}", result.getTimestamp());
|
|
}
|
|
|
|
@Test
|
|
@@ -26,14 +25,8 @@ class HealthCheckModuleTest {
|
|
HealthCheck.Result result = HealthCheck.Result.healthy("yay for %s", "me");
|
|
assertThat(mapper.writeValueAsString(result))
|
|
.isEqualTo(
|
|
- "{"
|
|
- + "\"healthy\":true,"
|
|
- + "\"message\":\"yay for me\","
|
|
- + "\"duration\":0,"
|
|
- + "\"timestamp\":\""
|
|
- + result.getTimestamp()
|
|
- + "\""
|
|
- + "}");
|
|
+ "{\"healthy\":true,\"message\":\"yay for me\",\"duration\":0,\"timestamp\":\"%s\"}",
|
|
+ result.getTimestamp());
|
|
}
|
|
|
|
@Test
|
|
@@ -41,14 +34,8 @@ class HealthCheckModuleTest {
|
|
HealthCheck.Result result = HealthCheck.Result.unhealthy("boo");
|
|
assertThat(mapper.writeValueAsString(result))
|
|
.isEqualTo(
|
|
- "{"
|
|
- + "\"healthy\":false,"
|
|
- + "\"message\":\"boo\","
|
|
- + "\"duration\":0,"
|
|
- + "\"timestamp\":\""
|
|
- + result.getTimestamp()
|
|
- + "\""
|
|
- + "}");
|
|
+ "{\"healthy\":false,\"message\":\"boo\",\"duration\":0,\"timestamp\":\"%s\"}",
|
|
+ result.getTimestamp());
|
|
}
|
|
|
|
@Test
|
|
@@ -60,19 +47,8 @@ class HealthCheckModuleTest {
|
|
HealthCheck.Result result = HealthCheck.Result.unhealthy(e);
|
|
assertThat(mapper.writeValueAsString(result))
|
|
.isEqualTo(
|
|
- "{"
|
|
- + "\"healthy\":false,"
|
|
- + "\"message\":\"oh no\","
|
|
- + "\"error\":{"
|
|
- + "\"type\":\"java.lang.RuntimeException\","
|
|
- + "\"message\":\"oh no\","
|
|
- + "\"stack\":[\"Blah.bloo(Blah.java:100)\"]"
|
|
- + "},"
|
|
- + "\"duration\":0,"
|
|
- + "\"timestamp\":\""
|
|
- + result.getTimestamp()
|
|
- + "\""
|
|
- + "}");
|
|
+ "{\"healthy\":false,\"message\":\"oh no\",\"error\":{\"type\":\"java.lang.RuntimeException\",\"message\":\"oh no\",\"stack\":[\"Blah.bloo(Blah.java:100)\"]},\"duration\":0,\"timestamp\":\"%s\"}",
|
|
+ result.getTimestamp());
|
|
}
|
|
|
|
@Test
|
|
@@ -88,24 +64,8 @@ class HealthCheckModuleTest {
|
|
HealthCheck.Result result = HealthCheck.Result.unhealthy(b);
|
|
assertThat(mapper.writeValueAsString(result))
|
|
.isEqualTo(
|
|
- "{"
|
|
- + "\"healthy\":false,"
|
|
- + "\"message\":\"oh well\","
|
|
- + "\"error\":{"
|
|
- + "\"type\":\"java.lang.RuntimeException\","
|
|
- + "\"message\":\"oh well\","
|
|
- + "\"stack\":[\"Blah.blee(Blah.java:150)\"],"
|
|
- + "\"cause\":{"
|
|
- + "\"type\":\"java.lang.RuntimeException\","
|
|
- + "\"message\":\"oh no\","
|
|
- + "\"stack\":[\"Blah.bloo(Blah.java:100)\"]"
|
|
- + "}"
|
|
- + "},"
|
|
- + "\"duration\":0,"
|
|
- + "\"timestamp\":\""
|
|
- + result.getTimestamp()
|
|
- + "\""
|
|
- + "}");
|
|
+ "{\"healthy\":false,\"message\":\"oh well\",\"error\":{\"type\":\"java.lang.RuntimeException\",\"message\":\"oh well\",\"stack\":[\"Blah.blee(Blah.java:150)\"],\"cause\":{\"type\":\"java.lang.RuntimeException\",\"message\":\"oh no\",\"stack\":[\"Blah.bloo(Blah.java:100)\"]}},\"duration\":0,\"timestamp\":\"%s\"}",
|
|
+ result.getTimestamp());
|
|
}
|
|
|
|
@Test
|
|
@@ -129,23 +89,7 @@ class HealthCheckModuleTest {
|
|
|
|
assertThat(mapper.writeValueAsString(result))
|
|
.isEqualTo(
|
|
- "{"
|
|
- + "\"healthy\":true,"
|
|
- + "\"duration\":0,"
|
|
- + "\"boolean\":true,"
|
|
- + "\"integer\":1,"
|
|
- + "\"long\":2,"
|
|
- + "\"float\":3.546,"
|
|
- + "\"double\":4.567,"
|
|
- + "\"BigInteger\":12345,"
|
|
- + "\"BigDecimal\":12345.56789,"
|
|
- + "\"String\":\"string\","
|
|
- + "\"complex\":{"
|
|
- + "\"field\":\"value\""
|
|
- + "},"
|
|
- + "\"timestamp\":\""
|
|
- + result.getTimestamp()
|
|
- + "\""
|
|
- + "}");
|
|
+ "{\"healthy\":true,\"duration\":0,\"boolean\":true,\"integer\":1,\"long\":2,\"float\":3.546,\"double\":4.567,\"BigInteger\":12345,\"BigDecimal\":12345.56789,\"String\":\"string\",\"complex\":{\"field\":\"value\"},\"timestamp\":\"%s\"}",
|
|
+ result.getTimestamp());
|
|
}
|
|
}
|
|
--- a/metrics-json/src/test/java/io/dropwizard/metrics5/json/MetricsModuleTest.java
|
|
+++ b/metrics-json/src/test/java/io/dropwizard/metrics5/json/MetricsModuleTest.java
|
|
@@ -16,7 +16,7 @@ import io.dropwizard.metrics5.Timer;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricsModuleTest {
|
|
+final class MetricsModuleTest {
|
|
private final ObjectMapper mapper =
|
|
new ObjectMapper()
|
|
.registerModule(
|
|
@@ -42,7 +42,7 @@ class MetricsModuleTest {
|
|
|
|
@Test
|
|
void serializesCounters() throws Exception {
|
|
- final Counter counter = mock(Counter.class);
|
|
+ final Counter counter = mock();
|
|
when(counter.getCount()).thenReturn(100L);
|
|
|
|
assertThat(mapper.writeValueAsString(counter)).isEqualTo("{\"count\":100}");
|
|
@@ -50,10 +50,10 @@ class MetricsModuleTest {
|
|
|
|
@Test
|
|
void serializesHistograms() throws Exception {
|
|
- final Histogram histogram = mock(Histogram.class);
|
|
+ final Histogram histogram = mock();
|
|
when(histogram.getCount()).thenReturn(1L);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(2L);
|
|
when(snapshot.getMean()).thenReturn(3.0);
|
|
when(snapshot.getMin()).thenReturn(4L);
|
|
@@ -107,7 +107,7 @@ class MetricsModuleTest {
|
|
|
|
@Test
|
|
void serializesMeters() throws Exception {
|
|
- final Meter meter = mock(Meter.class);
|
|
+ final Meter meter = mock();
|
|
when(meter.getCount()).thenReturn(1L);
|
|
when(meter.getMeanRate()).thenReturn(2.0);
|
|
when(meter.getOneMinuteRate()).thenReturn(5.0);
|
|
@@ -127,14 +127,14 @@ class MetricsModuleTest {
|
|
|
|
@Test
|
|
void serializesTimers() throws Exception {
|
|
- final Timer timer = mock(Timer.class);
|
|
+ final Timer timer = mock();
|
|
when(timer.getCount()).thenReturn(1L);
|
|
when(timer.getMeanRate()).thenReturn(2.0);
|
|
when(timer.getOneMinuteRate()).thenReturn(3.0);
|
|
when(timer.getFiveMinuteRate()).thenReturn(4.0);
|
|
when(timer.getFifteenMinuteRate()).thenReturn(5.0);
|
|
|
|
- final Snapshot snapshot = mock(Snapshot.class);
|
|
+ final Snapshot snapshot = mock();
|
|
when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
|
|
when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
|
|
when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/BufferPoolMetricSet.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/BufferPoolMetricSet.java
|
|
@@ -1,10 +1,11 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
import io.dropwizard.metrics5.MetricSet;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import javax.management.JMException;
|
|
@@ -19,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
|
* <p>These JMX objects are only available on Java 7 and above.
|
|
*/
|
|
public class BufferPoolMetricSet implements MetricSet {
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(BufferPoolMetricSet.class);
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(BufferPoolMetricSet.class);
|
|
private static final String[] ATTRIBUTES = {"Count", "MemoryUsed", "TotalCapacity"};
|
|
private static final String[] NAMES = {"count", "used", "capacity"};
|
|
private static final String[] POOLS = {"direct", "mapped"};
|
|
@@ -43,10 +44,10 @@ public class BufferPoolMetricSet implements MetricSet {
|
|
gauges.put(
|
|
MetricRegistry.name(pool, name), new JmxAttributeGauge(mBeanServer, on, attribute));
|
|
} catch (JMException ignored) {
|
|
- LOGGER.debug("Unable to load buffer pool MBeans, possibly running on Java 6");
|
|
+ LOG.debug("Unable to load buffer pool MBeans, possibly running on Java 6");
|
|
}
|
|
}
|
|
}
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/GarbageCollectorMetricSet.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/GarbageCollectorMetricSet.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -9,7 +11,6 @@ import java.lang.management.GarbageCollectorMXBean;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -43,6 +44,6 @@ public class GarbageCollectorMetricSet implements MetricSet {
|
|
gauges.put(MetricRegistry.name(name, "count"), (Gauge<Long>) gc::getCollectionCount);
|
|
gauges.put(MetricRegistry.name(name, "time"), (Gauge<Long>) gc::getCollectionTime);
|
|
}
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/JvmAttributeGaugeSet.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/JvmAttributeGaugeSet.java
|
|
@@ -1,12 +1,13 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import io.dropwizard.metrics5.MetricSet;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.RuntimeMXBean;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
@@ -47,6 +48,6 @@ public class JvmAttributeGaugeSet implements MetricSet {
|
|
runtime.getSpecVersion()));
|
|
gauges.put(MetricName.build("uptime"), (Gauge<Long>) runtime::getUptime);
|
|
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/MemoryUsageGaugeSet.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/MemoryUsageGaugeSet.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -12,7 +14,6 @@ import java.lang.management.MemoryPoolMXBean;
|
|
import java.lang.management.MemoryUsage;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -139,6 +140,6 @@ public class MemoryUsageGaugeSet implements MetricSet {
|
|
MetricRegistry.name(poolName, "init"), (Gauge<Long>) () -> pool.getUsage().getInit());
|
|
}
|
|
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/ThreadDeadlockDetector.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/ThreadDeadlockDetector.java
|
|
@@ -1,9 +1,11 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableSet;
|
|
+
|
|
+import com.google.common.collect.ImmutableSet;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ThreadInfo;
|
|
import java.lang.management.ThreadMXBean;
|
|
-import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
@@ -40,19 +42,16 @@ public class ThreadDeadlockDetector {
|
|
for (ThreadInfo info : threads.getThreadInfo(ids, MAX_STACK_TRACE_DEPTH)) {
|
|
final StringBuilder stackTrace = new StringBuilder();
|
|
for (StackTraceElement element : info.getStackTrace()) {
|
|
- stackTrace.append("\t at ").append(element.toString()).append(String.format("%n"));
|
|
+ stackTrace.append("\t at ").append(element).append(String.format("%n"));
|
|
}
|
|
|
|
deadlocks.add(
|
|
String.format(
|
|
"%s locked on %s (owned by %s):%n%s",
|
|
- info.getThreadName(),
|
|
- info.getLockName(),
|
|
- info.getLockOwnerName(),
|
|
- stackTrace.toString()));
|
|
+ info.getThreadName(), info.getLockName(), info.getLockOwnerName(), stackTrace));
|
|
}
|
|
- return Collections.unmodifiableSet(deadlocks);
|
|
+ return unmodifiableSet(deadlocks);
|
|
}
|
|
- return Collections.emptySet();
|
|
+ return ImmutableSet.of();
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/ThreadStatesGaugeSet.java
|
|
+++ b/metrics-jvm/src/main/java/io/dropwizard/metrics5/jvm/ThreadStatesGaugeSet.java
|
|
@@ -1,5 +1,7 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.Metric;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
@@ -8,7 +10,6 @@ import io.dropwizard.metrics5.MetricSet;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ThreadInfo;
|
|
import java.lang.management.ThreadMXBean;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
@@ -59,7 +60,7 @@ public class ThreadStatesGaugeSet implements MetricSet {
|
|
gauges.put(
|
|
MetricName.build("deadlocks"), (Gauge<Set<String>>) deadlockDetector::getDeadlockedThreads);
|
|
|
|
- return Collections.unmodifiableMap(gauges);
|
|
+ return unmodifiableMap(gauges);
|
|
}
|
|
|
|
private int getThreadCount(Thread.State state) {
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/BufferPoolMetricSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/BufferPoolMetricSetTest.java
|
|
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
-class BufferPoolMetricSetTest {
|
|
+final class BufferPoolMetricSetTest {
|
|
|
|
private static final MetricName DIRECT = MetricName.build("direct");
|
|
private static final MetricName MAPPED = MetricName.build("mapped");
|
|
@@ -24,7 +24,7 @@ class BufferPoolMetricSetTest {
|
|
private static final MetricName MAPPED_CAPACITY = MAPPED.resolve("capacity");
|
|
private static final MetricName MAPPED_USED = MAPPED.resolve("used");
|
|
|
|
- private final MBeanServer mBeanServer = mock(MBeanServer.class);
|
|
+ private final MBeanServer mBeanServer = mock();
|
|
private final BufferPoolMetricSet buffers = new BufferPoolMetricSet(mBeanServer);
|
|
|
|
private ObjectName mapped;
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ClassLoadingGaugeSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ClassLoadingGaugeSetTest.java
|
|
@@ -11,9 +11,9 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
-class ClassLoadingGaugeSetTest {
|
|
+final class ClassLoadingGaugeSetTest {
|
|
|
|
- private final ClassLoadingMXBean cl = mock(ClassLoadingMXBean.class);
|
|
+ private final ClassLoadingMXBean cl = mock();
|
|
private final ClassLoadingGaugeSet gauges = new ClassLoadingGaugeSet(cl);
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/CpuTimeClockTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/CpuTimeClockTest.java
|
|
@@ -6,7 +6,7 @@ import static org.assertj.core.api.Assertions.offset;
|
|
import java.lang.management.ManagementFactory;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CpuTimeClockTest {
|
|
+final class CpuTimeClockTest {
|
|
|
|
@Test
|
|
void cpuTimeClock() {
|
|
@@ -14,10 +14,10 @@ class CpuTimeClockTest {
|
|
|
|
final long clockTime = clock.getTime();
|
|
final long systemTime = System.currentTimeMillis();
|
|
- assertThat((double) clockTime).isEqualTo(systemTime, offset(200.0));
|
|
+ assertThat((double) clockTime).isCloseTo(systemTime, offset(200.0));
|
|
|
|
final long clockTick = clock.getTick();
|
|
final long systemTick = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
|
|
- assertThat((double) clockTick).isEqualTo(systemTick, offset(1000000.0));
|
|
+ assertThat((double) clockTick).isCloseTo(systemTick, offset(1000000.0));
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/FileDescriptorRatioGaugeTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/FileDescriptorRatioGaugeTest.java
|
|
@@ -1,5 +1,6 @@
|
|
package io.dropwizard.metrics5.jvm;
|
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
@@ -7,13 +8,12 @@ import static org.mockito.Mockito.when;
|
|
import com.sun.management.UnixOperatingSystemMXBean;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.OperatingSystemMXBean;
|
|
-import org.assertj.core.api.Assertions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
-class FileDescriptorRatioGaugeTest {
|
|
- private final UnixOperatingSystemMXBean os = mock(UnixOperatingSystemMXBean.class);
|
|
+final class FileDescriptorRatioGaugeTest {
|
|
+ private final UnixOperatingSystemMXBean os = mock();
|
|
|
|
private final FileDescriptorRatioGauge gauge = new FileDescriptorRatioGauge(os);
|
|
|
|
@@ -25,7 +25,7 @@ class FileDescriptorRatioGaugeTest {
|
|
|
|
@Test
|
|
void calculatesTheRatioOfUsedToTotalFileDescriptors() {
|
|
- Assertions.assertThat(gauge.getValue()).isEqualTo(0.1);
|
|
+ assertThat(gauge.getValue()).isEqualTo(0.1);
|
|
}
|
|
|
|
@Test
|
|
@@ -33,15 +33,11 @@ class FileDescriptorRatioGaugeTest {
|
|
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
|
|
assumeTrue(osBean instanceof com.sun.management.UnixOperatingSystemMXBean);
|
|
|
|
- Assertions.assertThat(new FileDescriptorRatioGauge().getValue())
|
|
- .isGreaterThanOrEqualTo(0.0)
|
|
- .isLessThanOrEqualTo(1.0);
|
|
+ assertThat(new FileDescriptorRatioGauge().getValue()).isNotNegative().isLessThanOrEqualTo(1.0);
|
|
}
|
|
|
|
@Test
|
|
void returnsNaNWhenTheInformationIsUnavailable() {
|
|
- Assertions.assertThat(
|
|
- new FileDescriptorRatioGauge(mock(OperatingSystemMXBean.class)).getValue())
|
|
- .isNaN();
|
|
+ assertThat(new FileDescriptorRatioGauge(mock(OperatingSystemMXBean.class)).getValue()).isNaN();
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/GarbageCollectorMetricSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/GarbageCollectorMetricSetTest.java
|
|
@@ -4,18 +4,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
import io.dropwizard.metrics5.Gauge;
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import java.lang.management.GarbageCollectorMXBean;
|
|
-import java.util.Collections;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
-class GarbageCollectorMetricSetTest {
|
|
- private final GarbageCollectorMXBean gc = mock(GarbageCollectorMXBean.class);
|
|
+final class GarbageCollectorMetricSetTest {
|
|
+ private final GarbageCollectorMXBean gc = mock();
|
|
private final GarbageCollectorMetricSet metrics =
|
|
- new GarbageCollectorMetricSet(Collections.singletonList(gc));
|
|
+ new GarbageCollectorMetricSet(ImmutableList.of(gc));
|
|
|
|
private static final MetricName PS_OLDGEN_TIME = MetricName.build("PS-OldGen.time");
|
|
private static final MetricName PS_OLDGEN_COUNT = MetricName.build("PS-OldGen.count");
|
|
@@ -46,6 +46,6 @@ class GarbageCollectorMetricSetTest {
|
|
|
|
@Test
|
|
void autoDiscoversGCs() {
|
|
- assertThat(new GarbageCollectorMetricSet().getMetrics().keySet()).isNotEmpty();
|
|
+ assertThat(new GarbageCollectorMetricSet().getMetrics()).isNotEmpty();
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/JmxAttributeGaugeTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/JmxAttributeGaugeTest.java
|
|
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterAll;
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class JmxAttributeGaugeTest {
|
|
+final class JmxAttributeGaugeTest {
|
|
|
|
private static MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
|
|
|
@@ -53,7 +53,7 @@ class JmxAttributeGaugeTest {
|
|
JmxAttributeGauge gauge = new JmxAttributeGauge(mBeanServer, objectName, "LoadedClassCount");
|
|
|
|
assertThat(gauge.getValue()).isInstanceOf(Integer.class);
|
|
- assertThat((Integer) gauge.getValue()).isGreaterThan(0);
|
|
+ assertThat((Integer) gauge.getValue()).isPositive();
|
|
}
|
|
|
|
@Test
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/JvmAttributeGaugeSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/JvmAttributeGaugeSetTest.java
|
|
@@ -11,8 +11,8 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
-class JvmAttributeGaugeSetTest {
|
|
- private final RuntimeMXBean runtime = mock(RuntimeMXBean.class);
|
|
+final class JvmAttributeGaugeSetTest {
|
|
+ private final RuntimeMXBean runtime = mock();
|
|
private final JvmAttributeGaugeSet gauges = new JvmAttributeGaugeSet(runtime);
|
|
|
|
@BeforeEach
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/MemoryUsageGaugeSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/MemoryUsageGaugeSetTest.java
|
|
@@ -14,15 +14,15 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
-class MemoryUsageGaugeSetTest {
|
|
- private final MemoryUsage heap = mock(MemoryUsage.class);
|
|
- private final MemoryUsage nonHeap = mock(MemoryUsage.class);
|
|
- private final MemoryUsage pool = mock(MemoryUsage.class);
|
|
- private final MemoryUsage weirdPool = mock(MemoryUsage.class);
|
|
- private final MemoryUsage weirdCollection = mock(MemoryUsage.class);
|
|
- private final MemoryMXBean mxBean = mock(MemoryMXBean.class);
|
|
- private final MemoryPoolMXBean memoryPool = mock(MemoryPoolMXBean.class);
|
|
- private final MemoryPoolMXBean weirdMemoryPool = mock(MemoryPoolMXBean.class);
|
|
+final class MemoryUsageGaugeSetTest {
|
|
+ private final MemoryUsage heap = mock();
|
|
+ private final MemoryUsage nonHeap = mock();
|
|
+ private final MemoryUsage pool = mock();
|
|
+ private final MemoryUsage weirdPool = mock();
|
|
+ private final MemoryUsage weirdCollection = mock();
|
|
+ private final MemoryMXBean mxBean = mock();
|
|
+ private final MemoryPoolMXBean memoryPool = mock();
|
|
+ private final MemoryPoolMXBean weirdMemoryPool = mock();
|
|
|
|
private final MemoryUsageGaugeSet gauges =
|
|
new MemoryUsageGaugeSet(mxBean, Arrays.asList(memoryPool, weirdMemoryPool));
|
|
@@ -159,7 +159,7 @@ class MemoryUsageGaugeSetTest {
|
|
}
|
|
|
|
@Test
|
|
- public void hasAGaugeForTotalMaxWhenNonHeapMaxUndefined() {
|
|
+ void hasAGaugeForTotalMaxWhenNonHeapMaxUndefined() {
|
|
when(nonHeap.getMax()).thenReturn(-1L);
|
|
|
|
final Gauge gauge = (Gauge) gauges.getMetrics().get(TOTAL_MAX);
|
|
@@ -238,7 +238,7 @@ class MemoryUsageGaugeSetTest {
|
|
}
|
|
|
|
@Test
|
|
- public void hasAGaugeForNonHeapUsageWhenNonHeapMaxUndefined() {
|
|
+ void hasAGaugeForNonHeapUsageWhenNonHeapMaxUndefined() {
|
|
when(nonHeap.getMax()).thenReturn(-1L);
|
|
final Gauge gauge = (Gauge) gauges.getMetrics().get(NON_HEAP_USAGE);
|
|
|
|
@@ -296,6 +296,6 @@ class MemoryUsageGaugeSetTest {
|
|
|
|
@Test
|
|
void autoDetectsMemoryUsageBeanAndMemoryPools() {
|
|
- assertThat(new MemoryUsageGaugeSet().getMetrics().keySet()).isNotEmpty();
|
|
+ assertThat(new MemoryUsageGaugeSet().getMetrics()).isNotEmpty();
|
|
}
|
|
}
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadDeadlockDetectorTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadDeadlockDetectorTest.java
|
|
@@ -11,8 +11,8 @@ import java.lang.management.ThreadMXBean;
|
|
import java.util.Locale;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ThreadDeadlockDetectorTest {
|
|
- private final ThreadMXBean threads = mock(ThreadMXBean.class);
|
|
+final class ThreadDeadlockDetectorTest {
|
|
+ private final ThreadMXBean threads = mock();
|
|
private final ThreadDeadlockDetector detector = new ThreadDeadlockDetector(threads);
|
|
|
|
@Test
|
|
@@ -24,7 +24,7 @@ class ThreadDeadlockDetectorTest {
|
|
|
|
@Test
|
|
void returnsASetOfThreadsIfAnyAreDeadlocked() {
|
|
- final ThreadInfo thread1 = mock(ThreadInfo.class);
|
|
+ final ThreadInfo thread1 = mock();
|
|
when(thread1.getThreadName()).thenReturn("thread1");
|
|
when(thread1.getLockName()).thenReturn("lock2");
|
|
when(thread1.getLockOwnerName()).thenReturn("thread2");
|
|
@@ -35,7 +35,7 @@ class ThreadDeadlockDetectorTest {
|
|
new StackTraceElement("Blah", "blee", "Blah.java", 100)
|
|
});
|
|
|
|
- final ThreadInfo thread2 = mock(ThreadInfo.class);
|
|
+ final ThreadInfo thread2 = mock();
|
|
when(thread2.getThreadName()).thenReturn("thread2");
|
|
when(thread2.getLockName()).thenReturn("lock1");
|
|
when(thread2.getLockOwnerName()).thenReturn("thread1");
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadDumpTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadDumpTest.java
|
|
@@ -14,11 +14,11 @@ import org.junit.jupiter.api.Test;
|
|
|
|
// TODO: 3/12/13 <coda> -- improve test coverage for ThreadDump
|
|
|
|
-class ThreadDumpTest {
|
|
- private final ThreadMXBean threadMXBean = mock(ThreadMXBean.class);
|
|
+final class ThreadDumpTest {
|
|
+ private final ThreadMXBean threadMXBean = mock();
|
|
private final ThreadDump threadDump = new ThreadDump(threadMXBean);
|
|
|
|
- private final ThreadInfo runnable = mock(ThreadInfo.class);
|
|
+ private final ThreadInfo runnable = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
@@ -39,8 +39,8 @@ class ThreadDumpTest {
|
|
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
threadDump.dump(output);
|
|
|
|
- assertThat(output.toString())
|
|
- .isEqualTo(
|
|
+ assertThat(output)
|
|
+ .hasToString(
|
|
String.format(
|
|
"\"runnable\" id=100 state=RUNNABLE%n"
|
|
+ " at Blah.blee(Blah.java:100)%n"
|
|
--- a/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadStatesGaugeSetTest.java
|
|
+++ b/metrics-jvm/src/test/java/io/dropwizard/metrics5/jvm/ThreadStatesGaugeSetTest.java
|
|
@@ -10,22 +10,21 @@ import java.lang.management.ThreadInfo;
|
|
import java.lang.management.ThreadMXBean;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
-import org.assertj.core.api.Assertions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ThreadStatesGaugeSetTest {
|
|
- private final ThreadMXBean threads = mock(ThreadMXBean.class);
|
|
- private final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
|
|
+final class ThreadStatesGaugeSetTest {
|
|
+ private final ThreadMXBean threads = mock();
|
|
+ private final ThreadDeadlockDetector detector = mock();
|
|
private final ThreadStatesGaugeSet gauges = new ThreadStatesGaugeSet(threads, detector);
|
|
private final long[] ids = new long[] {1, 2, 3};
|
|
|
|
- private final ThreadInfo newThread = mock(ThreadInfo.class);
|
|
- private final ThreadInfo runnableThread = mock(ThreadInfo.class);
|
|
- private final ThreadInfo blockedThread = mock(ThreadInfo.class);
|
|
- private final ThreadInfo waitingThread = mock(ThreadInfo.class);
|
|
- private final ThreadInfo timedWaitingThread = mock(ThreadInfo.class);
|
|
- private final ThreadInfo terminatedThread = mock(ThreadInfo.class);
|
|
+ private final ThreadInfo newThread = mock();
|
|
+ private final ThreadInfo runnableThread = mock();
|
|
+ private final ThreadInfo blockedThread = mock();
|
|
+ private final ThreadInfo waitingThread = mock();
|
|
+ private final ThreadInfo timedWaitingThread = mock();
|
|
+ private final ThreadInfo terminatedThread = mock();
|
|
|
|
private final Set<String> deadlocks = new HashSet<>();
|
|
|
|
@@ -87,7 +86,7 @@ class ThreadStatesGaugeSetTest {
|
|
|
|
@Test
|
|
void hasAGaugeForEachThreadState() {
|
|
- Assertions.assertThat(((Gauge<?>) gauges.getMetrics().get(NEW_COUNT)).getValue()).isEqualTo(1);
|
|
+ assertThat(((Gauge<?>) gauges.getMetrics().get(NEW_COUNT)).getValue()).isEqualTo(1);
|
|
|
|
assertThat(((Gauge<?>) gauges.getMetrics().get(RUNNABLE_COUNT)).getValue()).isEqualTo(1);
|
|
|
|
--- a/metrics-legacy-adapter/src/main/java/com/codahale/metrics/MetricRegistry.java
|
|
+++ b/metrics-legacy-adapter/src/main/java/com/codahale/metrics/MetricRegistry.java
|
|
@@ -1,16 +1,16 @@
|
|
package com.codahale.metrics;
|
|
|
|
+import static java.util.Collections.unmodifiableSortedMap;
|
|
import static java.util.Collections.unmodifiableSortedSet;
|
|
import static java.util.Objects.requireNonNull;
|
|
+import static java.util.stream.Collectors.toCollection;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
import java.util.SortedMap;
|
|
import java.util.SortedSet;
|
|
import java.util.TreeMap;
|
|
import java.util.TreeSet;
|
|
-import java.util.stream.Collectors;
|
|
|
|
@Deprecated
|
|
public class MetricRegistry implements MetricSet {
|
|
@@ -102,9 +102,7 @@ public class MetricRegistry implements MetricSet {
|
|
|
|
public SortedSet<String> getNames() {
|
|
return unmodifiableSortedSet(
|
|
- delegate.getNames().stream()
|
|
- .map(MetricName::getKey)
|
|
- .collect(Collectors.toCollection(TreeSet::new)));
|
|
+ delegate.getNames().stream().map(MetricName::getKey).collect(toCollection(TreeSet::new)));
|
|
}
|
|
|
|
public SortedMap<String, Gauge> getGauges() {
|
|
@@ -160,7 +158,7 @@ public class MetricRegistry implements MetricSet {
|
|
metrics.entrySet()) {
|
|
items.put(entry.getKey().getKey(), (T) Metric.of(entry.getValue()));
|
|
}
|
|
- return Collections.unmodifiableSortedMap(items);
|
|
+ return unmodifiableSortedMap(items);
|
|
}
|
|
|
|
@Override
|
|
--- a/metrics-legacy-adapter/src/main/java/com/codahale/metrics/MetricSet.java
|
|
+++ b/metrics-legacy-adapter/src/main/java/com/codahale/metrics/MetricSet.java
|
|
@@ -1,7 +1,8 @@
|
|
package com.codahale.metrics;
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
+
|
|
import io.dropwizard.metrics5.MetricName;
|
|
-import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@@ -24,7 +25,7 @@ public interface MetricSet extends Metric {
|
|
original.getMetrics().entrySet()) {
|
|
items.put(entry.getKey().getKey(), Metric.of(entry.getValue()));
|
|
}
|
|
- return Collections.unmodifiableMap(items);
|
|
+ return unmodifiableMap(items);
|
|
}
|
|
|
|
@Override
|
|
@@ -48,7 +49,7 @@ public interface MetricSet extends Metric {
|
|
for (Map.Entry<String, Metric> entry : delegate.getMetrics().entrySet()) {
|
|
items.put(MetricName.build(entry.getKey()), entry.getValue().getDelegate());
|
|
}
|
|
- return Collections.unmodifiableMap(items);
|
|
+ return unmodifiableMap(items);
|
|
}
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/main/java/com/codahale/metrics/ScheduledReporter.java
|
|
+++ b/metrics-legacy-adapter/src/main/java/com/codahale/metrics/ScheduledReporter.java
|
|
@@ -1,10 +1,10 @@
|
|
package com.codahale.metrics;
|
|
|
|
+import static java.util.Collections.unmodifiableSortedMap;
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
import io.dropwizard.metrics5.MetricName;
|
|
import java.io.Closeable;
|
|
-import java.util.Collections;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
@@ -115,7 +115,7 @@ public abstract class ScheduledReporter implements Closeable, Reporter {
|
|
for (Map.Entry<String, ? extends Metric> entry : metrics.entrySet()) {
|
|
items.put(MetricName.build(entry.getKey()), (T) entry.getValue().getDelegate());
|
|
}
|
|
- return Collections.unmodifiableSortedMap(items);
|
|
+ return unmodifiableSortedMap(items);
|
|
}
|
|
|
|
protected String getRateUnit() {
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/CachedGaugeTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/CachedGaugeTest.java
|
|
@@ -6,10 +6,10 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class CachedGaugeTest {
|
|
+final class CachedGaugeTest {
|
|
|
|
@Test
|
|
- void testCreate() {
|
|
+ void create() {
|
|
CachedGauge<String> cachedGauge =
|
|
new CachedGauge<String>(100, TimeUnit.MILLISECONDS) {
|
|
@Override
|
|
@@ -21,7 +21,7 @@ class CachedGaugeTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWothClock() {
|
|
+ void createWothClock() {
|
|
CachedGauge<String> cachedGauge =
|
|
new CachedGauge<String>(new Clock.UserTimeClock(), 100, TimeUnit.MILLISECONDS) {
|
|
@Override
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ClockTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ClockTest.java
|
|
@@ -5,22 +5,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class ClockTest {
|
|
+final class ClockTest {
|
|
|
|
@Test
|
|
- void testDefaultClockCanBeUsed() {
|
|
+ void defaultClockCanBeUsed() {
|
|
Clock clock = Clock.defaultClock();
|
|
- assertThat(clock.getTick()).isGreaterThan(0);
|
|
+ assertThat(clock.getTick()).isPositive();
|
|
}
|
|
|
|
@Test
|
|
- void testUserTimeClockCanBeUsed() {
|
|
+ void userTimeClockCanBeUsed() {
|
|
Clock clock = new Clock.UserTimeClock();
|
|
- assertThat(clock.getTick()).isGreaterThan(0);
|
|
+ assertThat(clock.getTick()).isPositive();
|
|
}
|
|
|
|
@Test
|
|
- void testCustomTimeClockCanBeUsed() {
|
|
+ void customTimeClockCanBeUsed() {
|
|
Clock clock =
|
|
new Clock() {
|
|
@Override
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ConsoleReporterTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ConsoleReporterTest.java
|
|
@@ -1,10 +1,10 @@
|
|
package com.codahale.metrics;
|
|
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.PrintStream;
|
|
-import java.nio.charset.StandardCharsets;
|
|
import java.util.EnumSet;
|
|
import java.util.Locale;
|
|
import java.util.TimeZone;
|
|
@@ -17,7 +17,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class ConsoleReporterTest {
|
|
+final class ConsoleReporterTest {
|
|
|
|
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
|
private final String dateHeader =
|
|
@@ -35,7 +35,7 @@ class ConsoleReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateConsoleReporter() throws Exception {
|
|
+ void createConsoleReporter() throws Exception {
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
MetricRegistry metricRegistry = new MetricRegistry();
|
|
@@ -72,7 +72,7 @@ class ConsoleReporterTest {
|
|
.build();
|
|
consoleReporter.report();
|
|
|
|
- assertThat(new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8))
|
|
+ assertThat(new String(byteArrayOutputStream.toByteArray(), UTF_8))
|
|
.isEqualToNormalizingNewlines(
|
|
dateHeader
|
|
+ "\n"
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/CounterTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/CounterTest.java
|
|
@@ -6,33 +6,33 @@ import io.dropwizard.metrics5.Counter;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class CounterTest {
|
|
+final class CounterTest {
|
|
|
|
private Counter counter = new Counter();
|
|
|
|
@Test
|
|
- void testIncrementCounter() {
|
|
+ void incrementCounter() {
|
|
counter.inc();
|
|
|
|
assertThat(counter.getCount()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- void testIncrementCounterOnManyPoints() {
|
|
+ void incrementCounterOnManyPoints() {
|
|
counter.inc(5);
|
|
|
|
assertThat(counter.getCount()).isEqualTo(5);
|
|
}
|
|
|
|
@Test
|
|
- void testDecrementCounter() {
|
|
+ void decrementCounter() {
|
|
counter.dec();
|
|
|
|
assertThat(counter.getCount()).isEqualTo(-1);
|
|
}
|
|
|
|
@Test
|
|
- void testDecrementCounterOnManyPoints() {
|
|
+ void decrementCounterOnManyPoints() {
|
|
counter.dec(5);
|
|
|
|
assertThat(counter.getCount()).isEqualTo(-5);
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/DerivativeGaugeTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/DerivativeGaugeTest.java
|
|
@@ -5,10 +5,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class DerivativeGaugeTest {
|
|
+final class DerivativeGaugeTest {
|
|
|
|
@Test
|
|
- void testCalculate() {
|
|
+ void calculate() {
|
|
DerivativeGauge<String, Integer> derivativeGauge =
|
|
new DerivativeGauge<String, Integer>(() -> "23") {
|
|
@Override
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ExponentiallyDecayingReservoirTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ExponentiallyDecayingReservoirTest.java
|
|
@@ -1,15 +1,15 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class ExponentiallyDecayingReservoirTest {
|
|
+final class ExponentiallyDecayingReservoirTest {
|
|
|
|
@Test
|
|
- void testCreateReservoir() {
|
|
+ void createReservoir() {
|
|
ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir();
|
|
reservoir.update(120);
|
|
reservoir.update(190);
|
|
@@ -22,7 +22,7 @@ class ExponentiallyDecayingReservoirTest {
|
|
assertThat(snapshot.getValues()).contains(120, 130, 140, 190, 200);
|
|
assertThat(snapshot.getMin()).isEqualTo(120);
|
|
assertThat(snapshot.getMax()).isEqualTo(200);
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(32.62, Offset.offset(0.1));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(32.62, offset(0.1));
|
|
assertThat(snapshot.get75thPercentile()).isEqualTo(190);
|
|
assertThat(snapshot.get95thPercentile()).isEqualTo(200);
|
|
assertThat(snapshot.get98thPercentile()).isEqualTo(200);
|
|
@@ -31,14 +31,14 @@ class ExponentiallyDecayingReservoirTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateReservoirWithCustomSizeAndAlpha() {
|
|
+ void createReservoirWithCustomSizeAndAlpha() {
|
|
ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(512, 0.01);
|
|
reservoir.update(100);
|
|
assertThat(reservoir.size()).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
- void testCreateReservoirWithCustomSizeAlphaAndClock() {
|
|
+ void createReservoirWithCustomSizeAlphaAndClock() {
|
|
ExponentiallyDecayingReservoir reservoir =
|
|
new ExponentiallyDecayingReservoir(
|
|
512,
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/FixedNameCsvFileProviderTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/FixedNameCsvFileProviderTest.java
|
|
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class FixedNameCsvFileProviderTest {
|
|
+final class FixedNameCsvFileProviderTest {
|
|
|
|
private Path tempDirectory;
|
|
private FixedNameCsvFileProvider fixedNameCsvFileProvider = new FixedNameCsvFileProvider();
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/GaugeTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/GaugeTest.java
|
|
@@ -5,12 +5,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class GaugeTest {
|
|
+final class GaugeTest {
|
|
|
|
private Gauge<Integer> gauge = () -> 83;
|
|
|
|
@Test
|
|
- void testGetValue() {
|
|
+ void getValue() {
|
|
assertThat(gauge.getValue()).isEqualTo(83);
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/HistogramTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/HistogramTest.java
|
|
@@ -1,15 +1,15 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class HistogramTest {
|
|
+final class HistogramTest {
|
|
|
|
@Test
|
|
- void testCreate() {
|
|
+ void create() {
|
|
Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
|
|
histogram.update(120);
|
|
histogram.update(190);
|
|
@@ -23,7 +23,7 @@ class HistogramTest {
|
|
assertThat(snapshot.getValues()).contains(120, 130, 140, 190, 200);
|
|
assertThat(snapshot.getMin()).isEqualTo(120);
|
|
assertThat(snapshot.getMax()).isEqualTo(200);
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(32.62, Offset.offset(0.1));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(32.62, offset(0.1));
|
|
assertThat(snapshot.get75thPercentile()).isEqualTo(190);
|
|
assertThat(snapshot.get95thPercentile()).isEqualTo(200);
|
|
assertThat(snapshot.get98thPercentile()).isEqualTo(200);
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedExecutorServiceTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedExecutorServiceTest.java
|
|
@@ -9,10 +9,10 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class InstrumentedExecutorServiceTest {
|
|
+final class InstrumentedExecutorServiceTest {
|
|
|
|
@Test
|
|
- void testCreate() throws Exception {
|
|
+ void create() throws Exception {
|
|
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
|
MetricRegistry registry = new MetricRegistry();
|
|
InstrumentedExecutorService instrumentedExecutorService =
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedScheduledExecutorServiceTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedScheduledExecutorServiceTest.java
|
|
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class InstrumentedScheduledExecutorServiceTest {
|
|
+final class InstrumentedScheduledExecutorServiceTest {
|
|
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
@AfterEach
|
|
@@ -19,7 +19,7 @@ class InstrumentedScheduledExecutorServiceTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreate() throws Exception {
|
|
+ void create() throws Exception {
|
|
MetricRegistry registry = new MetricRegistry();
|
|
InstrumentedScheduledExecutorService instrumentedExecutorService =
|
|
new InstrumentedScheduledExecutorService(
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedThreadFactoryTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/InstrumentedThreadFactoryTest.java
|
|
@@ -7,11 +7,11 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class InstrumentedThreadFactoryTest {
|
|
+final class InstrumentedThreadFactoryTest {
|
|
|
|
- @Test
|
|
@SuppressWarnings("DoNotCall")
|
|
- void testFactory() throws Exception {
|
|
+ @Test
|
|
+ void factory() throws Exception {
|
|
MetricRegistry registry = new MetricRegistry();
|
|
InstrumentedThreadFactory threadFactory =
|
|
new InstrumentedThreadFactory(Thread::new, registry, "test-instrumented-thread-factory");
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/MeterTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/MeterTest.java
|
|
@@ -6,16 +6,16 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class MeterTest {
|
|
+final class MeterTest {
|
|
|
|
@Test
|
|
- void testCreateMeteer() {
|
|
+ void createMeteer() {
|
|
Meter meter = new Meter();
|
|
assertThat(meter.getCount()).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
- void testCreateMeterWithCustomClock() {
|
|
+ void createMeterWithCustomClock() {
|
|
Meter meter =
|
|
new Meter(
|
|
new Clock() {
|
|
@@ -28,7 +28,7 @@ class MeterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testMark() {
|
|
+ void mark() {
|
|
Meter meter =
|
|
new Meter(
|
|
new Clock() {
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/MetricRegistryTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/MetricRegistryTest.java
|
|
@@ -11,19 +11,19 @@ import java.util.concurrent.TimeUnit;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class MetricRegistryTest {
|
|
+final class MetricRegistryTest {
|
|
|
|
private MetricRegistry metricRegistry = new MetricRegistry();
|
|
|
|
@Test
|
|
- void testRegisterMetric() {
|
|
+ void registerMetric() {
|
|
Counter counter = metricRegistry.register("test-counter", new Counter());
|
|
counter.inc(42);
|
|
assertThat(metricRegistry.counter("test-counter").getCount()).isEqualTo(42);
|
|
}
|
|
|
|
@Test
|
|
- void testRegisterAll() {
|
|
+ void registerAll() {
|
|
metricRegistry.registerAll(
|
|
() -> {
|
|
Map<String, Metric> map = new HashMap<>();
|
|
@@ -40,26 +40,26 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testRegisterGauge() {
|
|
+ void registerGauge() {
|
|
metricRegistry.registerGauge("test-gauge", () -> 42);
|
|
assertThat(metricRegistry.getGauges().get("test-gauge").getValue()).isEqualTo(42);
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCustomGauge() {
|
|
+ void createCustomGauge() {
|
|
Gauge gauge = metricRegistry.gauge("test-gauge-supplier", () -> () -> 42);
|
|
assertThat(gauge.getValue()).isEqualTo(42);
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCounter() {
|
|
+ void createCounter() {
|
|
Counter counter = metricRegistry.counter("test-counter");
|
|
counter.inc(42);
|
|
assertThat(metricRegistry.counter("test-counter").getCount()).isEqualTo(42);
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCustomCounter() {
|
|
+ void createCustomCounter() {
|
|
Counter counter =
|
|
metricRegistry.counter(
|
|
"test-custom-counter",
|
|
@@ -73,7 +73,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateHistogram() {
|
|
+ void createHistogram() {
|
|
Histogram histogram = metricRegistry.histogram("test-histogram");
|
|
histogram.update(100);
|
|
histogram.update(200);
|
|
@@ -83,7 +83,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCustomHistogram() {
|
|
+ void createCustomHistogram() {
|
|
Histogram histogram =
|
|
metricRegistry.histogram(
|
|
"test-custom-histogram", () -> new Histogram(new SlidingWindowReservoir(2)));
|
|
@@ -95,7 +95,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateMeter() {
|
|
+ void createMeter() {
|
|
Meter meter = metricRegistry.meter("test-meter");
|
|
meter.mark();
|
|
meter.mark(2);
|
|
@@ -104,7 +104,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCustomMeter() {
|
|
+ void createCustomMeter() {
|
|
Meter meter =
|
|
metricRegistry.meter(
|
|
"test-custom-meter",
|
|
@@ -119,7 +119,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateTimer() {
|
|
+ void createTimer() {
|
|
Timer timer = metricRegistry.timer("test-timer");
|
|
timer.update(100, TimeUnit.MILLISECONDS);
|
|
timer.update(200, TimeUnit.MILLISECONDS);
|
|
@@ -129,7 +129,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateCustomTimer() {
|
|
+ void createCustomTimer() {
|
|
Timer timer =
|
|
metricRegistry.timer(
|
|
"custom-test-timer",
|
|
@@ -145,7 +145,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testRemoveMetric() {
|
|
+ void removeMetric() {
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -156,7 +156,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testRemoveMatching() {
|
|
+ void removeMatching() {
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.timer("test-custom-timer");
|
|
@@ -168,7 +168,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddListenerForGauge() throws Exception {
|
|
+ void addListenerForGauge() throws Exception {
|
|
CountDownLatch gaugeAddedLatch = new CountDownLatch(1);
|
|
CountDownLatch gaugeRemovedLatch = new CountDownLatch(1);
|
|
metricRegistry.addListener(
|
|
@@ -197,7 +197,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddListenerForCounter() throws Exception {
|
|
+ void addListenerForCounter() throws Exception {
|
|
CountDownLatch counterAddedLatch = new CountDownLatch(1);
|
|
CountDownLatch counterRemovedLatch = new CountDownLatch(1);
|
|
metricRegistry.addListener(
|
|
@@ -225,7 +225,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddListenerForHistogram() throws Exception {
|
|
+ void addListenerForHistogram() throws Exception {
|
|
CountDownLatch histogramAddedLatch = new CountDownLatch(1);
|
|
CountDownLatch histogramRemovedLatch = new CountDownLatch(1);
|
|
metricRegistry.addListener(
|
|
@@ -254,7 +254,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddListenerForMeter() throws Exception {
|
|
+ void addListenerForMeter() throws Exception {
|
|
CountDownLatch meterAddedLatch = new CountDownLatch(1);
|
|
CountDownLatch meterRemovedLatch = new CountDownLatch(1);
|
|
metricRegistry.addListener(
|
|
@@ -283,7 +283,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddListenerForTimer() throws Exception {
|
|
+ void addListenerForTimer() throws Exception {
|
|
CountDownLatch timerAddedLatch = new CountDownLatch(1);
|
|
CountDownLatch timerRemovedLatch = new CountDownLatch(1);
|
|
metricRegistry.addListener(
|
|
@@ -312,7 +312,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testRemoveListener() throws Exception {
|
|
+ void removeListener() throws Exception {
|
|
CountDownLatch gaugeAddedLatch = new CountDownLatch(1);
|
|
MetricRegistryListener listener =
|
|
new MetricRegistryListener.Base() {
|
|
@@ -331,7 +331,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetNames() {
|
|
+ void getNames() {
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.timer("test-custom-timer");
|
|
@@ -342,7 +342,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetGauges() {
|
|
+ void getGauges() {
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -369,7 +369,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetGaugesWithFilter() {
|
|
+ void getGaugesWithFilter() {
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -398,7 +398,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetHistograms() {
|
|
+ void getHistograms() {
|
|
metricRegistry.counter("test-counter");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -411,7 +411,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetHistogramsWithFilter() {
|
|
+ void getHistogramsWithFilter() {
|
|
metricRegistry.counter("sw-counter");
|
|
metricRegistry.timer("sw-timer");
|
|
metricRegistry.meter("sw-meter");
|
|
@@ -424,7 +424,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetCounters() {
|
|
+ void getCounters() {
|
|
metricRegistry.histogram("test-histogram");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -437,7 +437,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetCountersWithFilter() {
|
|
+ void getCountersWithFilter() {
|
|
metricRegistry.histogram("test-histogram");
|
|
metricRegistry.timer("test-timer");
|
|
metricRegistry.meter("test-meter");
|
|
@@ -450,7 +450,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetMeters() {
|
|
+ void getMeters() {
|
|
metricRegistry.register("test-gauge", (Gauge<Integer>) () -> 42);
|
|
metricRegistry.histogram("test-histogram");
|
|
metricRegistry.timer("test-timer");
|
|
@@ -464,7 +464,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetMetersWithFilter() {
|
|
+ void getMetersWithFilter() {
|
|
metricRegistry.register("sw-gauge", (Gauge<Integer>) () -> 42);
|
|
metricRegistry.histogram("sw-histogram");
|
|
metricRegistry.timer("sw-timer");
|
|
@@ -478,7 +478,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetTimers() {
|
|
+ void getTimers() {
|
|
metricRegistry.histogram("test-histogram");
|
|
metricRegistry.meter("test-meter");
|
|
metricRegistry.counter("test-counter");
|
|
@@ -491,7 +491,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetTimersWithFilter() {
|
|
+ void getTimersWithFilter() {
|
|
metricRegistry.histogram("test-histogram-2");
|
|
metricRegistry.meter("test-meter-2");
|
|
metricRegistry.counter("test-counter-2");
|
|
@@ -504,7 +504,7 @@ class MetricRegistryTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetMetrics() {
|
|
+ void getMetrics() {
|
|
metricRegistry.register(
|
|
"test-text-gauge-2",
|
|
new CachedGauge<String>(1, TimeUnit.MINUTES) {
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/RatioGaugeTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/RatioGaugeTest.java
|
|
@@ -1,12 +1,12 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class RatioGaugeTest {
|
|
+final class RatioGaugeTest {
|
|
|
|
private RatioGauge ratioGauge =
|
|
new RatioGauge() {
|
|
@@ -17,12 +17,12 @@ class RatioGaugeTest {
|
|
};
|
|
|
|
@Test
|
|
- void testViewRatin() {
|
|
- assertThat(ratioGauge.getRatio().toString()).isEqualTo("1.0:3.0");
|
|
+ void viewRatin() {
|
|
+ assertThat(ratioGauge.getRatio()).hasToString("1.0:3.0");
|
|
}
|
|
|
|
@Test
|
|
- void testCalculateRatio() {
|
|
- assertThat(ratioGauge.getValue()).isCloseTo(0.33, Offset.offset(0.01));
|
|
+ void calculateRatio() {
|
|
+ assertThat(ratioGauge.getValue()).isCloseTo(0.33, offset(0.01));
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ScheduledReporterTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/ScheduledReporterTest.java
|
|
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class ScheduledReporterTest {
|
|
+final class ScheduledReporterTest {
|
|
|
|
private MetricRegistry metricRegistry = new MetricRegistry();
|
|
private ScheduledReporter scheduledReporter;
|
|
@@ -51,7 +51,7 @@ class ScheduledReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testReport() throws Exception {
|
|
+ void report() throws Exception {
|
|
CountDownLatch latch = new CountDownLatch(1);
|
|
scheduledReporter = createScheduledReporter(latch);
|
|
scheduledReporter.report();
|
|
@@ -61,7 +61,7 @@ class ScheduledReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testStart() throws Exception {
|
|
+ void start() throws Exception {
|
|
CountDownLatch latch = new CountDownLatch(2);
|
|
scheduledReporter = createScheduledReporter(latch);
|
|
scheduledReporter.start(10, TimeUnit.MILLISECONDS);
|
|
@@ -71,7 +71,7 @@ class ScheduledReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testStartWithoutDelay() throws Exception {
|
|
+ void startWithoutDelay() throws Exception {
|
|
CountDownLatch latch = new CountDownLatch(2);
|
|
scheduledReporter = createScheduledReporter(latch);
|
|
scheduledReporter.start(0, 10, TimeUnit.MILLISECONDS);
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SharedMetricRegistriesTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SharedMetricRegistriesTest.java
|
|
@@ -1,13 +1,13 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class SharedMetricRegistriesTest {
|
|
+final class SharedMetricRegistriesTest {
|
|
|
|
@AfterEach
|
|
void tearDown() throws Exception {
|
|
@@ -15,7 +15,7 @@ class SharedMetricRegistriesTest {
|
|
}
|
|
|
|
@Test
|
|
- void testGetOrCreateMetricRegistry() {
|
|
+ void getOrCreateMetricRegistry() {
|
|
SharedMetricRegistries.getOrCreate("get-or-create").counter("test-counter");
|
|
|
|
assertThat(SharedMetricRegistries.getOrCreate("get-or-create").getCounters())
|
|
@@ -23,7 +23,7 @@ class SharedMetricRegistriesTest {
|
|
}
|
|
|
|
@Test
|
|
- void testAddMetricRegistry() {
|
|
+ void addMetricRegistry() {
|
|
MetricRegistry metricRegistry = new MetricRegistry();
|
|
metricRegistry.histogram("test-histogram");
|
|
SharedMetricRegistries.add("add", metricRegistry);
|
|
@@ -33,7 +33,7 @@ class SharedMetricRegistriesTest {
|
|
}
|
|
|
|
@Test
|
|
- void testNames() {
|
|
+ void names() {
|
|
SharedMetricRegistries.add("registry-1", new MetricRegistry());
|
|
SharedMetricRegistries.add("registry-2", new MetricRegistry());
|
|
SharedMetricRegistries.add("registry-3", new MetricRegistry());
|
|
@@ -43,12 +43,13 @@ class SharedMetricRegistriesTest {
|
|
}
|
|
|
|
@Test
|
|
- void testTryGetDefaultRegistry() {
|
|
+ void tryGetDefaultRegistry() {
|
|
assertThat(SharedMetricRegistries.tryGetDefault()).isNull();
|
|
}
|
|
|
|
@Test
|
|
- void testGetDefaultRegistry() {
|
|
- assertThatIllegalStateException().isThrownBy(SharedMetricRegistries::getDefault);
|
|
+ void getDefaultRegistry() {
|
|
+ assertThatThrownBy(SharedMetricRegistries::getDefault)
|
|
+ .isInstanceOf(IllegalStateException.class);
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/Slf4jReporterTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/Slf4jReporterTest.java
|
|
@@ -14,11 +14,11 @@ import org.slf4j.Logger;
|
|
import org.slf4j.Marker;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class Slf4jReporterTest {
|
|
+final class Slf4jReporterTest {
|
|
|
|
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
|
- private Logger logger = mock(Logger.class);
|
|
- private Marker marker = mock(Marker.class);
|
|
+ private Logger logger = mock();
|
|
+ private Marker marker = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() throws Exception {
|
|
@@ -31,7 +31,7 @@ class Slf4jReporterTest {
|
|
}
|
|
|
|
@Test
|
|
- void testReport() throws Exception {
|
|
+ void report() throws Exception {
|
|
MetricRegistry metricRegistry = new MetricRegistry();
|
|
metricRegistry.counter("test-counter").inc(100);
|
|
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingTimeWindowArrayReservoirTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingTimeWindowArrayReservoirTest.java
|
|
@@ -1,16 +1,16 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class SlidingTimeWindowArrayReservoirTest {
|
|
+final class SlidingTimeWindowArrayReservoirTest {
|
|
|
|
@Test
|
|
- void testCreateWithWindow() {
|
|
+ void createWithWindow() {
|
|
SlidingTimeWindowArrayReservoir reservoir =
|
|
new SlidingTimeWindowArrayReservoir(1, TimeUnit.HOURS);
|
|
reservoir.update(100);
|
|
@@ -18,17 +18,17 @@ class SlidingTimeWindowArrayReservoirTest {
|
|
reservoir.update(30);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(3);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(110, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(110, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWithWindowAndClock() {
|
|
+ void createWithWindowAndClock() {
|
|
SlidingTimeWindowArrayReservoir reservoir =
|
|
new SlidingTimeWindowArrayReservoir(1, TimeUnit.HOURS, new Clock.UserTimeClock());
|
|
reservoir.update(400);
|
|
reservoir.update(300);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(2);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(350, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(350, offset(0.1));
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingTimeWindowReservoirTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingTimeWindowReservoirTest.java
|
|
@@ -1,33 +1,33 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class SlidingTimeWindowReservoirTest {
|
|
+final class SlidingTimeWindowReservoirTest {
|
|
|
|
@Test
|
|
- void testCreateWithWindow() {
|
|
+ void createWithWindow() {
|
|
SlidingTimeWindowReservoir reservoir = new SlidingTimeWindowReservoir(1, TimeUnit.HOURS);
|
|
reservoir.update(100);
|
|
reservoir.update(200);
|
|
reservoir.update(30);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(3);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(110, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(110, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWithWindowAndClock() {
|
|
+ void createWithWindowAndClock() {
|
|
SlidingTimeWindowReservoir reservoir =
|
|
new SlidingTimeWindowReservoir(1, TimeUnit.HOURS, new Clock.UserTimeClock());
|
|
reservoir.update(400);
|
|
reservoir.update(300);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(2);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(350, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(350, offset(0.1));
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingWindowReservoirTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SlidingWindowReservoirTest.java
|
|
@@ -1,26 +1,26 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class SlidingWindowReservoirTest {
|
|
+final class SlidingWindowReservoirTest {
|
|
|
|
@Test
|
|
- void testCreateWithBigWindow() {
|
|
+ void createWithBigWindow() {
|
|
SlidingWindowReservoir reservoir = new SlidingWindowReservoir(100);
|
|
reservoir.update(100);
|
|
reservoir.update(220);
|
|
reservoir.update(130);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(3);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(150, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(150, offset(0.1));
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWithLowWindow() {
|
|
+ void createWithLowWindow() {
|
|
SlidingWindowReservoir reservoir = new SlidingWindowReservoir(3);
|
|
reservoir.update(500);
|
|
reservoir.update(220);
|
|
@@ -28,6 +28,6 @@ class SlidingWindowReservoirTest {
|
|
reservoir.update(40);
|
|
|
|
assertThat(reservoir.size()).isEqualTo(3);
|
|
- assertThat(reservoir.getSnapshot().getMean()).isCloseTo(120, Offset.offset(0.1));
|
|
+ assertThat(reservoir.getSnapshot().getMean()).isCloseTo(120, offset(0.1));
|
|
}
|
|
}
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SnapshotTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/SnapshotTest.java
|
|
@@ -1,30 +1,30 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
import io.dropwizard.metrics5.UniformSnapshot;
|
|
import java.io.ByteArrayOutputStream;
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class SnapshotTest {
|
|
+final class SnapshotTest {
|
|
|
|
@Test
|
|
- void testCreateSnapshot() throws Exception {
|
|
+ void createSnapshot() throws Exception {
|
|
Snapshot snapshot = Snapshot.of(new UniformSnapshot(new long[] {5, 1, 2, 3, 4}));
|
|
|
|
assertThat(snapshot.getValues()).isEqualTo(new long[] {1, 2, 3, 4, 5});
|
|
assertThat(snapshot.size()).isEqualTo(5);
|
|
assertThat(snapshot.getMin()).isEqualTo(1);
|
|
assertThat(snapshot.getMax()).isEqualTo(5);
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(1.58, Offset.offset(0.01));
|
|
- assertThat(snapshot.getMedian()).isEqualTo(3, Offset.offset(0.01));
|
|
- assertThat(snapshot.get75thPercentile()).isEqualTo(4.5, Offset.offset(0.01));
|
|
- assertThat(snapshot.get95thPercentile()).isEqualTo(5, Offset.offset(0.01));
|
|
- assertThat(snapshot.get98thPercentile()).isEqualTo(5, Offset.offset(0.01));
|
|
- assertThat(snapshot.get99thPercentile()).isEqualTo(5, Offset.offset(0.01));
|
|
- assertThat(snapshot.get999thPercentile()).isEqualTo(5, Offset.offset(0.01));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(1.58, offset(0.01));
|
|
+ assertThat(snapshot.getMedian()).isCloseTo(3, offset(0.01));
|
|
+ assertThat(snapshot.get75thPercentile()).isCloseTo(4.5, offset(0.01));
|
|
+ assertThat(snapshot.get95thPercentile()).isCloseTo(5, offset(0.01));
|
|
+ assertThat(snapshot.get98thPercentile()).isCloseTo(5, offset(0.01));
|
|
+ assertThat(snapshot.get99thPercentile()).isCloseTo(5, offset(0.01));
|
|
+ assertThat(snapshot.get999thPercentile()).isCloseTo(5, offset(0.01));
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
snapshot.dump(baos);
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/TimerTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/TimerTest.java
|
|
@@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class TimerTest {
|
|
+final class TimerTest {
|
|
|
|
private static class ManualClock extends Clock {
|
|
|
|
@@ -26,7 +26,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreate() {
|
|
+ void create() {
|
|
Timer timer = new Timer();
|
|
timer.update(100, TimeUnit.MILLISECONDS);
|
|
timer.update(200, TimeUnit.MILLISECONDS);
|
|
@@ -35,7 +35,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWithCustomReservoir() {
|
|
+ void createWithCustomReservoir() {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100));
|
|
timer.update(100, TimeUnit.MILLISECONDS);
|
|
timer.update(200, TimeUnit.MILLISECONDS);
|
|
@@ -44,7 +44,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateWithCustomReservoirAndClock() {
|
|
+ void createWithCustomReservoirAndClock() {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100), new Clock.UserTimeClock());
|
|
timer.update(100, TimeUnit.MILLISECONDS);
|
|
timer.update(200, TimeUnit.MILLISECONDS);
|
|
@@ -53,7 +53,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testTimerContext() {
|
|
+ void timerContext() {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100), new ManualClock());
|
|
timer.time().stop();
|
|
|
|
@@ -61,7 +61,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testTimerRunnable() {
|
|
+ void timerRunnable() {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100), new ManualClock());
|
|
|
|
AtomicInteger counter = new AtomicInteger();
|
|
@@ -72,7 +72,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testTimerCallable() throws Exception {
|
|
+ void timerCallable() throws Exception {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100), new ManualClock());
|
|
|
|
String message = timer.time(() -> "SUCCESS");
|
|
@@ -82,7 +82,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testTimerSupplier() throws Exception {
|
|
+ void timerSupplier() throws Exception {
|
|
Timer timer = new Timer(new SlidingWindowReservoir(100), new ManualClock());
|
|
|
|
Integer result = timer.timeSupplier(() -> 42);
|
|
@@ -92,7 +92,7 @@ class TimerTest {
|
|
}
|
|
|
|
@Test
|
|
- void testUpdateDuration() {
|
|
+ void updateDuration() {
|
|
Timer timer = new Timer();
|
|
timer.update(Duration.ofMillis(100));
|
|
timer.update(Duration.ofMillis(200));
|
|
--- a/metrics-legacy-adapter/src/test/java/com/codahale/metrics/UniformReservoirTest.java
|
|
+++ b/metrics-legacy-adapter/src/test/java/com/codahale/metrics/UniformReservoirTest.java
|
|
@@ -1,15 +1,15 @@
|
|
package com.codahale.metrics;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.assertj.core.data.Offset.offset;
|
|
|
|
-import org.assertj.core.data.Offset;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
-class UniformReservoirTest {
|
|
+final class UniformReservoirTest {
|
|
|
|
@Test
|
|
- void testCreateReservoir() {
|
|
+ void createReservoir() {
|
|
UniformReservoir reservoir = new UniformReservoir();
|
|
reservoir.update(120);
|
|
reservoir.update(190);
|
|
@@ -22,7 +22,7 @@ class UniformReservoirTest {
|
|
assertThat(snapshot.getValues()).contains(120, 130, 140, 190, 200);
|
|
assertThat(snapshot.getMin()).isEqualTo(120);
|
|
assertThat(snapshot.getMax()).isEqualTo(200);
|
|
- assertThat(snapshot.getStdDev()).isEqualTo(36.47, Offset.offset(0.1));
|
|
+ assertThat(snapshot.getStdDev()).isCloseTo(36.47, offset(0.1));
|
|
assertThat(snapshot.get75thPercentile()).isEqualTo(195);
|
|
assertThat(snapshot.get95thPercentile()).isEqualTo(200);
|
|
assertThat(snapshot.get98thPercentile()).isEqualTo(200);
|
|
@@ -31,7 +31,7 @@ class UniformReservoirTest {
|
|
}
|
|
|
|
@Test
|
|
- void testCreateReservoirWithCustomSize() {
|
|
+ void createReservoirWithCustomSize() {
|
|
UniformReservoir reservoir = new UniformReservoir(128);
|
|
reservoir.update(440);
|
|
reservoir.update(250);
|
|
--- a/metrics-log4j2/src/test/java/io/dropwizard/metrics5/log4j2/InstrumentedAppenderConfigTest.java
|
|
+++ b/metrics-log4j2/src/test/java/io/dropwizard/metrics5/log4j2/InstrumentedAppenderConfigTest.java
|
|
@@ -12,7 +12,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedAppenderConfigTest {
|
|
+final class InstrumentedAppenderConfigTest {
|
|
public static final String METRIC_NAME_PREFIX = "metrics";
|
|
public static final String REGISTRY_NAME = "shared-metrics-registry";
|
|
|
|
--- a/metrics-log4j2/src/test/java/io/dropwizard/metrics5/log4j2/InstrumentedAppenderTest.java
|
|
+++ b/metrics-log4j2/src/test/java/io/dropwizard/metrics5/log4j2/InstrumentedAppenderTest.java
|
|
@@ -12,13 +12,13 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedAppenderTest {
|
|
+final class InstrumentedAppenderTest {
|
|
|
|
public static final String METRIC_NAME_PREFIX = "org.apache.logging.log4j.core.Appender";
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final InstrumentedAppender appender = new InstrumentedAppender(registry);
|
|
- private final LogEvent event = mock(LogEvent.class);
|
|
+ private final LogEvent event = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
--- a/metrics-logback13/src/test/java/io/dropwizard/metrics/logback13/InstrumentedAppenderTest.java
|
|
+++ b/metrics-logback13/src/test/java/io/dropwizard/metrics/logback13/InstrumentedAppenderTest.java
|
|
@@ -12,13 +12,13 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedAppenderTest {
|
|
+final class InstrumentedAppenderTest {
|
|
|
|
public static final String METRIC_NAME_PREFIX = "ch.qos.logback.core.Appender";
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final InstrumentedAppender appender = new InstrumentedAppender(registry);
|
|
- private final ILoggingEvent event = mock(ILoggingEvent.class);
|
|
+ private final ILoggingEvent event = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
--- a/metrics-logback14/src/test/java/io/dropwizard/metrics/logback14/InstrumentedAppenderTest.java
|
|
+++ b/metrics-logback14/src/test/java/io/dropwizard/metrics/logback14/InstrumentedAppenderTest.java
|
|
@@ -12,13 +12,13 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedAppenderTest {
|
|
+final class InstrumentedAppenderTest {
|
|
|
|
public static final String METRIC_NAME_PREFIX = "ch.qos.logback.core.Appender";
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final InstrumentedAppender appender = new InstrumentedAppender(registry);
|
|
- private final ILoggingEvent event = mock(ILoggingEvent.class);
|
|
+ private final ILoggingEvent event = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
--- a/metrics-logback15/src/test/java/io/dropwizard/metrics5/logback15/InstrumentedAppenderTest.java
|
|
+++ b/metrics-logback15/src/test/java/io/dropwizard/metrics5/logback15/InstrumentedAppenderTest.java
|
|
@@ -12,13 +12,13 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class InstrumentedAppenderTest {
|
|
+final class InstrumentedAppenderTest {
|
|
|
|
public static final String METRIC_NAME_PREFIX = "ch.qos.logback.core.Appender";
|
|
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final InstrumentedAppender appender = new InstrumentedAppender(registry);
|
|
- private final ILoggingEvent event = mock(ILoggingEvent.class);
|
|
+ private final ILoggingEvent event = mock();
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
--- a/metrics-servlet/src/main/java/io/dropwizard/metrics5/servlet/AbstractInstrumentedFilter.java
|
|
+++ b/metrics-servlet/src/main/java/io/dropwizard/metrics5/servlet/AbstractInstrumentedFilter.java
|
|
@@ -2,6 +2,7 @@ package io.dropwizard.metrics5.servlet;
|
|
|
|
import static io.dropwizard.metrics5.MetricRegistry.name;
|
|
|
|
+import com.google.common.base.Strings;
|
|
import io.dropwizard.metrics5.Counter;
|
|
import io.dropwizard.metrics5.Meter;
|
|
import io.dropwizard.metrics5.MetricRegistry;
|
|
@@ -64,7 +65,7 @@ public abstract class AbstractInstrumentedFilter implements Filter {
|
|
final MetricRegistry metricsRegistry = getMetricsFactory(filterConfig);
|
|
|
|
String metricName = filterConfig.getInitParameter(METRIC_PREFIX);
|
|
- if (metricName == null || metricName.isEmpty()) {
|
|
+ if (Strings.isNullOrEmpty(metricName)) {
|
|
metricName = getClass().getName();
|
|
}
|
|
|
|
--- a/metrics-servlet/src/test/java/io/dropwizard/metrics5/servlet/InstrumentedFilterContextListenerTest.java
|
|
+++ b/metrics-servlet/src/test/java/io/dropwizard/metrics5/servlet/InstrumentedFilterContextListenerTest.java
|
|
@@ -9,8 +9,8 @@ import javax.servlet.ServletContext;
|
|
import javax.servlet.ServletContextEvent;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class InstrumentedFilterContextListenerTest {
|
|
- private final MetricRegistry registry = mock(MetricRegistry.class);
|
|
+final class InstrumentedFilterContextListenerTest {
|
|
+ private final MetricRegistry registry = mock();
|
|
private final InstrumentedFilterContextListener listener =
|
|
new InstrumentedFilterContextListener() {
|
|
@Override
|
|
@@ -21,9 +21,9 @@ class InstrumentedFilterContextListenerTest {
|
|
|
|
@Test
|
|
void injectsTheMetricRegistryIntoTheServletContext() {
|
|
- final ServletContext context = mock(ServletContext.class);
|
|
+ final ServletContext context = mock();
|
|
|
|
- final ServletContextEvent event = mock(ServletContextEvent.class);
|
|
+ final ServletContextEvent event = mock();
|
|
when(event.getServletContext()).thenReturn(context);
|
|
|
|
listener.contextInitialized(event);
|
|
--- a/metrics-servlets/src/main/java/io/dropwizard/metrics5/servlets/HealthCheckServlet.java
|
|
+++ b/metrics-servlets/src/main/java/io/dropwizard/metrics5/servlets/HealthCheckServlet.java
|
|
@@ -99,7 +99,7 @@ public class HealthCheckServlet extends HttpServlet {
|
|
super.init(config);
|
|
|
|
final ServletContext context = config.getServletContext();
|
|
- if (null == registry) {
|
|
+ if (registry == null) {
|
|
final Object registryAttr = context.getAttribute(HEALTH_CHECK_REGISTRY);
|
|
if (registryAttr instanceof HealthCheckRegistry) {
|
|
this.registry = (HealthCheckRegistry) registryAttr;
|
|
--- a/metrics-servlets/src/main/java/io/dropwizard/metrics5/servlets/MetricsServlet.java
|
|
+++ b/metrics-servlets/src/main/java/io/dropwizard/metrics5/servlets/MetricsServlet.java
|
|
@@ -131,7 +131,7 @@ public class MetricsServlet extends HttpServlet {
|
|
super.init(config);
|
|
|
|
final ServletContext context = config.getServletContext();
|
|
- if (null == registry) {
|
|
+ if (registry == null) {
|
|
final Object registryAttr = context.getAttribute(METRICS_REGISTRY);
|
|
if (registryAttr instanceof MetricRegistry) {
|
|
this.registry = (MetricRegistry) registryAttr;
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletTest.java
|
|
@@ -9,7 +9,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class AdminServletTest extends AbstractServletTest {
|
|
+final class AdminServletTest extends AbstractServletTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
|
|
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletUriTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/AdminServletUriTest.java
|
|
@@ -9,7 +9,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class AdminServletUriTest extends AbstractServletTest {
|
|
+final class AdminServletUriTest extends AbstractServletTest {
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
|
|
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/CpuProfileServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/CpuProfileServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class CpuProfileServletTest extends AbstractServletTest {
|
|
+final class CpuProfileServletTest extends AbstractServletTest {
|
|
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/HealthCheckServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/HealthCheckServletTest.java
|
|
@@ -1,10 +1,9 @@
|
|
package io.dropwizard.metrics5.servlets;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
-import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@@ -27,7 +26,7 @@ import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class HealthCheckServletTest extends AbstractServletTest {
|
|
+final class HealthCheckServletTest extends AbstractServletTest {
|
|
|
|
private static final ZonedDateTime FIXED_TIME = ZonedDateTime.now();
|
|
|
|
@@ -95,9 +94,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\"}}");
|
|
+ "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"%s\"}}",
|
|
+ EXPECTED_TIMESTAMP);
|
|
}
|
|
|
|
@Test
|
|
@@ -111,9 +109,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\"}}");
|
|
+ "{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"%s\"}}",
|
|
+ EXPECTED_TIMESTAMP);
|
|
}
|
|
|
|
@Test
|
|
@@ -168,15 +165,8 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
String.format(
|
|
- "{%n"
|
|
- + " \"fun\" : {%n"
|
|
- + " \"healthy\" : true,%n"
|
|
- + " \"message\" : \"foo bar 123\",%n"
|
|
- + " \"duration\" : 0,%n"
|
|
- + " \"timestamp\" : \""
|
|
- + EXPECTED_TIMESTAMP
|
|
- + "\""
|
|
- + "%n }%n}"));
|
|
+ "{%n \"fun\" : {%n \"healthy\" : true,%n \"message\" : \"foo bar 123\",%n \"duration\" : 0,%n \"timestamp\" : \"%s\"%n }%n}",
|
|
+ EXPECTED_TIMESTAMP));
|
|
}
|
|
|
|
private static HealthCheck.Result healthyResultWithMessage(String message) {
|
|
@@ -197,23 +187,23 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
|
|
- final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final HealthCheckRegistry healthCheckRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
|
|
final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(healthCheckRegistry);
|
|
healthCheckServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
+ verify(servletConfig).getServletContext();
|
|
verify(servletContext, never()).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
|
|
- final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final HealthCheckRegistry healthCheckRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
.thenReturn(healthCheckRegistry);
|
|
@@ -221,32 +211,32 @@ class HealthCheckServletTest extends AbstractServletTest {
|
|
final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
healthCheckServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, times(1)).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- assertThrows(
|
|
- ServletException.class,
|
|
- () -> {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
- when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
- .thenReturn("IRELLEVANT_STRING");
|
|
-
|
|
- final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
- healthCheckServlet.init(servletConfig);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
+ when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
+ when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
+ .thenReturn("IRELLEVANT_STRING");
|
|
+
|
|
+ final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
|
|
+ healthCheckServlet.init(servletConfig);
|
|
+ })
|
|
+ .isInstanceOf(ServletException.class);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithObjectMapperAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY))
|
|
.thenReturn(registry);
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletContextListenerTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletContextListenerTest.java
|
|
@@ -17,8 +17,8 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricsServletContextListenerTest extends AbstractServletTest {
|
|
- private final Clock clock = mock(Clock.class);
|
|
+final class MetricsServletContextListenerTest extends AbstractServletTest {
|
|
+ private final Clock clock = mock();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private final String allowedOrigin = "some.other.origin";
|
|
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/MetricsServletTest.java
|
|
@@ -1,11 +1,9 @@
|
|
package io.dropwizard.metrics5.servlets;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
-import static org.mockito.ArgumentMatchers.eq;
|
|
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.never;
|
|
-import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@@ -25,8 +23,8 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class MetricsServletTest extends AbstractServletTest {
|
|
- private final Clock clock = mock(Clock.class);
|
|
+final class MetricsServletTest extends AbstractServletTest {
|
|
+ private final Clock clock = mock();
|
|
private final MetricRegistry registry = new MetricRegistry();
|
|
private ServletTester tester;
|
|
|
|
@@ -130,22 +128,8 @@ class MetricsServletTest extends AbstractServletTest {
|
|
assertThat(response.get("Access-Control-Allow-Origin")).isEqualTo("*");
|
|
assertThat(response.getContent())
|
|
.isEqualTo(
|
|
- callbackParamVal
|
|
- + "({"
|
|
- + "\"version\":\"5.0.0\","
|
|
- + "\"gauges\":{"
|
|
- + "\"g1\":{\"value\":100}"
|
|
- + "},"
|
|
- + "\"counters\":{"
|
|
- + "\"c\":{\"count\":1}"
|
|
- + "},"
|
|
- + "\"histograms\":{"
|
|
- + "\"h\":{\"count\":1,\"max\":1,\"mean\":1.0,\"min\":1,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0}"
|
|
- + "},"
|
|
- + "\"meters\":{"
|
|
- + "\"m\":{\"count\":1,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":3333333.3333333335,\"units\":\"events/second\"}},\"timers\":{\"t\":{\"count\":1,\"max\":1.0,\"mean\":1.0,\"min\":1.0,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":1.0E7,\"duration_units\":\"seconds\",\"rate_units\":\"calls/second\"}"
|
|
- + "}"
|
|
- + "})");
|
|
+ "%s({\"version\":\"5.0.0\",\"gauges\":{\"g1\":{\"value\":100}},\"counters\":{\"c\":{\"count\":1}},\"histograms\":{\"h\":{\"count\":1,\"max\":1,\"mean\":1.0,\"min\":1,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0}},\"meters\":{\"m\":{\"count\":1,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":3333333.3333333335,\"units\":\"events/second\"}},\"timers\":{\"t\":{\"count\":1,\"max\":1.0,\"mean\":1.0,\"min\":1.0,\"p50\":1.0,\"p75\":1.0,\"p95\":1.0,\"p98\":1.0,\"p99\":1.0,\"p999\":1.0,\"stddev\":0.0,\"m15_rate\":0.0,\"m1_rate\":0.0,\"m5_rate\":0.0,\"mean_rate\":1.0E7,\"duration_units\":\"seconds\",\"rate_units\":\"calls/second\"}}})",
|
|
+ callbackParamVal);
|
|
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
|
|
}
|
|
|
|
@@ -224,48 +208,47 @@ class MetricsServletTest extends AbstractServletTest {
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
|
|
- final MetricRegistry metricRegistry = mock(MetricRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final MetricRegistry metricRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
|
|
final MetricsServlet metricsServlet = new MetricsServlet(metricRegistry);
|
|
metricsServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, never()).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext, never()).getAttribute(MetricsServlet.METRICS_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
|
|
- final MetricRegistry metricRegistry = mock(MetricRegistry.class);
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
+ final MetricRegistry metricRegistry = mock();
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(eq(MetricsServlet.METRICS_REGISTRY)))
|
|
- .thenReturn(metricRegistry);
|
|
+ when(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).thenReturn(metricRegistry);
|
|
|
|
final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
metricsServlet.init(servletConfig);
|
|
|
|
- verify(servletConfig, times(1)).getServletContext();
|
|
- verify(servletContext, times(1)).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
|
|
+ verify(servletConfig).getServletContext();
|
|
+ verify(servletContext).getAttribute(MetricsServlet.METRICS_REGISTRY);
|
|
}
|
|
|
|
@Test
|
|
void constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext()
|
|
throws Exception {
|
|
- assertThrows(
|
|
- ServletException.class,
|
|
- () -> {
|
|
- final ServletContext servletContext = mock(ServletContext.class);
|
|
- final ServletConfig servletConfig = mock(ServletConfig.class);
|
|
- when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
- when(servletContext.getAttribute(eq(MetricsServlet.METRICS_REGISTRY)))
|
|
- .thenReturn("IRELLEVANT_STRING");
|
|
-
|
|
- final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
- metricsServlet.init(servletConfig);
|
|
- });
|
|
+ assertThatThrownBy(
|
|
+ () -> {
|
|
+ final ServletContext servletContext = mock();
|
|
+ final ServletConfig servletConfig = mock();
|
|
+ when(servletConfig.getServletContext()).thenReturn(servletContext);
|
|
+ when(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY))
|
|
+ .thenReturn("IRELLEVANT_STRING");
|
|
+
|
|
+ final MetricsServlet metricsServlet = new MetricsServlet(null);
|
|
+ metricsServlet.init(servletConfig);
|
|
+ })
|
|
+ .isInstanceOf(ServletException.class);
|
|
}
|
|
}
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/PingServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/PingServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class PingServletTest extends AbstractServletTest {
|
|
+final class PingServletTest extends AbstractServletTest {
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
tester.addServlet(PingServlet.class, "/ping");
|
|
--- a/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/ThreadDumpServletTest.java
|
|
+++ b/metrics-servlets/src/test/java/io/dropwizard/metrics5/servlets/ThreadDumpServletTest.java
|
|
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletTester;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-class ThreadDumpServletTest extends AbstractServletTest {
|
|
+final class ThreadDumpServletTest extends AbstractServletTest {
|
|
@Override
|
|
protected void setUp(ServletTester tester) {
|
|
tester.addServlet(ThreadDumpServlet.class, "/threads");
|