DynamicCounter extends AbstractMonitor<Long> implements CompositeMonitor<Long>, SpectatorMonitor { public static void increment(MonitorConfig config) { INSTANCE.get(config).increment(); } private  DynamicCounter(); @Override void initializeSpectator(TagList tags); static void increment(MonitorConfig config); static void increment(String name, String... tags); static void increment(MonitorConfig config, long delta); static void increment(String name, TagList list); static void increment(String name, TagList list, long delta); @Override @SuppressWarnings("unchecked") List<Monitor<?>> getMonitors(); @Override Long getValue(int pollerIndex); @Override String toString();  }
@Test public void testExpiration() throws Exception { clock.set(0L); DynamicCounter.increment("test1", tagList); DynamicCounter.increment("test2", tagList); clock.set(500L); DynamicCounter.increment("test1", tagList); clock.set(1000L); DynamicCounter.increment("test1", tagList); clock.set(60200L); StepCounter c1 = getByName("test1"); assert c1 != null; assertEquals(c1.getCount(0), 3L); Thread.sleep(200); StepCounter c2 = getByName("test2"); assertNull(c2, "Counters not used in a while should expire"); }
@Test public void testByStrings() throws Exception { clock.set(1L); DynamicCounter.increment("byName"); DynamicCounter.increment("byName"); StepCounter c = getByName("byName"); clock.set(60001L); assert c != null; assertEquals(c.getCount(0), 2L); DynamicCounter.increment("byName2", "key", "value", "key2", "value2"); DynamicCounter.increment("byName2", "key", "value", "key2", "value2"); StepCounter c2 = getByName("byName2"); clock.set(120001L); assert c2 != null; assertEquals(c2.getCount(0), 2L); }
@Test public void testShouldNotThrow() throws Exception { DynamicCounter.increment("name", "", ""); }