Search in sources :

Example 1 with FlowRule

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

the class ClientFilterTest 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));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 2 with FlowRule

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

the class GatewayRuleConverterTest method testConvertToFlowRule.

@Test
public void testConvertToFlowRule() {
    GatewayFlowRule rule = new GatewayFlowRule("routeId1").setCount(10).setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER).setMaxQueueingTimeoutMs(1000);
    FlowRule flowRule = GatewayRuleConverter.toFlowRule(rule);
    assertEquals(rule.getResource(), flowRule.getResource());
    assertEquals(rule.getCount(), flowRule.getCount(), 0.01);
    assertEquals(rule.getControlBehavior(), flowRule.getControlBehavior());
    assertEquals(rule.getMaxQueueingTimeoutMs(), flowRule.getMaxQueueingTimeMs());
}
Also used : ParamFlowRule(com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Test(org.junit.Test)

Example 3 with FlowRule

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

the class SentinelGrpcClientInterceptorTest method configureFlowRule.

private void configureFlowRule(int count) {
    FlowRule rule = new FlowRule().setCount(count).setGrade(RuleConstant.FLOW_GRADE_QPS).setResource(fullMethodName).setLimitApp("default").as(FlowRule.class);
    FlowRuleManager.loadRules(Collections.singletonList(rule));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 4 with FlowRule

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

the class SentinelGrpcServerInterceptorTest method configureFlowRule.

private void configureFlowRule(int count) {
    FlowRule rule = new FlowRule().setCount(count).setGrade(RuleConstant.FLOW_GRADE_QPS).setResource(resourceName).setLimitApp("default").as(FlowRule.class);
    FlowRuleManager.loadRules(Collections.singletonList(rule));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 5 with FlowRule

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

the class NacosDataSourceDemo method loadMyNamespaceRules.

private static void loadMyNamespaceRules() {
    Properties properties = new Properties();
    properties.put(PropertyKeyConst.SERVER_ADDR, remoteAddress);
    properties.put(PropertyKeyConst.NAMESPACE, NACOS_NAMESPACE_ID);
    ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(properties, groupId, dataId, source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
    }));
    FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
}
Also used : NacosDataSource(com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource) List(java.util.List) TypeReference(com.alibaba.fastjson.TypeReference) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Properties(java.util.Properties)

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