Browse Source

Fixes test cases for degrade regarding the new strategy

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 years ago
parent
commit
b2a3ef26a7
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeTest.java

+ 5
- 3
sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeTest.java View File

@@ -70,6 +70,8 @@ public class DegradeTest {
String key = "test_degrade_exception_ratio"; String key = "test_degrade_exception_ratio";
ClusterNode cn = mock(ClusterNode.class); ClusterNode cn = mock(ClusterNode.class);
when(cn.exceptionQps()).thenReturn(2L); when(cn.exceptionQps()).thenReturn(2L);
// Indicates that there are QPS more than min threshold.
when(cn.totalQps()).thenReturn(12L);
ClusterBuilderSlot.getClusterNodeMap().put(new StringResourceWrapper(key, EntryType.IN), cn); ClusterBuilderSlot.getClusterNodeMap().put(new StringResourceWrapper(key, EntryType.IN), cn);


Context context = mock(Context.class); Context context = mock(Context.class);
@@ -77,12 +79,12 @@ public class DegradeTest {
when(node.getClusterNode()).thenReturn(cn); when(node.getClusterNode()).thenReturn(cn);


DegradeRule rule = new DegradeRule(); DegradeRule rule = new DegradeRule();
rule.setCount(0.5);
rule.setCount(0.15);
rule.setResource(key); rule.setResource(key);
rule.setTimeWindow(5); rule.setTimeWindow(5);
rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION); rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION);


when(cn.successQps()).thenReturn(4L);
when(cn.successQps()).thenReturn(8L);


// Will fail. // Will fail.
assertFalse(rule.passCheck(context, node, 1)); assertFalse(rule.passCheck(context, node, 1));
@@ -90,7 +92,7 @@ public class DegradeTest {
// Restore from the degrade timeout. // Restore from the degrade timeout.
TimeUnit.SECONDS.sleep(6); TimeUnit.SECONDS.sleep(6);


when(cn.successQps()).thenReturn(7L);
when(cn.successQps()).thenReturn(20L);
// Will pass. // Will pass.
assertTrue(rule.passCheck(context, node, 1)); assertTrue(rule.passCheck(context, node, 1));
} }


Loading…
Cancel
Save