aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java
blob: 141681a277a00e62facc3934331b818d141e2ea7 (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
// Copyright 2016 Yahoo Inc. 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 junit.framework.TestCase;

/**
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
 */
public class RetryPolicyTestCase extends TestCase {

    public void testSimpleRetryPolicy() {
        RetryTransientErrorsPolicy policy = new RetryTransientErrorsPolicy();
        for (int i = 0; i < 5; ++i) {
            double delay = i / 3.0;
            policy.setBaseDelay(delay);
            for (int j = 0; j < 5; ++j) {
                assertEquals((int)(j * delay), (int)policy.getRetryDelay(j));
            }
            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));
            }
        }
    }
}