use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelSofaRpcConsumerFilterTest method verifyInvocationStructure.
/**
* Verify Sentinel invocation structure in memory:
* EntranceNode(defaultContextName)
* --InterfaceNode(interfaceName)
* ----MethodNode(resourceName)
*/
private void verifyInvocationStructure(String interfaceResourceName, String methodResourceName) {
Context context = ContextUtil.getContext();
assertNotNull(context);
// As not call ContextUtil.enter(methodResourceName, applicationName) in SentinelSofaRpcConsumerFilter, use default context
// In actual project, a consumer is usually also a provider, the context will be created by SentinelSofaRpcProviderFilter
// If consumer is on the top of SOFARPC invocation chain, use default context
assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
assertEquals("", context.getOrigin());
DefaultNode entranceNode = context.getEntranceNode();
ResourceWrapper entranceResource = entranceNode.getId();
assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
assertSame(EntryType.IN, entranceResource.getEntryType());
// As SphU.entry(interfaceResourceName, EntryType.OUT);
Set<Node> childList = entranceNode.getChildList();
assertEquals(1, childList.size());
DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
ResourceWrapper interfaceResource = interfaceNode.getId();
assertEquals(interfaceResourceName, interfaceResource.getName());
assertSame(EntryType.OUT, interfaceResource.getEntryType());
// As SphU.entry(methodResourceName, EntryType.OUT);
childList = interfaceNode.getChildList();
assertEquals(1, childList.size());
DefaultNode methodNode = (DefaultNode) childList.iterator().next();
ResourceWrapper methodResource = methodNode.getId();
assertEquals(methodResourceName, methodResource.getName());
assertSame(EntryType.OUT, methodResource.getEntryType());
// Verify curEntry
Entry curEntry = context.getCurEntry();
assertSame(methodNode, curEntry.getCurNode());
assertSame(interfaceNode, curEntry.getLastNode());
// As context origin is not "", no originNode should be created in curEntry
assertNull(curEntry.getOriginNode());
// Verify clusterNode
ClusterNode methodClusterNode = methodNode.getClusterNode();
ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
// Different resource->Different ProcessorSlot->Different ClusterNode
assertNotSame(methodClusterNode, interfaceClusterNode);
// As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
assertEquals(0, methodOriginCountMap.size());
Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
assertEquals(0, interfaceOriginCountMap.size());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitSingleSuccess.
@Test
public void testEmitSingleSuccess() {
String resourceName = createResourceName("testEmitSingleSuccess");
StepVerifier.create(Mono.just(1).transform(new SentinelReactorTransformer<>(resourceName))).expectNext(1).verifyComplete();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ReactorSphUTest method testReactorEntryWithCommon.
@Test
public void testReactorEntryWithCommon() {
String resourceName = createResourceName("testReactorEntryWithCommon");
StepVerifier.create(ReactorSphU.entryWith(resourceName, Mono.just(60)).subscribeOn(Schedulers.elastic()).map(e -> e * 3)).expectNext(180).verifyComplete();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class FluxSentinelOperatorTestIntegrationTest method testEmitFluxError.
@Test
public void testEmitFluxError() {
String resourceName = createResourceName("testEmitFluxError");
StepVerifier.create(Flux.error(new IllegalAccessException("oops")).transform(new SentinelReactorTransformer<>(resourceName))).expectError(IllegalAccessException.class).verify();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
assertEquals(1, cn.totalException());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class FluxSentinelOperatorTestIntegrationTest method testEmitMultipleValuesWhenFlowControlTriggered.
@Test
public void testEmitMultipleValuesWhenFlowControlTriggered() {
String resourceName = createResourceName("testEmitMultipleValuesWhenFlowControlTriggered");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
StepVerifier.create(Flux.just(1, 3, 5).map(e -> e * 2).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<>());
}
Aggregations