Search in sources :

Example 11 with EntranceNode

use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.

the class NodeSelectorTest method testMultipleEntrance.

@Test
public void testMultipleEntrance() throws Exception {
    final String firstEntry = "entry_multiple_one";
    final String anotherEntry = "entry_multiple_another";
    final String resName = "nodeA";
    Node firstNode, anotherNode;
    ContextUtil.enter(firstEntry);
    Entry nodeA = SphU.entry(resName);
    firstNode = ContextUtil.getContext().getCurNode();
    if (nodeA != null) {
        nodeA.exit();
    }
    ContextUtil.exit();
    ContextUtil.enter(anotherEntry);
    nodeA = SphU.entry(resName);
    anotherNode = ContextUtil.getContext().getCurNode();
    if (nodeA != null) {
        nodeA.exit();
    }
    assertNotSame(firstNode, anotherNode);
    for (Node node : Constants.ROOT.getChildList()) {
        EntranceNode firstEntrance = (EntranceNode) node;
        if (firstEntrance.getId().getName().equals(firstEntry)) {
            assertEquals(1, firstEntrance.getChildList().size());
            for (Node child : firstEntrance.getChildList()) {
                assertEquals(resName, ((DefaultNode) child).getId().getName());
            }
        } else if (firstEntrance.getId().getName().equals(anotherEntry)) {
            assertEquals(1, firstEntrance.getChildList().size());
            for (Node child : firstEntrance.getChildList()) {
                assertEquals(resName, ((DefaultNode) child).getId().getName());
            }
        } else {
            System.out.println("Multiple entries: " + firstEntrance.getId().getName());
        }
    }
    ContextUtil.exit();
}
Also used : Entry(com.alibaba.csp.sentinel.Entry) 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) Test(org.junit.Test)

Example 12 with EntranceNode

use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.

the class NodeSelectorTest method testSingleEntrance.

@Test
public void testSingleEntrance() throws Exception {
    final String contextName = "entry_SingleEntrance";
    ContextUtil.enter(contextName);
    EntranceNode entranceNode = null;
    for (Node node : Constants.ROOT.getChildList()) {
        entranceNode = (EntranceNode) node;
        if (entranceNode.getId().getName().equals(contextName)) {
            break;
        } else {
            System.out.println("Single entry: " + entranceNode.getId().getName());
        }
    }
    assertNotNull(entranceNode);
    assertTrue(entranceNode.getId().getName().equalsIgnoreCase(contextName));
    final String resName = "nodeA";
    Entry nodeA = SphU.entry(resName);
    assertNotNull(ContextUtil.getContext().getCurNode());
    assertEquals(resName, ((DefaultNode) ContextUtil.getContext().getCurNode()).getId().getName());
    boolean hasNode = false;
    for (Node node : entranceNode.getChildList()) {
        if (((DefaultNode) node).getId().getName().equals(resName)) {
            hasNode = true;
        }
    }
    assertTrue(hasNode);
    if (nodeA != null) {
        nodeA.exit();
    }
    ContextUtil.exit();
}
Also used : EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) Entry(com.alibaba.csp.sentinel.Entry) 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) Test(org.junit.Test)

Example 13 with EntranceNode

use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.

the class SentinelJaxRsQuarkusAdapterTest method testAsyncGetHello.

@Test
public void testAsyncGetHello() {
    String url = "/test/async-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);
}
Also used : Response(io.restassured.response.Response) 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) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

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