]> git.basschouten.com Git - openhab-addons.git/blob
90a6c43177a1f32ad54472ecc74e2c279a5c99d6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.energidataservice.internal.retry.strategy;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.time.Duration;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.energidataservice.internal.retry.RetryStrategy;
23
24 /**
25  * Tests for {@link ExponentialBackoff}.
26  * 
27  * @author Jacob Laursen - Initial contribution
28  */
29 @NonNullByDefault
30 public class ExponentialBackoffTest {
31
32     @Test
33     void exponential() {
34         RetryStrategy retryPolicy = new ExponentialBackoff().withMinimum(Duration.ofSeconds(2)).withJitter(0.0);
35         for (long i = 2; i <= 256; i *= 2) {
36             assertThat(retryPolicy.getDuration().toSeconds(), is(i));
37         }
38     }
39 }