Skip to content

Commit

Permalink
Merge pull request #67 from newrelic/shut_down_client
Browse files Browse the repository at this point in the history
shut down the client when reporter shuts down.
  • Loading branch information
breedx-nr authored Jun 29, 2020
2 parents 12d0ca5 + fb6e1e9 commit 6351cc5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public void report(
timeTracker.tick();
}

@Override
public void close() {
super.close();
sender.shutdown();
}

private <T> Stream<Metric> transform(
Map<String, T> metrics, BiFunction<String, T, Collection<Metric>> supplier) {
return metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 6351cc5

Please sign in to comment.