use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class CommonFilterContextTest method testCommonFilterMiscellaneous.
@Test
public void testCommonFilterMiscellaneous() 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);
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(url, context);
}
use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class ContextUtil method trueEnter.
protected static Context trueEnter(String name, String origin) {
Context context = contextHolder.get();
if (context == null) {
Map<String, DefaultNode> localCacheNameMap = contextNameNodeMap;
DefaultNode node = localCacheNameMap.get(name);
if (node == null) {
if (localCacheNameMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) {
setNullContext();
return NULL_CONTEXT;
} else {
LOCK.lock();
try {
node = contextNameNodeMap.get(name);
if (node == null) {
if (contextNameNodeMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) {
setNullContext();
return NULL_CONTEXT;
} else {
node = new EntranceNode(new StringResourceWrapper(name, EntryType.IN), null);
// Add entrance node.
Constants.ROOT.addChild(node);
Map<String, DefaultNode> newMap = new HashMap<>(contextNameNodeMap.size() + 1);
newMap.putAll(contextNameNodeMap);
newMap.put(name, node);
contextNameNodeMap = newMap;
}
}
} finally {
LOCK.unlock();
}
}
}
context = new Context(node, name);
context.setOrigin(origin);
contextHolder.set(context);
}
return context;
}
use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class FetchTreeCommandHandler method visitTree.
private void visitTree(int level, DefaultNode node, /*@NonNull*/
StringBuilder sb) {
for (int i = 0; i < level; ++i) {
sb.append("-");
}
if (!(node instanceof EntranceNode)) {
sb.append(String.format("%s(t:%s pq:%s bq:%s tq:%s rt:%s prq:%s 1mp:%s 1mb:%s 1mt:%s)", node.getId().getShowName(), node.curThreadNum(), node.passQps(), node.blockQps(), node.totalQps(), node.avgRt(), node.successQps(), node.totalRequest() - node.blockRequest(), node.blockRequest(), node.totalRequest())).append("\n");
} else {
sb.append(String.format("EntranceNode: %s(t:%s pq:%s bq:%s tq:%s rt:%s prq:%s 1mp:%s 1mb:%s 1mt:%s)", node.getId().getShowName(), node.curThreadNum(), node.passQps(), node.blockQps(), node.totalQps(), node.avgRt(), node.successQps(), node.totalRequest() - node.blockRequest(), node.blockRequest(), node.totalRequest())).append("\n");
}
for (Node n : node.getChildList()) {
DefaultNode dn = (DefaultNode) n;
visitTree(level + 1, dn, sb);
}
}
use of com.alibaba.csp.sentinel.node.EntranceNode 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.EntranceNode in project Sentinel by alibaba.
the class ContextUtil method initDefaultContext.
private static void initDefaultContext() {
String defaultContextName = Constants.CONTEXT_DEFAULT_NAME;
EntranceNode node = new EntranceNode(new StringResourceWrapper(defaultContextName, EntryType.IN), null);
Constants.ROOT.addChild(node);
contextNameNodeMap.put(defaultContextName, node);
}
Aggregations