use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelWebFluxIntegrationTest method testWebFluxFilterBasic.
@Test
public void testWebFluxFilterBasic() throws Exception {
String url = "/hello";
this.webClient.get().uri(url).accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk().expectBody(String.class).isEqualTo(HELLO_STR);
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelWebFluxIntegrationTest method testWebFluxRouterFunction.
@Test
public void testWebFluxRouterFunction() throws Exception {
String url = "/router/hello";
this.webClient.get().uri(url).accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk().expectBody(String.class).isEqualTo(HELLO_STR);
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
configureRulesFor(url, 0);
this.webClient.get().uri(url).accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isEqualTo(HttpStatus.TOO_MANY_REQUESTS).expectBody(String.class).value(StringContains.containsString(BLOCK_MSG_PREFIX));
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelAnnotationInterceptorIntegrationTest method testBlockHandlerNotFound.
@Test(expected = FlowException.class)
public void testBlockHandlerNotFound() {
assertThat(fooService.baz("Sentinel")).isEqualTo("cheers, Sentinel");
String resourceName = "apiBaz";
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertThat(cn).isNotNull();
assertThat(cn.passQps()).isPositive();
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
fooService.baz("Sentinel");
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelAnnotationInterceptorIntegrationTest method testNormalBlockHandlerAndFallback.
@Test
public void testNormalBlockHandlerAndFallback() throws Exception {
assertThat(fooService.foo(1)).isEqualTo("Hello for 1");
String resourceName = "apiFoo";
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertThat(cn).isNotNull();
assertThat(cn.passQps()).isPositive();
// Test for biz exception.
try {
fooService.foo(5758);
fail("should not reach here");
} catch (Exception ex) {
// Should not be traced.
assertThat(cn.exceptionQps()).isZero();
}
try {
fooService.foo(5763);
fail("should not reach here");
} catch (Exception ex) {
assertThat(cn.exceptionQps()).isPositive();
}
// Test for blockHandler
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
assertThat(fooService.foo(1121)).isEqualTo("Oops, 1121");
assertThat(cn.blockQps()).isPositive();
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelAnnotationInterceptorIntegrationTest method testForeignBlockHandlerClass.
@Test
public void testForeignBlockHandlerClass() throws Exception {
assertThat(fooService.random()).isNotEqualTo(FooUtil.BLOCK_FLAG);
String resourceName = MethodUtil.resolveMethodName(FooService.class.getDeclaredMethod("random"));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertThat(cn).isNotNull();
assertThat(cn.passQps()).isPositive();
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
assertThat(fooService.random()).isEqualTo(FooUtil.BLOCK_FLAG);
assertThat(cn.blockQps()).isPositive();
}
Aggregations