private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
@Test public void testExpiration() throws Exception { clock.set(0L); DynamicTimer.start("test1", tagList); DynamicTimer.start("test2", tagList); clock.set(500L); DynamicTimer.start("test1", tagList); clock.set(1000L); Stopwatch s = DynamicTimer.start("test1", tagList); clock.set(1200L); s.stop(); Timer c1 = getByName("test1"); assert c1 != null; assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); Thread.sleep(200L); Timer c2 = getByName("test2"); assertNull(c2, "Timers not used in a while should expire"); }
@Test public void testByStrings() throws Exception { Stopwatch s = DynamicTimer.start("byName"); Stopwatch s2 = DynamicTimer.start("byName2", "key", "value"); Thread.sleep(100L); s.stop(); s2.stop(); Timer c1 = getByName("byName"); assert c1 != null; assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); Timer c2 = getByName("byName2"); assert c2 != null; assertEquals(c2.getValue().longValue(), s2.getDuration(TimeUnit.MILLISECONDS)); } }
@Test public void testGetValue() throws Exception { Stopwatch s = DynamicTimer.start("test1", tagList); Timer c = getByName("test1"); s.stop(); // we don't call s.stop(), so we only have one recorded value assert c != null; assertEquals(c.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); c.record(13, TimeUnit.MILLISECONDS); long expected = (13 + s.getDuration(TimeUnit.MILLISECONDS)) / 2; assertEquals(c.getValue().longValue(), expected); }
@SuppressWarnings("unchecked") @Test public void testHasUnitTag() throws Exception { DynamicTimer.start("test1", tagList); CompositeMonitor c = (CompositeMonitor<Long>) getByName("test1"); assert c != null; List<Monitor<?>> monitors = c.getMonitors(); for (Monitor<?> m : monitors) { Tag type = m.getConfig().getTags().getTag("unit"); assertEquals(type.getValue(), "MILLISECONDS"); } }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }