ServiceMonitorMetrics { public LatencyMeasurement startServiceModelSnapshotLatencyMeasurement() { Consumer<Double> atCompletion = elapsedSeconds -> setValue(metricKey("snapshot.latency"), elapsedSeconds); return new LatencyMeasurement(timer, atCompletion).start(); } ServiceMonitorMetrics(Metric metric, Timer timer); LatencyMeasurement startServiceModelSnapshotLatencyMeasurement(); static String SERVICE_MODEL_METRIC_PREFIX; }
@Test public void testTryWithResources() { Metric metric = mock(Metric.class); Timer timer = mock(Timer.class); ServiceMonitorMetrics metrics = new ServiceMonitorMetrics(metric, timer); when(timer.currentTimeMillis()).thenReturn(Long.valueOf(500), Long.valueOf(1000)); try (LatencyMeasurement measurement = metrics.startServiceModelSnapshotLatencyMeasurement()) { measurement.hashCode(); } verify(metric).set("serviceModel.snapshot.latency", 0.5, null); }