throw new LockCallbackException(e); } finally { acquireDurationTimer.stop(timer);
@Test public void patternUsingState() { LongTaskTimer t = LongTaskTimer.get(registry, registry.createId("foo")); long tid = t.start(); clock.addSeconds(60); PolledMeter.update(registry); Gauge g = registry.gauge(registry.createId("foo").withTag(Statistic.duration)); Assertions.assertEquals(60.0, g.value(), 1e-12); t.stop(tid); PolledMeter.update(registry); Assertions.assertEquals(0.0, g.value(), 1e-12); } }
@Test public void stateIsPreservedAcrossGets() { long t1 = LongTaskTimer.get(registry, id).start(); long t2 = LongTaskTimer.get(registry, id).start(); Assertions.assertFalse(t1 == t2); Assertions.assertEquals(LongTaskTimer.get(registry, id).activeTasks(), 2); clock.setMonotonicTime(5L); Assertions.assertEquals(LongTaskTimer.get(registry, id).duration(), 10L); LongTaskTimer.get(registry, id).stop(t1); Assertions.assertEquals(LongTaskTimer.get(registry, id).duration(), 5L); }