public TodoManagerImpl(Reactor reactor, StatsCollector statsCollector) { this.reactor = reactor; this.statsCollector = statsCollector; /** Send stat count i.am.alive every three seconds. */ this.reactor.addRepeatingTask(Duration.ofSeconds(3), () -> statsCollector.increment("todoservice.i.am.alive")); this.reactor.addRepeatingTask(Duration.ofSeconds(1), statsCollector::clientProxyFlush); }
@Test public void testRepeatingTask() { AtomicLong count = new AtomicLong(); reactor.addRepeatingTask(Duration.ofSeconds(1), count::incrementAndGet); assertEquals(0, count.get()); reactor.process(); assertEquals(1, count.get()); testTimer.setTime(System.currentTimeMillis() + Duration.ofMillis(1001).toMillis()); reactor.process(); assertEquals(2, count.get()); }