-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: VSDSPUB-1123: customization of rate limiter (#463)
- Loading branch information
Showing
7 changed files
with
232 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...rmatievlaanderen/ldes/ldi/requestexecutor/executor/ratelimiter/RateLimiterConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.ratelimiter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class RateLimiterConfigTest { | ||
private static final int LIMIT = 500; | ||
|
||
@Test | ||
void test_LimitPerMinute() { | ||
final io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig = RateLimiterConfig.limitPerMinute(LIMIT).getRateLimiter().getRateLimiterConfig(); | ||
|
||
assertThat(rateLimiterConfig.getLimitForPeriod()).isEqualTo(LIMIT); | ||
assertThat(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.ofMinutes(1)); | ||
} | ||
|
||
@Test | ||
void given_ValidPeriodAndLimit_when_LimitForPeriod_then_ReturnRateLimiterConfig() { | ||
final String periodString = "PT1M"; | ||
|
||
final io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig = RateLimiterConfig.limitForPeriod(LIMIT, periodString).getRateLimiter().getRateLimiterConfig(); | ||
|
||
assertThat(rateLimiterConfig.getLimitForPeriod()).isEqualTo(LIMIT); | ||
assertThat(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.parse(periodString)); | ||
assertThat(rateLimiterConfig.getTimeoutDuration()).isEqualTo(Duration.parse(periodString)); | ||
} | ||
|
||
@Test | ||
void given_InvalidPeriod_when_LimitForPeriod_then_ThrowException() { | ||
String periodString = "TP1J"; | ||
|
||
assertThatThrownBy(() -> RateLimiterConfig.limitForPeriod(LIMIT, periodString)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Invalid config for the property 'rate-limiter.period': this must be a valid 8601 duration"); | ||
} | ||
} |
Oops, something went wrong.