aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/tests/com/yahoo/jrt/slobrok/api/BackOffTestCase.java
blob: c4991d572d72f21109f0fed8b0f92a251b7312f7 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt.slobrok.api;

import org.junit.Test;
import static org.junit.Assert.*;

/**
 * @author arnej27959
 */
public class BackOffTestCase {

    static final double[] expectWait = {
        0.5, 1.0, 1.5, 2.0, 2.5,
        3.0, 3.5, 4.0, 4.5,
        5.0, 6.0, 7.0, 8.0, 9.0,
        10, 15, 20, 25, 30, 30, 30
    };

    @Test
    public void requireThatWaitTimesAreExpected() {
        double sum = 0;
        BackOffPolicy two = new BackOff();
        for (int i = 0; i < expectWait.length; i++) {
            double got = two.get();
            sum += got;
            assertEquals(expectWait[i], got, 0.001);
            boolean sw = two.shouldWarn(got);
/*
            System.err.println("i = "+i);
            System.err.println("got = "+got);
            System.err.println("sum = "+sum);
            System.err.println("sw = "+sw);
*/
            if (i == 13 || i > 17) {
                assertTrue(two.shouldWarn(got));
            } else {
                assertFalse(two.shouldWarn(got));
            }
        }
        two.reset();
        for (int i = 0; i < expectWait.length; i++) {
            double got = two.get();
            assertEquals(expectWait[i], got, 0.001);
            if (i == 13 || i > 17) {
                assertTrue(two.shouldWarn(got));
            } else {
                assertFalse(two.shouldWarn(got));
            }
        }

    }
}