@Override public boolean hasExpired() { return get().hasExpired(); } }
@Override public boolean hasExpired() { return get().hasExpired(); } }
@Test public void testHasExpired() { CompositeRegistry r = new CompositeRegistry(clock); Counter c1 = r.counter("id1"); Assertions.assertFalse(c1.hasExpired()); Registry r1 = new DefaultRegistry(clock); r.add(r1); // depends on registry type, some will be expired until first increment Assertions.assertFalse(c1.hasExpired()); c1.increment(); Assertions.assertFalse(c1.hasExpired()); }
@Test public void testHasExpired() { String[] tagValue = new String[] { "default" }; Counter c = factory.counter(factory.createId("testHasExpired", Collections.singleton(new TestTagFactory(tagValue)))); Assertions.assertFalse(c.hasExpired()); } }
@Test public void expiration() { final long initTime = TimeUnit.MINUTES.toMillis(30); final long fifteenMinutes = TimeUnit.MINUTES.toMillis(15); // Not expired on init, wait for activity to mark as active clock.setWallTime(initTime); Counter c = newCounter("foo"); Assertions.assertFalse(c.hasExpired()); c.increment(42); Assertions.assertFalse(c.hasExpired()); // Expires with inactivity, total count in memory is maintained clock.setWallTime(initTime + fifteenMinutes); Assertions.assertFalse(c.hasExpired()); // Expires with inactivity, total count in memory is maintained clock.setWallTime(initTime + fifteenMinutes + 1); Assertions.assertEquals(c.count(), 42); Assertions.assertTrue(c.hasExpired()); // Activity brings it back c.increment(); Assertions.assertEquals(c.count(), 43); Assertions.assertFalse(c.hasExpired()); }
@Test public void resurrectExpiredAndIncrement() { ManualClock clock = new ManualClock(); ServoRegistry registry = new ServoRegistry(clock); Counter c = registry.counter("test"); clock.setWallTime(60000 * 30); registry.getMonitors(); Assertions.assertTrue(c.hasExpired()); c.increment(); Assertions.assertEquals(1, c.count()); Assertions.assertEquals(1, registry.counter("test").count()); clock.setWallTime(60000 * 60); registry.getMonitors(); Assertions.assertTrue(c.hasExpired()); c.increment(); Assertions.assertEquals(1, c.count()); Assertions.assertEquals(1, registry.counter("test").count()); }