Search in sources :

Example 1 with WarmUpRateLimiterController

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

the class WarmUpRateLimiterControllerTest method testPaceCanNotPass.

@Test
public void testPaceCanNotPass() throws InterruptedException {
    WarmUpRateLimiterController controller = new WarmUpRateLimiterController(10, 10, 10, 3);
    Node node = mock(Node.class);
    when(node.passQps()).thenReturn(100d);
    when(node.previousPassQps()).thenReturn(100d);
    assertTrue(controller.canPass(node, 1));
    assertFalse(controller.canPass(node, 1));
}
Also used : WarmUpRateLimiterController(com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpRateLimiterController) StatisticNode(com.alibaba.csp.sentinel.node.StatisticNode) Node(com.alibaba.csp.sentinel.node.Node) Test(org.junit.Test)

Example 2 with WarmUpRateLimiterController

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

the class WarmUpRateLimiterControllerTest method testPace.

@Test
public void testPace() throws InterruptedException {
    WarmUpRateLimiterController controller = new WarmUpRateLimiterController(10, 10, 1000, 3);
    Node node = mock(Node.class);
    when(node.passQps()).thenReturn(100d);
    when(node.previousPassQps()).thenReturn(100d);
    assertTrue(controller.canPass(node, 1));
    // Easily fail in single request testing, so we increase it to 10 requests and test the average time
    long start = System.currentTimeMillis();
    int requests = 10;
    for (int i = 0; i < requests; i++) {
        assertTrue(controller.canPass(node, 1));
    }
    float cost = (System.currentTimeMillis() - start) / 1.0f / requests;
    assertTrue(Math.abs(cost - 100) < 10);
}
Also used : WarmUpRateLimiterController(com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpRateLimiterController) StatisticNode(com.alibaba.csp.sentinel.node.StatisticNode) Node(com.alibaba.csp.sentinel.node.Node) Test(org.junit.Test)

Aggregations

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