Search in sources :

Example 41 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-cloud-alibaba by alibaba.

the class SentinelConverterTests method testXmlConverter.

@Test
public void testXmlConverter() {
    XmlConverter jsonConverter = new XmlConverter(xmlMapper, FlowRule.class);
    List<FlowRule> flowRules = (List<FlowRule>) jsonConverter.convert(readFileContent("classpath: flowrule.xml"));
    assertThat(flowRules.size()).isEqualTo(2);
    assertThat(flowRules.get(0).getResource()).isEqualTo("resource");
    assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default");
    assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0");
    assertThat(flowRules.get(0).getControlBehavior()).isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
    assertThat(flowRules.get(0).getStrategy()).isEqualTo(RuleConstant.STRATEGY_DIRECT);
    assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
    assertThat(flowRules.get(1).getResource()).isEqualTo("test");
    assertThat(flowRules.get(1).getLimitApp()).isEqualTo("default");
    assertThat(String.valueOf(flowRules.get(1).getCount())).isEqualTo("1.0");
    assertThat(flowRules.get(1).getControlBehavior()).isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
    assertThat(flowRules.get(1).getStrategy()).isEqualTo(RuleConstant.STRATEGY_DIRECT);
    assertThat(flowRules.get(1).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
}
Also used : List(java.util.List) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) XmlConverter(com.alibaba.cloud.sentinel.datasource.converter.XmlConverter) Test(org.junit.Test)

Example 42 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project solon by noear.

the class CloudBreakerEntryImpl method loadRules.

private void loadRules() {
    List<FlowRule> ruleList = new ArrayList<>();
    FlowRule rule = null;
    rule = new FlowRule();
    rule.setResource(breakerName);
    // qps
    rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule.setCount(thresholdValue);
    ruleList.add(rule);
    rule = new FlowRule();
    rule.setResource(breakerName);
    // 并发数
    rule.setGrade(RuleConstant.FLOW_GRADE_THREAD);
    rule.setCount(thresholdValue);
    ruleList.add(rule);
    FlowRuleManager.loadRules(ruleList);
}
Also used : ArrayList(java.util.ArrayList) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 43 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-boot-student by wyh-spring-ecosystem-student.

the class FlowRuleEntity method toRule.

@Override
public FlowRule toRule() {
    FlowRule flowRule = new FlowRule();
    flowRule.setCount(this.count);
    flowRule.setGrade(this.grade);
    flowRule.setResource(this.resource);
    flowRule.setLimitApp(this.limitApp);
    flowRule.setRefResource(this.refResource);
    flowRule.setStrategy(this.strategy);
    if (this.controlBehavior != null) {
        flowRule.setControlBehavior(controlBehavior);
    }
    if (this.warmUpPeriodSec != null) {
        flowRule.setWarmUpPeriodSec(warmUpPeriodSec);
    }
    if (this.maxQueueingTimeMs != null) {
        flowRule.setMaxQueueingTimeMs(maxQueueingTimeMs);
    }
    flowRule.setClusterMode(clusterMode);
    flowRule.setClusterConfig(clusterConfig);
    return flowRule;
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 44 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project slate by shepherdviolet.

the class AbstractEzSentinelRuleConfigurer method commentRule.

protected static FlowRule commentRule(String comment) {
    FlowRule flowRule = new FlowRule(comment);
    flowRule.setCount(0);
    return flowRule;
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 45 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project JHodgepodge by werwolfGu.

the class SentinelDemo method main.

public static void main(String[] args) {
    Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
    RedissonClient redissonClient = null;
    String ruleKey = "flowRule:${appid}";
    String channel = "flow:topic:${appid}";
    ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(redissonClient, ruleKey, channel, flowConfigParser) {

        @Override
        public String defaultReadSrouce() {
            return null;
        }
    };
    FlowRuleManager.register2Property(redisDataSource.getProperty());
    String degradeKey = "degradeRule:${appid}";
    String degradeTopic = "degrade:topic:${appid}";
    ReadableDataSource<String, List<DegradeRule>> redisDegradeRule = new RedisDataSource<List<DegradeRule>>(redissonClient, degradeKey, degradeTopic, buildFDegradeConfigParser()) {

        @Override
        public String defaultReadSrouce() {
            return null;
        }
    };
    DegradeRuleManager.register2Property(redisDegradeRule.getProperty());
}
Also used : RedissonClient(org.redisson.api.RedissonClient) List(java.util.List) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Aggregations

FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)113 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)22 List (java.util.List)17 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)11 DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)9 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)6 Test (org.junit.jupiter.api.Test)6 ClusterFlowConfig (com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)5 TypeReference (com.alibaba.fastjson.TypeReference)5 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)5 Before (org.junit.Before)5 ParamFlowRule (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule)4 ClusterMetric (com.alibaba.csp.sentinel.cluster.flow.statistic.metric.ClusterMetric)3 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)3 AbstractTimeBasedTest (com.alibaba.csp.sentinel.test.AbstractTimeBasedTest)3 RateLimitDescriptor (io.envoyproxy.envoy.extensions.common.ratelimit.v3.RateLimitDescriptor)3 RateLimitResponse (io.envoyproxy.envoy.service.ratelimit.v3.RateLimitResponse)3 IOException (java.io.IOException)3