aboutsummaryrefslogtreecommitdiffstats
path: root/zookeeper-server/zookeeper-server-common/src/test/java/com/yahoo/vespa/zookeeper/ExponentialBackoffTest.java
blob: bc5c4531e51332b2111fcca3ba864017f1ae43c8 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.zookeeper;

import org.junit.Test;

import java.time.Duration;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.junit.Assert.assertEquals;

/**
 * @author mpolden
 */
public class ExponentialBackoffTest {

    @Test
    public void delay() {
        ExponentialBackoff b = new ExponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(10), new Random(1000));
        assertEquals(List.of(Duration.ofMillis(1210),
                             Duration.ofMillis(2150),
                             Duration.ofMillis(4340),
                             Duration.ofMillis(2157),
                             Duration.ofMillis(4932)),
                     IntStream.rangeClosed(1, 5)
                              .mapToObj(b::delay)
                              .toList());
    }

}