@Test public void shouldNotDetectBurst() throws InterruptedException { BurstDetector burstDetector = new BurstDetector(3, 10); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); }
public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } }
BurstDetector { public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } } }
BurstDetector { public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } } BurstDetector(int n, long delta); }
BurstDetector { public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } } BurstDetector(int n, long delta); boolean invoke(); }
BurstDetector { public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } } BurstDetector(int n, long delta); boolean invoke();  }