Skip to content

Commit

Permalink
fix: change refill strategy for API rate limiting (#3949)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Tabone <[email protected]>
  • Loading branch information
taban03 authored Jan 15, 2025
1 parent d47a7c5 commit 32793d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Mono<Response> isAllowed(String routeId, String id) {
}

private Bucket newBucket(String id) {
Bandwidth limit = Bandwidth.builder().capacity(capacity).refillGreedy(tokens, Duration.ofMinutes(refillDuration)).build();
Bandwidth limit = Bandwidth.builder().capacity(capacity).refillIntervally(tokens, Duration.ofMinutes(refillDuration)).build();
return Bucket.builder().addLimit(limit).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.zowe.apiml.util.categories.RateLimitTest;
import org.zowe.apiml.util.http.HttpRequestUtils;
import reactor.netty.http.client.HttpClient;

import javax.net.ssl.SSLException;

@RateLimitTest
public class InMemoryRateLimiterFilterFactoryIntegrationTest {

private static WebTestClient client;
Expand All @@ -33,7 +35,7 @@ public class InMemoryRateLimiterFilterFactoryIntegrationTest {
@BeforeAll
static void setUpTester() {
String baseUrl = HttpRequestUtils.getUriFromGateway("/discoverableclient/api/v1/greeting").toString();
SslContext sslContext = null;
SslContext sslContext;
try {
sslContext = SslContextBuilder
.forClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.util.categories;
import org.junit.jupiter.api.Tag;

import java.lang.annotation.*;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

/**
* Test related to the API Rate limiting.
*/
@Tag("RateLimitTest")
@Target({ TYPE, METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface RateLimitTest {
}

0 comments on commit 32793d8

Please sign in to comment.