Polish "Add maxAttempts to ExponentialBackOff"
See gh-27071
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ExponentialBackOff}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class ExponentialBackOffTests {
|
||||
@@ -137,15 +139,15 @@ class ExponentialBackOffTests {
|
||||
|
||||
@Test
|
||||
void maxAttempts() {
|
||||
ExponentialBackOff bo = new ExponentialBackOff();
|
||||
bo.setInitialInterval(1_000L);
|
||||
bo.setMultiplier(2.0);
|
||||
bo.setMaxInterval(10_000L);
|
||||
bo.setMaxAttempts(6);
|
||||
ExponentialBackOff backOff = new ExponentialBackOff();
|
||||
backOff.setInitialInterval(1000L);
|
||||
backOff.setMultiplier(2.0);
|
||||
backOff.setMaxInterval(10000L);
|
||||
backOff.setMaxAttempts(6);
|
||||
List<Long> delays = new ArrayList<>();
|
||||
BackOffExecution boEx = bo.start();
|
||||
IntStream.range(0, 7).forEach(i -> delays.add(boEx.nextBackOff()));
|
||||
assertThat(delays).containsExactly(1_000L, 2_000L, 4_000L, 8_000L, 10_000L, 10_000L, -1L);
|
||||
BackOffExecution execution = backOff.start();
|
||||
IntStream.range(0, 7).forEach(i -> delays.add(execution.nextBackOff()));
|
||||
assertThat(delays).containsExactly(1000L, 2000L, 4000L, 8000L, 10000L, 10000L, BackOffExecution.STOP);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user