Search in sources :

Example 91 with ClusterNode

use of com.alibaba.csp.sentinel.node.ClusterNode 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)

Example 92 with ClusterNode

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

the class SentinelJaxRsQuarkusAdapterTest method testDefaultFallback.

@Test
public void testDefaultFallback() {
    String url = "/test/hello";
    String resourceName = "GET:" + url;
    configureRulesFor(resourceName, 0);
    Response response = given().get(url);
    response.then().statusCode(javax.ws.rs.core.Response.Status.TOO_MANY_REQUESTS.getStatusCode()).body(equalTo("Blocked by Sentinel (flow limiting)"));
    ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
    assertNotNull(cn);
    assertEquals(0, cn.passQps(), 0.01);
}
Also used : Response(io.restassured.response.Response) ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)92 Test (org.junit.Test)61 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)26 Response (io.restassured.response.Response)14 Node (com.alibaba.csp.sentinel.node.Node)13 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)13 Test (org.junit.jupiter.api.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 DefaultNode (com.alibaba.csp.sentinel.node.DefaultNode)11 Response (javax.ws.rs.core.Response)11 Context (com.alibaba.csp.sentinel.context.Context)10 ResourceWrapper (com.alibaba.csp.sentinel.slotchain.ResourceWrapper)10 EntranceNode (com.alibaba.csp.sentinel.node.EntranceNode)9 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)9 ArrayList (java.util.ArrayList)7 StatisticNode (com.alibaba.csp.sentinel.node.StatisticNode)6 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)6 ClusterBuilderSlot (com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot)6 Collections (java.util.Collections)6 Assert (org.junit.Assert)6