diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java index 2a0d7260..f6f10a76 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java @@ -39,6 +39,7 @@ public abstract class AbstractRule implements Rule { */ private String limitApp; + @Override public String getResource() { return resource; } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/Rule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/Rule.java index e429b2a5..35630eda 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/Rule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/Rule.java @@ -15,9 +15,6 @@ */ package com.alibaba.csp.sentinel.slots.block; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; - /** * Base interface of all rules. * @@ -26,14 +23,10 @@ import com.alibaba.csp.sentinel.node.DefaultNode; public interface Rule { /** - * Check whether current statistical indicators meet this rule, which means not exceeding any threshold. + * Get target resource of this rule. * - * @param context current {@link Context} - * @param node current {@link com.alibaba.csp.sentinel.node.Node} - * @param count tokens needed. - * @param args arguments of the original invocation. - * @return If current statistical indicators not exceeding any threshold return true, otherwise return false. + * @return target resource of this rule */ - boolean passCheck(Context context, DefaultNode node, int count, Object... args); + String getResource(); } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRule.java index a5b5f277..c1606d0a 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRule.java @@ -15,8 +15,6 @@ */ package com.alibaba.csp.sentinel.slots.block.authority; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.RuleConstant; @@ -59,11 +57,6 @@ public class AuthorityRule extends AbstractRule { return result; } - @Override - public boolean passCheck(Context context, DefaultNode node, int count, Object... args) { - return true; - } - @Override public String toString() { return "AuthorityRule{" + diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java index 57d20729..edc9f1b3 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java @@ -15,8 +15,6 @@ */ package com.alibaba.csp.sentinel.slots.block.degrade; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.RuleConstant; @@ -172,10 +170,4 @@ public class DegradeRule extends AbstractRule { ", statIntervalMs=" + statIntervalMs + '}'; } - - @Override - @Deprecated - public boolean passCheck(Context context, DefaultNode node, int count, Object... args) { - return false; - } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java index e7413ea2..f05d1cbf 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java @@ -15,8 +15,6 @@ */ package com.alibaba.csp.sentinel.slots.block.flow; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.RuleConstant; @@ -186,11 +184,6 @@ public class FlowRule extends AbstractRule { return this; } - @Override - public boolean passCheck(Context context, DefaultNode node, int acquireCount, Object... args) { - return true; - } - @Override public boolean equals(Object o) { if (this == o) { return true; } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRule.java index 7a2ac333..66afdb29 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRule.java @@ -15,8 +15,6 @@ */ package com.alibaba.csp.sentinel.slots.system; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.slots.block.AbstractRule; /** @@ -133,11 +131,6 @@ public class SystemRule extends AbstractRule { this.highestCpuUsage = highestCpuUsage; } - @Override - public boolean passCheck(Context context, DefaultNode node, int count, Object... args) { - return true; - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleTest.java deleted file mode 100755 index 0180501e..00000000 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.csp.sentinel.slots.block.flow; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Ignore; -import org.junit.Test; - -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.ClusterNode; -import com.alibaba.csp.sentinel.node.DefaultNode; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.flow.controller.DefaultController; - -/** - * @author jialiang.linjl - */ -@Ignore("Deprecated test for legacy FlowRule") -public class FlowRuleTest { - - @Test - public void testFlowRule_grade() { - - FlowRule flowRule = new FlowRule(); - flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); - flowRule.setCount(1); - flowRule.setLimitApp("default"); - flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT); - - DefaultController defaultController = new DefaultController(1, flowRule.getGrade()); - flowRule.setRater(defaultController); - - Context context = mock(Context.class); - DefaultNode node = mock(DefaultNode.class); - ClusterNode cn = mock(ClusterNode.class); - - when(context.getOrigin()).thenReturn(""); - when(node.getClusterNode()).thenReturn(cn); - when(cn.passQps()).thenReturn(1d); - - assertFalse(flowRule.passCheck(context, node, 1)); - - flowRule.setGrade(RuleConstant.FLOW_GRADE_THREAD); - defaultController = new DefaultController(1, flowRule.getGrade()); - flowRule.setRater(defaultController); - when(cn.curThreadNum()).thenReturn(1); - assertTrue(!flowRule.passCheck(context, node, 1)); - } - - @Test - public void testFlowRule_strategy() { - - FlowRule flowRule = new FlowRule(); - flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); - flowRule.setCount(1); - flowRule.setLimitApp("default"); - flowRule.setStrategy(RuleConstant.STRATEGY_CHAIN); - DefaultController defaultController = new DefaultController(1, flowRule.getGrade()); - flowRule.setRater(defaultController); - flowRule.setRefResource("entry1"); - - Context context = mock(Context.class); - DefaultNode dn = mock(DefaultNode.class); - - when(context.getName()).thenReturn("entry1"); - when(dn.passQps()).thenReturn(1d); - assertFalse(flowRule.passCheck(context, dn, 1)); - - when(context.getName()).thenReturn("entry2"); - assertTrue(flowRule.passCheck(context, dn, 1)); - - // Strategy == relate - flowRule.setStrategy(RuleConstant.STRATEGY_CHAIN); - ClusterNode cn = mock(ClusterNode.class); - assertTrue(flowRule.passCheck(context, dn, 1)); - } - - @Test - public void testOrigin() { - FlowRule flowRule = new FlowRule(); - flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); - flowRule.setCount(1); - flowRule.setLimitApp("default"); - flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT); - DefaultController defaultController = new DefaultController(1, flowRule.getGrade()); - flowRule.setRater(defaultController); - flowRule.setRefResource("entry1"); - - Context context = mock(Context.class); - DefaultNode dn = mock(DefaultNode.class); - when(context.getOrigin()).thenReturn("origin1"); - when(dn.passQps()).thenReturn(1d); - when(context.getOriginNode()).thenReturn(dn); - - /* - * first scenario, limit app as default - * - */ - ClusterNode cn = mock(ClusterNode.class); - when(dn.getClusterNode()).thenReturn(cn); - when(cn.passQps()).thenReturn(1d); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - when(cn.passQps()).thenReturn(0d); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - flowRule.setStrategy(RuleConstant.STRATEGY_CHAIN); - flowRule.setResource("entry1"); - when(context.getName()).thenReturn("entry1"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - when(context.getName()).thenReturn("entry2"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - // relate node - flowRule.setStrategy(RuleConstant.STRATEGY_RELATE); - flowRule.setResource("worong"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - /* - * second scenario test a context with the same origin1 - * - */ - flowRule.setLimitApp("origin1"); - when(context.getName()).thenReturn("entry1"); - // direct node - flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - - // chain node - flowRule.setResource("entry1"); - flowRule.setStrategy(RuleConstant.STRATEGY_CHAIN); - when(context.getName()).thenReturn("entry1"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - when(context.getName()).thenReturn("entry2"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - // relate node - flowRule.setStrategy(RuleConstant.STRATEGY_RELATE); - flowRule.setResource("not exits"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - when(context.getOrigin()).thenReturn("origin2"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - - /* - * limit app= other - */ - flowRule.setLimitApp("other"); - flowRule.setResource("hello world"); - - flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - - flowRule.setStrategy(RuleConstant.STRATEGY_CHAIN); - flowRule.setResource("entry1"); - when(context.getName()).thenReturn("entry1"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0]) == false); - - when(context.getName()).thenReturn("entry2"); - assertTrue(flowRule.passCheck(context, dn, 1, new Object[0])); - } - -} diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java index 5d49c5bf..3d2186a9 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java @@ -21,8 +21,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import com.alibaba.csp.sentinel.context.Context; -import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.RuleConstant; @@ -190,12 +188,6 @@ public class ParamFlowRule extends AbstractRule { return this; } - @Override - @Deprecated - public boolean passCheck(Context context, DefaultNode node, int count, Object... args) { - return true; - } - @Override public boolean equals(Object o) { if (this == o) { return true; }