Java Code Examples for com.alibaba.csp.sentinel.node.DefaultNode#getChildList()

The following examples show how to use com.alibaba.csp.sentinel.node.DefaultNode#getChildList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FetchTreeCommandHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: FetchTreeCommandHandler.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: FetchJsonTreeCommandHandler.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Preorder traversal.
 */
private void visit(DefaultNode node, List<NodeVo> results, String parentId) {
    NodeVo vo = NodeVo.fromDefaultNode(node, parentId);
    results.add(vo);
    String id = vo.getId();
    for (Node n : node.getChildList()) {
        visit((DefaultNode)n, results, id);
    }
}
 
Example 4
Source File: AsyncEntryIntegrationTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private DefaultNode shouldHasChildFor(DefaultNode root, String resourceName, boolean check) {
    if (root == null) {
        if (check) {
            fail("Root node should not be empty");
        } else {
            return null;
        }
    }
    Set<Node> nodeSet = root.getChildList();
    if (nodeSet == null || nodeSet.isEmpty()) {
        if (check) {
            fail("Child nodes should not be empty: " + root.getId().getName());
        } else {
            return null;
        }
    }
    for (Node node : nodeSet) {
        if (node instanceof DefaultNode) {
            DefaultNode dn = (DefaultNode) node;
            if (dn.getId().getName().equals(resourceName)) {
                return dn;
            }
        }
    }

    if (check) {
        fail(String.format("The given node <%s> does not have child for resource <%s>",
            root.getId().getName(), resourceName));
    }
    return null;
}
 
Example 5
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private DefaultNode getNode(String resourceName, DefaultNode root) {

        Queue<DefaultNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            DefaultNode temp = queue.poll();
            if (temp.getId().getName().equals(resourceName)) {
                return temp;
            }
            for (Node node : temp.getChildList()) {
                queue.offer((DefaultNode) node);
            }
        }
        return null;
    }
 
Example 6
Source File: AsyncEntryIntegrationTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private DefaultNode shouldHasChildFor(DefaultNode root, String resourceName, boolean check) {
    if (root == null) {
        if (check) {
            fail("Root node should not be empty");
        } else {
            return null;
        }
    }
    Set<Node> nodeSet = root.getChildList();
    if (nodeSet == null || nodeSet.isEmpty()) {
        if (check) {
            fail("Child nodes should not be empty: " + root.getId().getName());
        } else {
            return null;
        }
    }
    for (Node node : nodeSet) {
        if (node instanceof DefaultNode) {
            DefaultNode dn = (DefaultNode) node;
            if (dn.getId().getName().equals(resourceName)) {
                return dn;
            }
        }
    }

    if (check) {
        fail(String.format("The given node <%s> does not have child for resource <%s>",
            root.getId().getName(), resourceName));
    }
    return null;
}
 
Example 7
Source File: FetchJsonTreeCommandHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
/**
 * Preorder traversal.
 */
private void visit(DefaultNode node, List<NodeVo> results, String parentId) {
    NodeVo vo = NodeVo.fromDefaultNode(node, parentId);
    results.add(vo);
    String id = vo.getId();
    for (Node n : node.getChildList()) {
        visit((DefaultNode)n, results, id);
    }
}
 
