Polish "Add maxAttempts to ExponentialBackOff"

See gh-27071
This commit is contained in:
Stephane Nicoll
2023-08-26 12:54:24 +02:00
parent f6a09f3fad
commit 609580bfb9
2 changed files with 25 additions and 22 deletions

View File

@@ -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);
}
}