Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Dec 4, 2024
1 parent 27b1213 commit cfd48e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Mono<Response> isAllowed(String routeId, String id) {

AsyncBucketProxy bucket = proxyManager.builder().build(id, bucketConfiguration);
CompletableFuture<ConsumptionProbe> bucketFuture = bucket
.tryConsumeAndReturnRemaining(routeConfig.getRequestedTokens());
.tryConsumeAndReturnRemaining(routeConfig.getRequestedTokens());
return Mono.fromFuture(bucketFuture).onErrorResume(throwable -> {
if (log.isDebugEnabled()) {
log.debug("Error calling Bucket4J rate limiter", throwable);
Expand All @@ -80,7 +80,8 @@ public Mono<Response> isAllowed(String routeId, String id) {

protected static BucketConfiguration getBucketConfiguration(Config routeConfig) {
return BucketConfiguration.builder()
.addLimit(Bandwidth.simple(routeConfig.getCapacity(), routeConfig.getPeriod())).build();
.addLimit(Bandwidth.simple(routeConfig.getCapacity(), routeConfig.getPeriod()))
.build();
}

protected Config loadRouteConfiguration(String routeId) {
Expand All @@ -107,7 +108,7 @@ public Map<String, String> getHeaders(Config config, Long tokensLeft) {

public static class Config {

//TODO: create simple and classic w/Refill
// TODO: create simple and classic w/Refill

long capacity;

Expand Down Expand Up @@ -143,8 +144,10 @@ public Config setRequestedTokens(long requestedTokens) {
}

public String toString() {
return new ToStringCreator(this).append("capacity", capacity).append("requestedTokens", requestedTokens)
.append("period", period).toString();
return new ToStringCreator(this).append("capacity", capacity)
.append("requestedTokens", requestedTokens)
.append("period", period)
.toString();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void bucket4jRateLimiterWorks() throws Exception {
int requestedTokens = 1;

String routeId = "myroute";
rateLimiter.getConfig().put(routeId,
new Bucket4jRateLimiter.Config().setCapacity(capacity).setPeriod(Duration.ofSeconds(1)));
rateLimiter.getConfig()
.put(routeId, new Bucket4jRateLimiter.Config().setCapacity(capacity).setPeriod(Duration.ofSeconds(1)));

checkLimitEnforced(id, capacity, requestedTokens, routeId);
}
Expand All @@ -79,8 +79,11 @@ public void bucket4jRateLimiterIsAllowedFalseWorks() throws Exception {
int requestedTokens = 2;

String routeId = "zero_capacity_route";
rateLimiter.getConfig().put(routeId, new Bucket4jRateLimiter.Config().setCapacity(capacity)
.setPeriod(Duration.ofSeconds(1)).setRequestedTokens(requestedTokens));
rateLimiter.getConfig()
.put(routeId,
new Bucket4jRateLimiter.Config().setCapacity(capacity)
.setPeriod(Duration.ofSeconds(1))
.setRequestedTokens(requestedTokens));

Response response = rateLimiter.isAllowed(routeId, id).block();
assertThat(response.isAllowed()).isFalse();
Expand Down

0 comments on commit cfd48e6

Please sign in to comment.