mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -4,11 +4,13 @@ import org.dromara.hutool.core.thread.ThreadUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class SemaphoreRateLimiterTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
final RateLimiterConfig rateLimiterConfig = RateLimiterConfig.of(5000, 300, 5);
|
||||
final RateLimiterConfig rateLimiterConfig = RateLimiterConfig.of(Duration.ofSeconds(5), Duration.ofMillis(300), 5);
|
||||
final RateLimiter rateLimiter = new SemaphoreRateLimiter(rateLimiterConfig);
|
||||
|
||||
final boolean b = rateLimiter.tryAcquire(5);
|
||||
@@ -16,7 +18,9 @@ public class SemaphoreRateLimiterTest {
|
||||
// 超过数量
|
||||
final boolean b1 = rateLimiter.tryAcquire(1);
|
||||
Assertions.assertFalse(b1);
|
||||
|
||||
ThreadUtil.sleep(310);
|
||||
|
||||
// 填充新的许可
|
||||
final boolean b2 = rateLimiter.tryAcquire(5);
|
||||
Assertions.assertTrue(b2);
|
||||
|
Reference in New Issue
Block a user