mirror of
https://github.com/google/nomulus
synced 2026-03-27 12:55:28 +00:00
Add a convenience method to clear all registered metrics
Also making these methods public so that other test methods can use them. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=174074038
This commit is contained in:
@@ -36,11 +36,10 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||
/** The canonical registry for metrics. The map key is the metric name. */
|
||||
private final ConcurrentHashMap<String, Metric<?>> registeredMetrics = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Production code must use {@link getDefault}, since this returns the {@link MetricRegistry}
|
||||
* that {@link MetricReporter} uses. Test code that does not use {@link MetricReporter} can
|
||||
* use this constructor to get an isolated instance of the registry.
|
||||
* Production code must use {@link #getDefault}, since this returns the {@link MetricRegistry}
|
||||
* that {@link MetricReporter} uses. Test code that does not use {@link MetricReporter} can use
|
||||
* this constructor to get an isolated instance of the registry.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public MetricRegistryImpl() {}
|
||||
@@ -144,11 +143,16 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||
* write intervals.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void unregisterMetric(String name) {
|
||||
public void unregisterMetric(String name) {
|
||||
registeredMetrics.remove(name);
|
||||
logger.info("Unregistered metric: " + name);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void unregisterAllMetrics() {
|
||||
registeredMetrics.clear();
|
||||
}
|
||||
|
||||
/** Registers a metric. */
|
||||
@VisibleForTesting
|
||||
void registerMetric(String name, Metric<?> metric) {
|
||||
|
||||
@@ -37,19 +37,14 @@ import org.junit.runners.JUnit4;
|
||||
@RunWith(JUnit4.class)
|
||||
public class MetricRegistryImplTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final LabelDescriptor label =
|
||||
LabelDescriptor.create("test_labelname", "test_labeldescription");
|
||||
|
||||
@After
|
||||
public void clearMetrics() {
|
||||
ImmutableList<Metric<?>> metrics = MetricRegistryImpl.getDefault().getRegisteredMetrics();
|
||||
|
||||
for (Metric<?> metric : metrics) {
|
||||
MetricRegistryImpl.getDefault().unregisterMetric(metric.getMetricSchema().name());
|
||||
}
|
||||
MetricRegistryImpl.getDefault().unregisterAllMetrics();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user