@Test public void testLogLimiting() throws Exception { long count = 0; for (long i = 0; i < 100; i++) { if (logLimiter.check()) count++; } assertEquals(0, logger.warnCount); assertEquals(1, count); Thread.sleep(600); assertEquals(1, logger.warnCount); assertEquals(1, count); for (long i = 0; i < 100; i++) { if (logLimiter.check()) count++; } assertEquals(1, logger.warnCount); assertEquals(2, count); Thread.sleep(600); assertEquals(2, logger.warnCount); assertEquals(2, count); }
boolean check() { long current = System.currentTimeMillis(); if (current - timestamp >= LOG_SUPPRESSION_INTERVAL) { timestamp = 0; timeout = null; } if (timestamp == 0) { timestamp = current; return true; } else { if (timeout == null) { timeout = new TimerTaskImpl(); timer.schedule(timeout, LOG_SUPPRESSION_INTERVAL); } timeout.messageSuppressed(); return false; } }
LogLimiter { boolean check() { long current = System.currentTimeMillis(); if (current - timestamp >= LOG_SUPPRESSION_INTERVAL) { timestamp = 0; timeout = null; } if (timestamp == 0) { timestamp = current; return true; } else { if (timeout == null) { timeout = new TimerTaskImpl(); timer.schedule(timeout, LOG_SUPPRESSION_INTERVAL); } timeout.messageSuppressed(); return false; } } }
LogLimiter { boolean check() { long current = System.currentTimeMillis(); if (current - timestamp >= LOG_SUPPRESSION_INTERVAL) { timestamp = 0; timeout = null; } if (timestamp == 0) { timestamp = current; return true; } else { if (timeout == null) { timeout = new TimerTaskImpl(); timer.schedule(timeout, LOG_SUPPRESSION_INTERVAL); } timeout.messageSuppressed(); return false; } } LogLimiter(Logger logger); }
LogLimiter { boolean check() { long current = System.currentTimeMillis(); if (current - timestamp >= LOG_SUPPRESSION_INTERVAL) { timestamp = 0; timeout = null; } if (timestamp == 0) { timestamp = current; return true; } else { if (timeout == null) { timeout = new TimerTaskImpl(); timer.schedule(timeout, LOG_SUPPRESSION_INTERVAL); } timeout.messageSuppressed(); return false; } } LogLimiter(Logger logger);  }
LogLimiter { boolean check() { long current = System.currentTimeMillis(); if (current - timestamp >= LOG_SUPPRESSION_INTERVAL) { timestamp = 0; timeout = null; } if (timestamp == 0) { timestamp = current; return true; } else { if (timeout == null) { timeout = new TimerTaskImpl(); timer.schedule(timeout, LOG_SUPPRESSION_INTERVAL); } timeout.messageSuppressed(); return false; } } LogLimiter(Logger logger);   }