From cab0f9be524f42911d702b3b9733ececf718da27 Mon Sep 17 00:00:00 2001 From: Andrea Tabone Date: Wed, 15 Jan 2025 13:20:00 +0100 Subject: [PATCH 1/3] change the token refill technique Signed-off-by: Andrea Tabone --- .../org/zowe/apiml/gateway/filters/InMemoryRateLimiter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway-service/src/main/java/org/zowe/apiml/gateway/filters/InMemoryRateLimiter.java b/gateway-service/src/main/java/org/zowe/apiml/gateway/filters/InMemoryRateLimiter.java index c24c7d292b..a0b2b0d97f 100644 --- a/gateway-service/src/main/java/org/zowe/apiml/gateway/filters/InMemoryRateLimiter.java +++ b/gateway-service/src/main/java/org/zowe/apiml/gateway/filters/InMemoryRateLimiter.java @@ -48,7 +48,7 @@ public Mono 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(); } From 72893215f3a7b318841643bfa99ac36a9eebc5e0 Mon Sep 17 00:00:00 2001 From: Andrea Tabone Date: Wed, 15 Jan 2025 14:02:13 +0100 Subject: [PATCH 2/3] add test to exec Signed-off-by: Andrea Tabone --- ...teLimiterFilterFactoryIntegrationTest.java | 4 ++- .../apiml/util/categories/RateLimitTest.java | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java diff --git a/integration-tests/src/test/java/org/zowe/apiml/functional/gateway/InMemoryRateLimiterFilterFactoryIntegrationTest.java b/integration-tests/src/test/java/org/zowe/apiml/functional/gateway/InMemoryRateLimiterFilterFactoryIntegrationTest.java index 913284bf88..e252c53b21 100644 --- a/integration-tests/src/test/java/org/zowe/apiml/functional/gateway/InMemoryRateLimiterFilterFactoryIntegrationTest.java +++ b/integration-tests/src/test/java/org/zowe/apiml/functional/gateway/InMemoryRateLimiterFilterFactoryIntegrationTest.java @@ -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; @@ -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() diff --git a/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java b/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java new file mode 100644 index 0000000000..574f293f7c --- /dev/null +++ b/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java @@ -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 that makes sense only in AT-TLS context. + */ +@Tag("RateLimitTest") +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface RateLimitTest { +} From 64ad59190efbda33b6bf769475ce7bf4b368ba6a Mon Sep 17 00:00:00 2001 From: Andrea Tabone Date: Wed, 15 Jan 2025 14:19:41 +0100 Subject: [PATCH 3/3] fix comment Signed-off-by: Andrea Tabone --- .../test/java/org/zowe/apiml/util/categories/RateLimitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java b/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java index 574f293f7c..7c5ea0296e 100644 --- a/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java +++ b/integration-tests/src/test/java/org/zowe/apiml/util/categories/RateLimitTest.java @@ -17,7 +17,7 @@ import static java.lang.annotation.ElementType.TYPE; /** - * Test that makes sense only in AT-TLS context. + * Test related to the API Rate limiting. */ @Tag("RateLimitTest") @Target({ TYPE, METHOD })