aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java
blob: 40c224ec7817c6ed38a6c6f72f45a029d0104988 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.routing;

import com.yahoo.messagebus.ErrorCode;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author Simon Thoresen Hult
 */
public class RetryPolicyTestCase {

    private static final double SMALL = 0.00000000000000000001;

    @Test
    void testSimpleRetryPolicy() {
        RetryTransientErrorsPolicy policy = new RetryTransientErrorsPolicy();
        assertEquals(0.0, policy.getRetryDelay(0), SMALL);
        assertEquals(0.0, policy.getRetryDelay(1), SMALL);
        for (int i = 2; i < 15; i++) {
            assertEquals(0.001 * (1 << (i - 1)), policy.getRetryDelay(i), SMALL);
        }
        assertEquals(10.0, policy.getRetryDelay(15), SMALL);
        assertEquals(10.0, policy.getRetryDelay(20), SMALL);
        for (int j = ErrorCode.NONE; j < ErrorCode.ERROR_LIMIT; ++j) {
            policy.setEnabled(true);
            if (j < ErrorCode.FATAL_ERROR) {
                assertTrue(policy.canRetry(j));
            } else {
                assertFalse(policy.canRetry(j));
            }
            policy.setEnabled(false);
            assertFalse(policy.canRetry(j));
        }
    }

}