Search in sources :

Example 1 with TrafficShapingController

use of com.alibaba.csp.sentinel.slots.block.flow.TrafficShapingController in project Sentinel by alibaba.

the class DefaultControllerTest method testCanPassForQps.

@Test
public void testCanPassForQps() {
    double threshold = 10;
    TrafficShapingController controller = new DefaultController(threshold, RuleConstant.FLOW_GRADE_QPS);
    Node node = mock(Node.class);
    when(node.passQps()).thenReturn(threshold - 1).thenReturn(threshold);
    assertTrue(controller.canPass(node, 1));
    assertFalse(controller.canPass(node, 1));
}
Also used : Node(com.alibaba.csp.sentinel.node.Node) TrafficShapingController(com.alibaba.csp.sentinel.slots.block.flow.TrafficShapingController) Test(org.junit.Test)

Example 2 with TrafficShapingController

use of com.alibaba.csp.sentinel.slots.block.flow.TrafficShapingController in project Sentinel by alibaba.

the class DefaultControllerTest method testCanPassForThreadCount.

@Test
public void testCanPassForThreadCount() {
    int threshold = 8;
    TrafficShapingController controller = new DefaultController(threshold, RuleConstant.FLOW_GRADE_THREAD);
    Node node = mock(Node.class);
    when(node.curThreadNum()).thenReturn(threshold - 1).thenReturn(threshold);
    assertTrue(controller.canPass(node, 1));
    assertFalse(controller.canPass(node, 1));
}
Also used : Node(com.alibaba.csp.sentinel.node.Node) TrafficShapingController(com.alibaba.csp.sentinel.slots.block.flow.TrafficShapingController) Test(org.junit.Test)

Aggregations

Node (com.alibaba.csp.sentinel.node.Node)2 TrafficShapingController (com.alibaba.csp.sentinel.slots.block.flow.TrafficShapingController)2 Test (org.junit.Test)2