From cfd48e6f38f8809570599d9ca6b586d56c1881fe Mon Sep 17 00:00:00 2001 From: spencergibb Date: Wed, 4 Dec 2024 11:40:30 -0500 Subject: [PATCH] Formatting --- .../filter/ratelimit/Bucket4jRateLimiter.java | 13 ++++++++----- .../filter/ratelimit/Bucket4jRateLimiterTests.java | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiter.java index 72f2c91c9b..56a4a6fb05 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiter.java @@ -60,7 +60,7 @@ public Mono isAllowed(String routeId, String id) { AsyncBucketProxy bucket = proxyManager.builder().build(id, bucketConfiguration); CompletableFuture 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); @@ -80,7 +80,8 @@ public Mono 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) { @@ -107,7 +108,7 @@ public Map 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; @@ -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(); } } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiterTests.java index 9efb35eb25..dfc62e3fcd 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/ratelimit/Bucket4jRateLimiterTests.java @@ -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); } @@ -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();