@Test public void logDebouncePaused() throws InterruptedException { TestLogger testLogger = new TestLogger(); DebounceEventLogger debounceEventLogger = new DebounceEventLogger(10, testLogger); int count = 5; for (int i = 0; i < count; i++) { debounceEventLogger.log(null); Thread.sleep(15); } Assert.assertEquals(count, testLogger.count); }
@Override public void log(String event, Map<String, String> metadata) { boolean log = false; synchronized (this) { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - lastTimeMillis > timespanMillis) { lastTimeMillis = currentTimeMillis; log = true; } } if (log) { eventLogger.log(event, metadata); } }
DebounceEventLogger implements EventLogger { @Override public void log(String event, Map<String, String> metadata) { boolean log = false; synchronized (this) { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - lastTimeMillis > timespanMillis) { lastTimeMillis = currentTimeMillis; log = true; } } if (log) { eventLogger.log(event, metadata); } } }
DebounceEventLogger implements EventLogger { @Override public void log(String event, Map<String, String> metadata) { boolean log = false; synchronized (this) { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - lastTimeMillis > timespanMillis) { lastTimeMillis = currentTimeMillis; log = true; } } if (log) { eventLogger.log(event, metadata); } } DebounceEventLogger(long timespanMillis); @VisibleForTesting  DebounceEventLogger(long timespanMillis, EventLogger logger); }
DebounceEventLogger implements EventLogger { @Override public void log(String event, Map<String, String> metadata) { boolean log = false; synchronized (this) { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - lastTimeMillis > timespanMillis) { lastTimeMillis = currentTimeMillis; log = true; } } if (log) { eventLogger.log(event, metadata); } } DebounceEventLogger(long timespanMillis); @VisibleForTesting  DebounceEventLogger(long timespanMillis, EventLogger logger); @Override void log(String event, Map<String, String> metadata); }
DebounceEventLogger implements EventLogger { @Override public void log(String event, Map<String, String> metadata) { boolean log = false; synchronized (this) { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - lastTimeMillis > timespanMillis) { lastTimeMillis = currentTimeMillis; log = true; } } if (log) { eventLogger.log(event, metadata); } } DebounceEventLogger(long timespanMillis); @VisibleForTesting  DebounceEventLogger(long timespanMillis, EventLogger logger); @Override void log(String event, Map<String, String> metadata);  }