Search in sources :

Example 6 with EntranceNode

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);
}
Also used : ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) Node(com.alibaba.csp.sentinel.node.Node) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with EntranceNode

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;
}
Also used : StringResourceWrapper(com.alibaba.csp.sentinel.slotchain.StringResourceWrapper) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) HashMap(java.util.HashMap) DefaultNode(com.alibaba.csp.sentinel.node.DefaultNode)

Example 8 with EntranceNode

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);
    }
}
Also used : EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) DefaultNode(com.alibaba.csp.sentinel.node.DefaultNode) Node(com.alibaba.csp.sentinel.node.Node) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) DefaultNode(com.alibaba.csp.sentinel.node.DefaultNode)

Example 9 with EntranceNode

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();
}
Also used : ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) Node(com.alibaba.csp.sentinel.node.Node) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with EntranceNode

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);
}
Also used : StringResourceWrapper(com.alibaba.csp.sentinel.slotchain.StringResourceWrapper) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode)

Aggregations

EntranceNode (com.alibaba.csp.sentinel.node.EntranceNode)13 Node (com.alibaba.csp.sentinel.node.Node)10 ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)8 Test (org.junit.Test)8 DefaultNode (com.alibaba.csp.sentinel.node.DefaultNode)4 Response (io.restassured.response.Response)4 Entry (com.alibaba.csp.sentinel.Entry)2 StringResourceWrapper (com.alibaba.csp.sentinel.slotchain.StringResourceWrapper)2 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Constants (com.alibaba.csp.sentinel.Constants)1 EntryType (com.alibaba.csp.sentinel.EntryType)1 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)1 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)1 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)1 ClusterBuilderSlot (com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1