Search in sources :

Example 1 with EntranceNode

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

the class ClientFilterTest method testClientGetHello.

@Test
public void testClientGetHello() {
    final String url = "/test/hello";
    String resourceName = "GET:" + url;
    Response response = SentinelJaxRsClientTemplate.execute(resourceName, new Supplier<Response>() {

        @Override
        public Response get() {
            return client.target(host).path(url).request().get();
        }
    });
    assertEquals(200, response.getStatus());
    assertEquals(HELLO_STR, response.readEntity(String.class));
    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(javax.ws.rs.core.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) Test(org.junit.Test)

Example 2 with EntranceNode

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

the class ProviderFilterTest method testGetHello.

@Test
public void testGetHello() {
    String url = "/test/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) Test(org.junit.Test)

Example 3 with EntranceNode

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

the class ProviderFilterTest 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) Test(org.junit.Test)

Example 4 with EntranceNode

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

the class MonoSentinelOperatorIntegrationTest method testTransformMonoWithSentinelContextEnter.

@Test
public void testTransformMonoWithSentinelContextEnter() {
    String resourceName = createResourceName("testTransformMonoWithSentinelContextEnter");
    String contextName = "test_reactive_context";
    String origin = "originA";
    FlowRuleManager.loadRules(Collections.singletonList(new FlowRule(resourceName).setCount(0).setLimitApp(origin).as(FlowRule.class)));
    StepVerifier.create(Mono.just(2).transform(new SentinelReactorTransformer<>(// Customized context with origin.
    new EntryConfig(resourceName, EntryType.OUT, new ContextConfig(contextName, origin))))).expectError(BlockException.class).verify();
    ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
    assertNotNull(cn);
    assertEquals(0, cn.passQps(), 0.01);
    assertEquals(1, cn.blockRequest());
    assertTrue(Constants.ROOT.getChildList().stream().filter(node -> node instanceof EntranceNode).map(e -> (EntranceNode) e).anyMatch(e -> e.getId().getName().equals(contextName)));
    FlowRuleManager.loadRules(new ArrayList<>());
}
Also used : ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) StepVerifier(reactor.test.StepVerifier) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) FlowRuleManager(com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager) ArrayList(java.util.ArrayList) Constants(com.alibaba.csp.sentinel.Constants) Flux(reactor.core.publisher.Flux) BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) ClusterBuilderSlot(com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot) Duration(java.time.Duration) EntryType(com.alibaba.csp.sentinel.EntryType) ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) Assert(org.junit.Assert) Collections(java.util.Collections) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) EntranceNode(com.alibaba.csp.sentinel.node.EntranceNode) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Test(org.junit.Test)

Example 5 with EntranceNode

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

the class SentinelJaxRsQuarkusAdapterTest method testGetHello.

@Test
public void testGetHello() {
    String url = "/test/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