support rejecting all requests by ratelimit

This commit is contained in:
Francis Dong
2023-06-29 11:34:48 +08:00
parent 9ba5afa69a
commit b92dd42c8e
3 changed files with 12 additions and 12 deletions

View File

@@ -46,14 +46,14 @@ public class ResourceConfig {
// Flow control rule // Flow control rule
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/** /**
* Maximum concurrent request, zero or negative for no limit * Maximum concurrent request, negative for no limit
*/ */
private long maxCon; private long maxCon = -1L;
/** /**
* Maximum QPS, zero or negative for no limit * Maximum QPS, negative for no limit
*/ */
private long maxQPS; private long maxQPS = -1L;
//--------------------------------------------------------------------- //---------------------------------------------------------------------

View File

@@ -63,9 +63,9 @@ public class ResourceRateLimitConfig {
public byte type; public byte type;
public long qps; public long qps = -1L;
public long concurrents; public long concurrents = -1L;
public String responseType; public String responseType;

View File

@@ -115,8 +115,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c5 = new FlowRuleCase(); FlowRuleCase c5 = new FlowRuleCase();
c5.resourceConfigs.add(new ResourceConfig("_global5", 0, 0)); c5.resourceConfigs.add(new ResourceConfig("_global5", -1L, -1L));
c5.resourceConfigs.add(new ResourceConfig("service5", 0, 0)); c5.resourceConfigs.add(new ResourceConfig("service5", -1L, -1L));
c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0)); c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0));
c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0)); c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0));
c5.expectResult = IncrRequestResult.success(); c5.expectResult = IncrRequestResult.success();
@@ -124,8 +124,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c6 = new FlowRuleCase(); FlowRuleCase c6 = new FlowRuleCase();
c6.resourceConfigs.add(new ResourceConfig("_global6", 20, 0)); c6.resourceConfigs.add(new ResourceConfig("_global6", 20, -1L));
c6.resourceConfigs.add(new ResourceConfig("service6", 20, 0)); c6.resourceConfigs.add(new ResourceConfig("service6", 20, -1L));
c6.resourceExpects.add(new ResourceExpect(20, 20, 20, c6.totalReqs - 20)); c6.resourceExpects.add(new ResourceExpect(20, 20, 20, c6.totalReqs - 20));
c6.resourceExpects.add(new ResourceExpect(20, 20, 20, 0)); c6.resourceExpects.add(new ResourceExpect(20, 20, 20, 0));
c6.expectResult = IncrRequestResult.block("_global6", BlockType.CONCURRENT_REQUEST); c6.expectResult = IncrRequestResult.block("_global6", BlockType.CONCURRENT_REQUEST);
@@ -133,8 +133,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c7 = new FlowRuleCase(); FlowRuleCase c7 = new FlowRuleCase();
c7.resourceConfigs.add(new ResourceConfig("_global7", 0, 0)); c7.resourceConfigs.add(new ResourceConfig("_global7", -1L, -1L));
c7.resourceConfigs.add(new ResourceConfig("service7", 0, 20)); c7.resourceConfigs.add(new ResourceConfig("service7", -1L, 20));
c7.resourceExpects.add(new ResourceExpect(20, 20, 20, 0)); c7.resourceExpects.add(new ResourceExpect(20, 20, 20, 0));
c7.resourceExpects.add(new ResourceExpect(20, 20, 20, c7.totalReqs - 20)); c7.resourceExpects.add(new ResourceExpect(20, 20, 20, c7.totalReqs - 20));
c7.expectResult = IncrRequestResult.block("service7", BlockType.QPS); c7.expectResult = IncrRequestResult.block("service7", BlockType.QPS);