@Test public void shouldAllowAddingItemsWithinLimit() { final RateTracker tracker = new RateTracker(1, 1, timeProvider); assertThat(tracker.wantToRequestObjects(1)).isEqualTo(1); }
public synchronized long wantToRequestObjects(final long objectCount) { pruneRequests(); if ((peerRateLimit - requestsWithinWindow) <= 0) { return 0L; } requestsWithinWindow += objectCount; requestCount.compute( timeProvider.getTimeInSeconds(), (key, val) -> val == null ? objectCount : val + objectCount); return objectCount; }
RateTracker { public synchronized long wantToRequestObjects(final long objectCount) { pruneRequests(); if ((peerRateLimit - requestsWithinWindow) <= 0) { return 0L; } requestsWithinWindow += objectCount; requestCount.compute( timeProvider.getTimeInSeconds(), (key, val) -> val == null ? objectCount : val + objectCount); return objectCount; } }
RateTracker { public synchronized long wantToRequestObjects(final long objectCount) { pruneRequests(); if ((peerRateLimit - requestsWithinWindow) <= 0) { return 0L; } requestsWithinWindow += objectCount; requestCount.compute( timeProvider.getTimeInSeconds(), (key, val) -> val == null ? objectCount : val + objectCount); return objectCount; } RateTracker(
      final int peerRateLimit, final long timeoutSeconds, final TimeProvider timeProvider); }
RateTracker { public synchronized long wantToRequestObjects(final long objectCount) { pruneRequests(); if ((peerRateLimit - requestsWithinWindow) <= 0) { return 0L; } requestsWithinWindow += objectCount; requestCount.compute( timeProvider.getTimeInSeconds(), (key, val) -> val == null ? objectCount : val + objectCount); return objectCount; } RateTracker(
      final int peerRateLimit, final long timeoutSeconds, final TimeProvider timeProvider); synchronized long wantToRequestObjects(final long objectCount); }
RateTracker { public synchronized long wantToRequestObjects(final long objectCount) { pruneRequests(); if ((peerRateLimit - requestsWithinWindow) <= 0) { return 0L; } requestsWithinWindow += objectCount; requestCount.compute( timeProvider.getTimeInSeconds(), (key, val) -> val == null ? objectCount : val + objectCount); return objectCount; } RateTracker(
      final int peerRateLimit, final long timeoutSeconds, final TimeProvider timeProvider); synchronized long wantToRequestObjects(final long objectCount);  }