Example 8
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = filter.getResourceName(invoker, invocation);
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNull(curEntry.getOriginNode());// As context origin is not "", no originNode should be created in curEntry

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 9
Source File: SentinelDubboProviderFilterTest.java    From dubbo-sentinel-support with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(resourceName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(String originApplication, Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As ContextUtil.enter(resourceName, application) in SentinelDubboProviderFilter
    String resourceName = DubboUtils.getResourceName(invoker, invocation);
    assertEquals(resourceName, context.getName());
    assertEquals(originApplication, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(resourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNotNull(curEntry.getOriginNode());// As context origin is not "", originNode should be created

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(originApplication));

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(originApplication));
}
 
Example 10
Source File: SentinelDubboConsumerFilterTest.java    From dubbo-sentinel-support with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = DubboUtils.getResourceName(invoker, invocation);
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNull(curEntry.getOriginNode());// As context origin is not "", no originNode should be created in curEntry

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 11
Source File: SentinelDubboProviderFilterTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(resourceName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(String originApplication, Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As ContextUtil.enter(resourceName, application) in SentinelDubboProviderFilter
    String resourceName = filter.getResourceName(invoker, invocation);
    assertEquals(resourceName, context.getName());
    assertEquals(originApplication, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(resourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNotNull(curEntry.getOriginNode());// As context origin is not "", originNode should be created

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(originApplication));

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(originApplication));
}
 
Example 12
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = DubboUtils.getResourceName(invoker, invocation);
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNull(curEntry.getOriginNode());// As context origin is not "", no originNode should be created in curEntry

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 13
Source File: SentinelDubboProviderFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(methodResourceName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(methodResourceName)
 */
private void verifyInvocationStructure(String originApplication, Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As ContextUtil.enter(resourceName, application) in SentinelDubboProviderFilter
    String methodResourceName = filter.getMethodName(invoker, invocation);
    assertEquals(methodResourceName, context.getName());
    assertEquals(originApplication, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(methodResourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();

    assertEquals(filter.getInterfaceName(invoker), interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getEntryType());

    // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(methodResourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNotNull(curEntry.getOriginNode());// As context origin is not "", originNode should be created

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(originApplication));

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(originApplication));
}
 
Example 14
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);
    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = consumerFilter.getMethodName(invoker, invocation);
    assertEquals(com.alibaba.csp.sentinel.Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();

    assertEquals(com.alibaba.csp.sentinel.Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = getNode(DubboUtils.getInterfaceName(invoker), entranceNode);
    ResourceWrapper interfaceResource = interfaceNode.getId();

    assertEquals(DubboUtils.getInterfaceName(invoker), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getEntryType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = getNode(resourceName, entranceNode);
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNull(curEntry.getOriginNode());// As context origin is not "", no originNode should be created in curEntry

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 15
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
private void verifyInvocationStructureForAsyncCall(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = consumerFilter.getMethodName(invoker, invocation);
    assertEquals(com.alibaba.csp.sentinel.Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(com.alibaba.csp.sentinel.Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(2, childList.size());
    DefaultNode interfaceNode = getNode(DubboUtils.getInterfaceName(invoker), entranceNode);
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DubboUtils.getInterfaceName(invoker), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getEntryType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(0, childList.size());
    DefaultNode methodNode = getNode(resourceName, entranceNode);
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getEntryType());

    // Verify curEntry
    // nothing will bind to local context when use the AsyncEntry
    Entry curEntry = context.getCurEntry();
    assertNull(curEntry);

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 16
Source File: SentinelDubboProviderFilterTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(resourceName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(String originApplication, Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As ContextUtil.enter(resourceName, application) in SentinelDubboProviderFilter
    String resourceName = DubboUtils.getResourceName(invoker, invocation);
    assertEquals(resourceName, context.getName());
    assertEquals(originApplication, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(resourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getType());

    // As SphU.entry(interfaceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getType());

    // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNotNull(curEntry.getOriginNode());// As context origin is not "", originNode should be created

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(originApplication));

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(originApplication));
}
 
Example 17
Source File: SentinelSofaRpcProviderFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Verify Sentinel invocation structure in memory:
 * EntranceNode(methodResourceName)
 * --InterfaceNode(interfaceResourceName)
 * ----MethodNode(methodResourceName)
 */
private void verifyInvocationStructure(String applicationName, String interfaceResourceName, String methodResourceName) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    assertEquals(methodResourceName, context.getName());
    assertEquals(applicationName, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(methodResourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceResourceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(interfaceResourceName, interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getEntryType());

    // As SphU.entry(methodResourceName, EntryType.IN, 1, methodArguments);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(methodResourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    // As context origin is not "", originNode should be created
    assertNotNull(curEntry.getOriginNode());

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    // Different resource->Different ProcessorSlot->Different ClusterNode
    assertNotSame(methodClusterNode, interfaceClusterNode);

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(applicationName));
    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(applicationName));
}
 
Example 18
Source File: SentinelSofaRpcConsumerFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Verify Sentinel invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(String interfaceResourceName, String methodResourceName) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(methodResourceName, applicationName) in SentinelSofaRpcConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelSofaRpcProviderFilter
    // If consumer is on the top of SOFARPC invocation chain, use default context
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceResourceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(interfaceResourceName, interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getEntryType());

    // As SphU.entry(methodResourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(methodResourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    // As context origin is not "", no originNode should be created in curEntry
    assertNull(curEntry.getOriginNode());

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    // Different resource->Different ProcessorSlot->Different ClusterNode
    assertNotSame(methodClusterNode, interfaceClusterNode);

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}
 
Example 19
Source File: SentinelDubboProviderFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(resourceName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(String originApplication, Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As ContextUtil.enter(resourceName, application) in SentinelDubboProviderFilter
    String resourceName = filter.getResourceName(invoker, invocation);
    assertEquals(resourceName, context.getName());
    assertEquals(originApplication, context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(resourceName, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceName, EntryType.IN);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.IN, interfaceResource.getEntryType());

    // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.IN, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNotNull(curEntry.getOriginNode());// As context origin is not "", originNode should be created

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is not "", the StatisticNode should be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(1, methodOriginCountMap.size());
    assertTrue(methodOriginCountMap.containsKey(originApplication));

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(1, interfaceOriginCountMap.size());
    assertTrue(interfaceOriginCountMap.containsKey(originApplication));
}
 
Example 20
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Simply verify invocation structure in memory:
 * EntranceNode(defaultContextName)
 * --InterfaceNode(interfaceName)
 * ----MethodNode(resourceName)
 */
private void verifyInvocationStructure(Invoker invoker, Invocation invocation) {
    Context context = ContextUtil.getContext();
    assertNotNull(context);

    // As not call ContextUtil.enter(resourceName, application) in SentinelDubboConsumerFilter, use default context
    // In actual project, a consumer is usually also a provider, the context will be created by SentinelDubboProviderFilter
    // If consumer is on the top of Dubbo RPC invocation chain, use default context
    String resourceName = filter.getResourceName(invoker, invocation);
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, context.getName());
    assertEquals("", context.getOrigin());

    DefaultNode entranceNode = context.getEntranceNode();
    ResourceWrapper entranceResource = entranceNode.getId();
    assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName());
    assertSame(EntryType.IN, entranceResource.getEntryType());

    // As SphU.entry(interfaceName, EntryType.OUT);
    Set<Node> childList = entranceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode interfaceNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper interfaceResource = interfaceNode.getId();
    assertEquals(DemoService.class.getName(), interfaceResource.getName());
    assertSame(EntryType.OUT, interfaceResource.getEntryType());

    // As SphU.entry(resourceName, EntryType.OUT);
    childList = interfaceNode.getChildList();
    assertEquals(1, childList.size());
    DefaultNode methodNode = (DefaultNode) childList.iterator().next();
    ResourceWrapper methodResource = methodNode.getId();
    assertEquals(resourceName, methodResource.getName());
    assertSame(EntryType.OUT, methodResource.getEntryType());

    // Verify curEntry
    Entry curEntry = context.getCurEntry();
    assertSame(methodNode, curEntry.getCurNode());
    assertSame(interfaceNode, curEntry.getLastNode());
    assertNull(curEntry.getOriginNode());// As context origin is not "", no originNode should be created in curEntry

    // Verify clusterNode
    ClusterNode methodClusterNode = methodNode.getClusterNode();
    ClusterNode interfaceClusterNode = interfaceNode.getClusterNode();
    assertNotSame(methodClusterNode, interfaceClusterNode);// Different resource->Different ProcessorSlot->Different ClusterNode

    // As context origin is "", the StatisticNode should not be created in originCountMap of ClusterNode
    Map<String, StatisticNode> methodOriginCountMap = methodClusterNode.getOriginCountMap();
    assertEquals(0, methodOriginCountMap.size());

    Map<String, StatisticNode> interfaceOriginCountMap = interfaceClusterNode.getOriginCountMap();
    assertEquals(0, interfaceOriginCountMap.size());
}