use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class CommonFilterTest method testUrlCleaner.
private void testUrlCleaner() throws Exception {
final String fooPrefix = "/foo/";
String url1 = fooPrefix + 1;
String url2 = fooPrefix + 2;
WebCallbackManager.setUrlCleaner(new UrlCleaner() {
@Override
public String clean(String originUrl) {
if (originUrl.startsWith(fooPrefix)) {
return "/foo/*";
}
return originUrl;
}
});
this.mvc.perform(get(url1).accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()).andExpect(content().string("Hello 1"));
this.mvc.perform(get(url2).accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()).andExpect(content().string("Hello 2"));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(fooPrefix + "*");
assertEquals(2, cn.passQps(), 0.01);
assertNull(ClusterBuilderSlot.getClusterNode(url1));
assertNull(ClusterBuilderSlot.getClusterNode(url2));
WebCallbackManager.setUrlCleaner(new DefaultUrlCleaner());
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class CommonFilterTest method testCommonFilterMiscellaneous.
@Test
public void testCommonFilterMiscellaneous() throws Exception {
Constants.ROOT.removeChildList();
String url = "/hello";
this.mvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(HELLO_STR));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
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);
testCommonBlockAndRedirectBlockPage(url, cn);
// Test for url cleaner.
testUrlCleaner();
testUrlExclusion();
testCustomOriginParser();
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelSpringMvcIntegrationTest method testRuntimeException.
@Test
public void testRuntimeException() throws Exception {
String url = "/runtimeException";
configureExceptionRulesFor(url, 3, null);
int repeat = 3;
for (int i = 0; i < repeat; i++) {
this.mvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(ResultWrapper.error().toJsonString()));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
assertNotNull(cn);
assertEquals(i + 1, cn.passQps(), 0.01);
}
// This will be blocked and response json.
this.mvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(ResultWrapper.blocked().toJsonString()));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
assertNotNull(cn);
assertEquals(repeat, cn.passQps(), 0.01);
assertEquals(1, cn.blockRequest(), 1);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelSpringMvcIntegrationTest method testTotalInterceptor.
@Test
public void testTotalInterceptor() throws Exception {
String url = "/hello";
String totalTarget = "my_spring_mvc_total_url_request";
for (int i = 0; i < 3; i++) {
this.mvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(HELLO_STR));
}
ClusterNode cn = ClusterBuilderSlot.getClusterNode(totalTarget);
assertNotNull(cn);
assertEquals(3, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class SentinelSpringMvcIntegrationTest method testBase.
@Test
public void testBase() throws Exception {
String url = "/hello";
this.mvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(HELLO_STR));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(url);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
}
Aggregations