use of com.alibaba.csp.sentinel.slotchain.StringResourceWrapper in project Sentinel by alibaba.
the class EntryTest method testEntryExitCounts.
@Test
public void testEntryExitCounts() {
ResourceWrapper resourceWrapper = new StringResourceWrapper("resA", EntryType.IN);
TestEntry entry = new TestEntry(resourceWrapper);
entry.exit();
assertEquals(-1, entry.count);
entry.exit(9);
assertEquals(-10, entry.count);
}
use of com.alibaba.csp.sentinel.slotchain.StringResourceWrapper in project Sentinel by alibaba.
the class EntryTest method testEntryFieldsGetSet.
@Test
public void testEntryFieldsGetSet() {
ResourceWrapper resourceWrapper = new StringResourceWrapper("resA", EntryType.IN);
Entry entry = new TestEntry(resourceWrapper);
assertSame(resourceWrapper, entry.getResourceWrapper());
Throwable error = new IllegalStateException();
entry.setError(error);
assertSame(error, entry.getError());
Node curNode = mock(Node.class);
entry.setCurNode(curNode);
assertSame(curNode, entry.getCurNode());
Node originNode = mock(Node.class);
entry.setOriginNode(originNode);
assertSame(originNode, entry.getOriginNode());
}
use of com.alibaba.csp.sentinel.slotchain.StringResourceWrapper in project Sentinel by alibaba.
the class AuthoritySlotTest method testCheckAuthorityNoExceptionItemsBlackFail.
@Test(expected = AuthorityException.class)
public void testCheckAuthorityNoExceptionItemsBlackFail() throws Exception {
String origin = "appA";
String resourceName = "testCheckAuthorityNoExceptionItemsBlackFail";
ResourceWrapper resourceWrapper = new StringResourceWrapper(resourceName, EntryType.IN);
ContextUtil.enter("entrance", origin);
try {
AuthorityRule ruleA = new AuthorityRule().setResource(resourceName).setLimitApp(origin + ",appC").as(AuthorityRule.class).setStrategy(RuleConstant.AUTHORITY_BLACK);
AuthorityRuleManager.loadRules(Collections.singletonList(ruleA));
authoritySlot.checkBlackWhiteAuthority(resourceWrapper, ContextUtil.getContext());
} finally {
ContextUtil.exit();
}
}
use of com.alibaba.csp.sentinel.slotchain.StringResourceWrapper in project Sentinel by alibaba.
the class FlowRuleCheckerTest method testSelectNodeForRelateReference.
@Test
public void testSelectNodeForRelateReference() {
String refResource = "testSelectNodeForRelateReference_refResource";
DefaultNode node = mock(DefaultNode.class);
ClusterNode refCn = mock(ClusterNode.class);
ClusterBuilderSlot.getClusterNodeMap().put(new StringResourceWrapper(refResource, EntryType.IN), refCn);
Context context = mock(Context.class);
FlowRule rule = new FlowRule("testSelectNodeForRelateReference").setCount(1).setStrategy(RuleConstant.STRATEGY_RELATE).setRefResource(refResource);
assertEquals(refCn, FlowRuleChecker.selectReferenceNode(rule, context, node));
}
use of com.alibaba.csp.sentinel.slotchain.StringResourceWrapper in project Sentinel by alibaba.
the class FlowSlotTest method testCheckFlowBlock.
@Test(expected = FlowException.class)
@SuppressWarnings("unchecked")
public void testCheckFlowBlock() throws Exception {
FlowRuleChecker checker = mock(FlowRuleChecker.class);
FlowSlot flowSlot = new FlowSlot(checker);
Context context = mock(Context.class);
DefaultNode node = mock(DefaultNode.class);
doCallRealMethod().when(checker).checkFlow(any(Function.class), any(ResourceWrapper.class), any(Context.class), any(DefaultNode.class), anyInt(), anyBoolean());
String resA = "resAK";
FlowRule rule = new FlowRule(resA).setCount(10);
FlowRuleManager.loadRules(Collections.singletonList(rule));
when(checker.canPassCheck(any(FlowRule.class), any(Context.class), any(DefaultNode.class), anyInt(), anyBoolean())).thenReturn(false);
flowSlot.checkFlow(new StringResourceWrapper(resA, EntryType.IN), context, node, 1, false);
}
Aggregations