use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitExceptionWhenFlowControlTriggered.
@Test
public void testEmitExceptionWhenFlowControlTriggered() {
String resourceName = createResourceName("testEmitExceptionWhenFlowControlTriggered");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
StepVerifier.create(Mono.error(new IllegalStateException("some")).transform(new SentinelReactorTransformer<>(resourceName))).expectError(BlockException.class).verify();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
assertEquals(1, cn.blockRequest());
FlowRuleManager.loadRules(new ArrayList<>());
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.
the class HttpServerHandlerTest method testFetchActiveRuleCommandSomeFlowRules.
@Test
public void testFetchActiveRuleCommandSomeFlowRules() {
List<FlowRule> rules = new ArrayList<FlowRule>();
FlowRule rule1 = new FlowRule();
rule1.setResource("key");
rule1.setCount(20);
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule1.setLimitApp("default");
rules.add(rule1);
FlowRuleManager.loadRules(rules);
String httpRequestStr = "GET /getRules?type=flow HTTP/1.1" + CRLF + "Host: localhost:8719" + CRLF + CRLF;
// body json
/*
String expectedBody = "[{\"clusterMode\":false,\"controlBehavior\":0,\"count\":20.0"
+ ",\"grade\":1,\"limitApp\":\"default\",\"maxQueueingTimeMs\":500"
+ ",\"resource\":\"key\",\"strategy\":0,\"warmUpPeriodSec\":10}]";
*/
String expectedBody = JSON.toJSONString(rules);
processSuccess(httpRequestStr, expectedBody);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.
the class SentinelDubboConsumerFilterTest method initFlowRule.
private void initFlowRule(String resource) {
FlowRule flowRule = new FlowRule(resource);
flowRule.setCount(1);
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
List<FlowRule> flowRules = new ArrayList<>();
flowRules.add(flowRule);
FlowRuleManager.loadRules(flowRules);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.
the class CommonFilterContextTest method configureRulesFor.
private void configureRulesFor(String resource, int count, String limitApp) {
FlowRule rule = new FlowRule().setCount(count).setGrade(RuleConstant.FLOW_GRADE_QPS);
rule.setResource(resource);
if (StringUtil.isNotBlank(limitApp)) {
rule.setLimitApp(limitApp);
}
FlowRuleManager.loadRules(Collections.singletonList(rule));
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.
the class SentinelSpringMvcIntegrationTest method configureRulesFor.
private void configureRulesFor(String resource, int count, String limitApp) {
FlowRule rule = new FlowRule().setCount(count).setGrade(RuleConstant.FLOW_GRADE_QPS);
rule.setResource(resource);
if (StringUtil.isNotBlank(limitApp)) {
rule.setLimitApp(limitApp);
}
FlowRuleManager.loadRules(Collections.singletonList(rule));
}
Aggregations