@ -34,26 +34,26 @@ public class RedisRateLimiterTests extends BaseWebClientTests {
@@ -34,26 +34,26 @@ public class RedisRateLimiterTests extends BaseWebClientTests {
String id = UUID . randomUUID ( ) . toString ( ) ;
int replenishRate = 10 ;
int c apacity = 2 * replenishRate ;
int burstC apacity = 2 * replenishRate ;
// Bursts work
for ( int i = 0 ; i < c apacity; i + + ) {
Response response = rateLimiter . isAllowed ( id , replenishRate , c apacity) ;
for ( int i = 0 ; i < burstC apacity; i + + ) {
Response response = rateLimiter . isAllowed ( id , replenishRate , burstC apacity) ;
assertThat ( response . isAllowed ( ) ) . as ( "Burst # %s is allowed" , i ) . isTrue ( ) ;
}
Response response = rateLimiter . isAllowed ( id , replenishRate , c apacity) ;
assertThat ( response . isAllowed ( ) ) . as ( "Burst # %s is not allowed" , c apacity) . isFalse ( ) ;
Response response = rateLimiter . isAllowed ( id , replenishRate , burstC apacity) ;
assertThat ( response . isAllowed ( ) ) . as ( "Burst # %s is not allowed" , burstC apacity) . isFalse ( ) ;
Thread . sleep ( 1000 ) ;
// # After the burst is done, check the steady state
for ( int i = 0 ; i < replenishRate ; i + + ) {
response = rateLimiter . isAllowed ( id , replenishRate , c apacity) ;
response = rateLimiter . isAllowed ( id , replenishRate , burstC apacity) ;
assertThat ( response . isAllowed ( ) ) . as ( "steady state # %s is allowed" , i ) . isTrue ( ) ;
}
response = rateLimiter . isAllowed ( id , replenishRate , c apacity) ;
response = rateLimiter . isAllowed ( id , replenishRate , burstC apacity) ;
assertThat ( response . isAllowed ( ) ) . as ( "steady state # %s is allowed" , replenishRate ) . isFalse ( ) ;
}