限流的dubbo测试通过.

This commit is contained in:
huangsimin 2019-07-23 11:34:52 +08:00
parent 93c1f1742e
commit 4c2280e543
2 changed files with 12 additions and 8 deletions

View File

@ -46,8 +46,8 @@ dubbo:
- name: RequestRateLimiter
args:
key-resolver: '#{@ipResolver}' #SPEL表达式去的对应的bean
redis-rate-limiter.replenishRate: 81 # 令牌桶的容积
redis-rate-limiter.burstCapacity: 40 # 流速 每秒
redis-rate-limiter.replenishRate: 40 # 令牌桶的容积
redis-rate-limiter.burstCapacity: 80 # 流速 每秒
# - name: RequestRateLimiter1
# args:

View File

@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.factory.SetRequestHeaderGatewayFilterFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@ -30,9 +31,8 @@ public class TestHttp2DubboConfig4 {
@Test
public void Test1RequestHttp2DubboSetHeader() {
// Test Base Url
for(int i = 0; i < 2;i++) {
for(int i = 0; i < 50;i++) {
HttpClient client = HttpClient.create();
ResponseReceiver<?> receiver;
String content;
@ -42,10 +42,14 @@ public class TestHttp2DubboConfig4 {
HttpClientResponse response = receiver.response().block();
Assert.assertNotNull(response);
Assert.assertEquals(response.status().code(), 200);
content = receiver.responseContent().asString().blockLast();
Assert.assertNotNull(content);
Assert.assertEquals(content, "Hello Dubbo");
if(response.status().code() == 200) {
content = receiver.responseContent().asString().blockLast();
Assert.assertNotNull(content);
Assert.assertEquals(content, "Hello Dubbo");
} else {
Assert.assertEquals(response.status().code(), 429);
}
}
}