Skip to content

Commit

Permalink
Merge pull request ReactiveX#64 from resilience4j/uppetlimit-for-sema…
Browse files Browse the repository at this point in the history
…phore-based-limiter

Issue ReactiveX#63 upper limit for SemaphoreBasedRateLimiter
  • Loading branch information
storozhukBM committed Mar 24, 2017
2 parents accd424 + 9d8d841 commit 256f89a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private void scheduleLimitRefresh() {
}

void refreshLimit() {
semaphore.release(this.rateLimiterConfig.getLimitForPeriod());
int permissionsToRelease = this.rateLimiterConfig.getLimitForPeriod() - semaphore.availablePermits();
semaphore.release(permissionsToRelease);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ public void getRateLimiterConfig() throws Exception {
then(limit.getRateLimiterConfig()).isEqualTo(config);
}

@Test
public void isUpperLimitedForPermissions() throws Exception {
ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
SemaphoreBasedRateLimiter limit = new SemaphoreBasedRateLimiter("test", config, scheduler);
RateLimiter.Metrics metrics = limit.getMetrics();
then(metrics.getAvailablePermissions()).isEqualTo(2);
limit.refreshLimit();
then(metrics.getAvailablePermissions()).isEqualTo(2);
}

@Test
public void getDetailedMetrics() throws Exception {
ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
Expand Down

0 comments on commit 256f89a

Please sign in to comment.