use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitExceptionWhenFlowControlTriggered.
@Test
public void testEmitExceptionWhenFlowControlTriggered() {
String resourceName = createResourceName("testEmitExceptionWhenFlowControlTriggered");
FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0)));
StepVerifier.create(Mono.error(new IllegalStateException("some")).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<>());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class MonoSentinelOperatorIntegrationTest method testEmitSingleError.
@Test
public void testEmitSingleError() {
String resourceName = createResourceName("testEmitSingleError");
StepVerifier.create(Mono.error(new IllegalStateException()).transform(new SentinelReactorTransformer<>(resourceName))).expectError(IllegalStateException.class).verify();
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.totalException());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelOkHttpInterceptorTest method testSentinelOkHttpInterceptor0.
@Test
public void testSentinelOkHttpInterceptor0() throws Exception {
// With prefix
SentinelOkHttpConfig config = new SentinelOkHttpConfig("okhttp:");
String url0 = "http://localhost:" + port + "/okhttp/back";
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new SentinelOkHttpInterceptor(config)).build();
Request request = new Request.Builder().url(url0).build();
System.out.println(client.newCall(request).execute().body().string());
ClusterNode cn = ClusterBuilderSlot.getClusterNode(config.getResourcePrefix() + "GET:" + url0);
assertNotNull(cn);
Constants.ROOT.removeChildList();
ClusterBuilderSlot.getClusterNodeMap().clear();
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelJaxRsQuarkusAdapterTest method testGetHello.
@Test
public void testGetHello() {
String url = "/test/hello";
String resourceName = "GET:" + url;
Response response = given().get(url);
response.then().statusCode(200).body(equalTo(HELLO_STR));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
String context = "";
for (Node n : Constants.ROOT.getChildList()) {
if (n instanceof EntranceNode) {
String id = ((EntranceNode) n).getId().getName();
if (url.equals(id)) {
context = ((EntranceNode) n).getId().getName();
}
}
}
assertEquals("", context);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelJaxRsQuarkusAdapterTest 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);
}
Aggregations