use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testMultipleReactorTransformerLatterFlowControl.
@Test
public void testMultipleReactorTransformerLatterFlowControl() {
String resourceName1 = createResourceName("testMultipleReactorTransformerLatterFlowControl1");
String resourceName2 = createResourceName("testMultipleReactorTransformerLatterFlowControl2");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName2).setCount(0)));
StepVerifier.create(Mono.just(2).transform(new SentinelReactorTransformer<>(resourceName1)).transform(new SentinelReactorTransformer<>(resourceName2))).expectError(BlockException.class).verify();
ClusterNode cn1 = ClusterBuilderSlot.getClusterNode(resourceName1);
assertNotNull(cn1);
ClusterNode cn2 = ClusterBuilderSlot.getClusterNode(resourceName2);
assertNotNull(cn2);
assertEquals(1, cn2.blockRequest());
assertEquals(1, cn1.totalSuccess());
FlowRuleManager.loadRules(new ArrayList<>());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitSingleLongTimeRt.
@Test
public void testEmitSingleLongTimeRt() {
String resourceName = createResourceName("testEmitSingleLongTimeRt");
StepVerifier.create(Mono.just(2).delayElement(Duration.ofMillis(1000)).map(e -> e * 2).transform(new SentinelReactorTransformer<>(resourceName))).expectNext(4).verifyComplete();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1000, cn.avgRt(), 20);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitEmptySuccess.
@Test
public void testEmitEmptySuccess() {
String resourceName = createResourceName("testEmitEmptySuccess");
StepVerifier.create(Mono.empty().transform(new SentinelReactorTransformer<>(resourceName))).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 ProviderFilterTest method testCustomFallback.
@Test
public void testCustomFallback() {
String url = "/test/hello";
String resourceName = "GET:" + url;
SentinelJaxRsConfig.setJaxRsFallback(new SentinelJaxRsFallback() {
@Override
public javax.ws.rs.core.Response fallbackResponse(String route, Throwable cause) {
return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.OK).entity("Blocked by Sentinel (flow limiting)").type(MediaType.APPLICATION_JSON_TYPE).build();
}
@Override
public Future<javax.ws.rs.core.Response> fallbackFutureResponse(final String route, final Throwable cause) {
return new FutureTask<>(new Callable<javax.ws.rs.core.Response>() {
@Override
public javax.ws.rs.core.Response call() throws Exception {
return fallbackResponse(route, cause);
}
});
}
});
configureRulesFor(resourceName, 0);
Response response = given().get(url);
response.then().statusCode(javax.ws.rs.core.Response.Status.OK.getStatusCode()).body(equalTo("Blocked by Sentinel (flow limiting)"));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ProviderFilterTest method testDefaultFallback.
@Test
public void testDefaultFallback() {
String url = "/test/hello";
String resourceName = "GET:" + url;
configureRulesFor(resourceName, 0);
Response response = given().get(url);
response.then().statusCode(javax.ws.rs.core.Response.Status.TOO_MANY_REQUESTS.getStatusCode()).body(equalTo("Blocked by Sentinel (flow limiting)"));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
}
Aggregations