DynamicMetricsManager { public void createOrUpdateSlidingWindowHistogram(String classSimpleName, String key, String metricName, long windowTimeMs, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = registerAndGetSlidingWindowHistogram(MetricRegistry.name(classSimpleName, key, metricName), windowTimeMs); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); } private  DynamicMetricsManager(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry, @Nullable String testName); static DynamicMetricsManager getInstance(); @SuppressWarnings("unchecked") T registerMetric(String simpleName, String key, String metricName, Class<T> metricClass); T registerMetric(String classSimpleName, String metricName, Class<T> metricClass); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String key, String metricName, Supplier<T> supplier); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String metricName, Supplier<T> supplier); void unregisterMetric(String simpleName, String key, String metricName); void unregisterMetric(String simpleName, String metricName); void createOrUpdateCounter(String classSimpleName, String key, String metricName, long value); void createOrUpdateCounter(String classSimpleName, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String key, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String metricName, long value); void createOrUpdateSlidingWindowHistogram(String classSimpleName, String key, String metricName,
      long windowTimeMs, long value); void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value); void createOrUpdateHistogram(String classSimpleName, String metricName, long value); @SuppressWarnings("unchecked") T getMetric(String name); MetricRegistry getMetricRegistry();  }
@Test public void testCreateOrUpdateSlidingWindowHistogram() throws Exception { long highLatency = 10000; _metricsManager.createOrUpdateSlidingWindowHistogram(CLASS_NAME, "test", "latency", 1, highLatency); Thread.sleep(100); _metricsManager.createOrUpdateSlidingWindowHistogram(CLASS_NAME, "test", "latency", 1, 10); String fullName = MetricRegistry.name(CLASS_NAME, "test", "latency"); Histogram histogram = _metricsManager.getMetric(fullName); Assert.assertNotEquals(histogram.getSnapshot().getMax(), highLatency); }