use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ReactorSphUTest method testReactorEntryNormalWhenFlowControlTriggered.
@Test
public void testReactorEntryNormalWhenFlowControlTriggered() {
String resourceName = createResourceName("testReactorEntryNormalWhenFlowControlTriggered");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
StepVerifier.create(ReactorSphU.entryWith(resourceName, Mono.just(60)).subscribeOn(Schedulers.elastic()).map(e -> e * 3)).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<>());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class FluxSentinelOperatorTestIntegrationTest method testEmitMultipleValueSuccess.
@Test
public void testEmitMultipleValueSuccess() {
String resourceName = createResourceName("testEmitMultipleSuccess");
StepVerifier.create(Flux.just(1, 2).map(e -> e * 2).transform(new SentinelReactorTransformer<>(resourceName))).expectNext(2).expectNext(4).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 MonoSentinelOperatorIntegrationTest method testTransformMonoWithSentinelContextEnter.
@Test
public void testTransformMonoWithSentinelContextEnter() {
String resourceName = createResourceName("testTransformMonoWithSentinelContextEnter");
String contextName = "test_reactive_context";
String origin = "originA";
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0).setLimitApp(origin).as(FlowRule.class)));
StepVerifier.create(Mono.just(2).transform(new SentinelReactorTransformer<>(// Customized context with origin.
new EntryConfig(resourceName, EntryType.OUT, new ContextConfig(contextName, origin))))).expectError(BlockException.class).verify();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
assertEquals(1, cn.blockRequest());
assertTrue(Constants.ROOT.getChildList().stream().filter(node -> node instanceof EntranceNode).map(e -> (EntranceNode) e).anyMatch(e -> e.getId().getName().equals(contextName)));
FlowRuleManager.loadRules(new ArrayList<>());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testFluxToMonoNextThenCancelSuccess.
@Test
public void testFluxToMonoNextThenCancelSuccess() {
String resourceName = createResourceName("testFluxToMonoNextThenCancelSuccess");
StepVerifier.create(Flux.range(1, 10).map(e -> e * 2).next().transform(new SentinelReactorTransformer<>(resourceName))).expectNext(2).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 MonoSentinelOperatorIntegrationTest method testEmitSingleValueWhenFlowControlTriggered.
@Test
public void testEmitSingleValueWhenFlowControlTriggered() {
String resourceName = createResourceName("testEmitSingleValueWhenFlowControlTriggered");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
StepVerifier.create(Mono.just(1).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