Merge branch '3.1.x'

This commit is contained in:
spencergibb
2023-01-17 11:14:28 -05:00
2 changed files with 9 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.core.style.ToStringCreator;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
/**
@@ -332,6 +333,8 @@ public class RedisRateLimiter extends AbstractRateLimiter<RedisRateLimiter.Confi
}
public Config setBurstCapacity(int burstCapacity) {
Assert.isTrue(burstCapacity >= this.replenishRate, "BurstCapacity(" + burstCapacity
+ ") must be greater than or equal than replenishRate(" + this.replenishRate + ")");
this.burstCapacity = burstCapacity;
return this;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.gateway.filter.ratelimit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.assertj.core.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
@@ -52,6 +53,11 @@ public class RedisRateLimiterConfigTests {
routeLocator.getRoutes().collectList().block();
}
@Test
public void shouldThrowAnErrorWhenReplenishRateIsHigherThanBurstCapacity() {
Assertions.assertThatThrownBy(() -> new RedisRateLimiter(10, 5)).isInstanceOf(IllegalArgumentException.class);
}
@Test
public void redisRateConfiguredFromEnvironment() {
assertFilter("redis_rate_limiter_config_test", 10, 20, 1, false);