aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningThrottlerTest.java
blob: f38b4732ed7cfdbd5276890708f2a9fcd1d05f93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.yahoo.vespa.hosted.provision.provisioning;

import com.yahoo.vespa.hosted.provision.node.Agent;
import org.junit.jupiter.api.Test;

import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static com.yahoo.vespa.hosted.provision.provisioning.ProvisioningThrottler.throttle;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author mpolden
 */
class ProvisioningThrottlerTest {

    @Test
    void throttling() {
        Agent agent = Agent.system;
        Duration window = Duration.ofHours(1);
        assertFalse(throttle(199, 99, window, agent));
        assertTrue(throttle(200, 99, window, agent));
        assertFalse(throttle(40, 100, window, agent));
        assertTrue(throttle(41, 100, window, agent));
        assertTrue(throttle(100, 100, window, agent));
        assertFalse(throttle(200, 2100, window, agent));
        assertTrue(throttle(201, 2100, window, agent));
    }

}