forked from alibaba/Sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the problem that requests will never be blocked when slowRatioThr…
…eshold = 100% (alibaba#1779)
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ibaba/csp/sentinel/slots/block/degrade/circuitbreaker/ResponseTimeCircuitBreakerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.alibaba.csp.sentinel.slots.block.degrade.circuitbreaker; | ||
|
||
import com.alibaba.csp.sentinel.slots.block.RuleConstant; | ||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; | ||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; | ||
import com.alibaba.csp.sentinel.test.AbstractTimeBasedTest; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author xierz | ||
* @date 2020/10/4 | ||
*/ | ||
public class ResponseTimeCircuitBreakerTest extends AbstractTimeBasedTest { | ||
@Before | ||
public void setUp() { | ||
DegradeRuleManager.loadRules(new ArrayList<DegradeRule>()); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
DegradeRuleManager.loadRules(new ArrayList<DegradeRule>()); | ||
} | ||
|
||
@Test | ||
public void testMaxSlowRatioThreshold() { | ||
String resource = "testMaxSlowRatioThreshold"; | ||
DegradeRule rule = new DegradeRule("resource") | ||
.setCount(10) | ||
.setGrade(RuleConstant.DEGRADE_GRADE_RT) | ||
.setMinRequestAmount(3) | ||
.setSlowRatioThreshold(1) | ||
.setStatIntervalMs(5000) | ||
.setTimeWindow(5); | ||
rule.setResource(resource); | ||
DegradeRuleManager.loadRules(Collections.singletonList(rule)); | ||
|
||
assertTrue(entryAndSleepFor(resource, 20)); | ||
assertTrue(entryAndSleepFor(resource, 20)); | ||
assertTrue(entryAndSleepFor(resource, 20)); | ||
|
||
// should be blocked, cause 3/3 requests' rt is bigger than max rt. | ||
assertFalse(entryAndSleepFor(resource,20)); | ||
sleep(1000); | ||
assertFalse(entryAndSleepFor(resource,20)); | ||
sleep(4000); | ||
|
||
assertTrue(entryAndSleepFor(resource, 20)); | ||
} | ||
|
||
} |