diff --git a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporter.java b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporter.java index 6837151..465f62d 100644 --- a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporter.java +++ b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporter.java @@ -142,6 +142,12 @@ public void report( timeTracker.tick(); } + @Override + public void close() { + super.close(); + sender.shutdown(); + } + private Stream transform( Map metrics, BiFunction> supplier) { return metrics diff --git a/src/test/java/com/codahale/metrics/newrelic/NewRelicReporterTest.java b/src/test/java/com/codahale/metrics/newrelic/NewRelicReporterTest.java index d98c463..6605e2c 100644 --- a/src/test/java/com/codahale/metrics/newrelic/NewRelicReporterTest.java +++ b/src/test/java/com/codahale/metrics/newrelic/NewRelicReporterTest.java @@ -9,10 +9,16 @@ import static java.util.Collections.emptySet; import static java.util.Collections.singleton; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.newrelic.transformer.*; +import com.codahale.metrics.newrelic.transformer.CounterTransformer; +import com.codahale.metrics.newrelic.transformer.GaugeTransformer; +import com.codahale.metrics.newrelic.transformer.HistogramTransformer; +import com.codahale.metrics.newrelic.transformer.MeterTransformer; +import com.codahale.metrics.newrelic.transformer.TimerTransformer; import com.codahale.metrics.newrelic.util.TimeTracker; import com.newrelic.telemetry.Attributes; import com.newrelic.telemetry.TelemetryClient; @@ -188,4 +194,26 @@ void testStopRemovesListener() { verify(registry).removeListener(timerTransformer); verify(registry).removeListener(counterTransformer); } + + @Test + void testCloseCallsShutdownOnTelemetryClient() { + NewRelicReporter testClass = + new NewRelicReporter( + null, + metricRegistry, + null, + null, + TimeUnit.SECONDS, + TimeUnit.MILLISECONDS, + sender, + null, + null, + null, + null, + null, + null, + emptySet()); + testClass.close(); + verify(sender).shutdown(); + } }