Browse Source

Use Duration.ZERO whenever possible

pull/35163/head
Sam Brannen 7 months ago
parent
commit
c6a8df4a9d
  1. 2
      spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java
  2. 2
      spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java
  3. 2
      spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java
  4. 2
      spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java
  5. 8
      spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java
  6. 4
      spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java
  7. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java
  8. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java

2
spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java

@ -52,7 +52,7 @@ public record MethodRetrySpec( @@ -52,7 +52,7 @@ public record MethodRetrySpec(
Duration maxDelay) {
public MethodRetrySpec(MethodRetryPredicate predicate, long maxAttempts, Duration delay) {
this(predicate, maxAttempts, delay, Duration.ofMillis(0), 1.0, Duration.ofMillis(Long.MAX_VALUE));
this(predicate, maxAttempts, delay, Duration.ZERO, 1.0, Duration.ofMillis(Long.MAX_VALUE));
}
public MethodRetrySpec(MethodRetryPredicate predicate, long maxAttempts, Duration delay,

2
spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java

@ -90,7 +90,7 @@ class ScheduledTaskTests { @@ -90,7 +90,7 @@ class ScheduledTaskTests {
@Test
void singleExecutionShouldNotHaveNextExecution() {
ScheduledTask scheduledTask = taskRegistrar.scheduleOneTimeTask(new OneTimeTask(countingRunnable, Duration.ofSeconds(0)));
ScheduledTask scheduledTask = taskRegistrar.scheduleOneTimeTask(new OneTimeTask(countingRunnable, Duration.ZERO));
Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> countingRunnable.executionCount > 0);
assertThat(scheduledTask.nextExecution()).isNull();
}

2
spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java

@ -39,7 +39,7 @@ class MaxAttemptsRetryPolicyTests { @@ -39,7 +39,7 @@ class MaxAttemptsRetryPolicyTests {
@Test
void maxAttempts() {
var retryPolicy = RetryPolicy.builder().maxAttempts(2).delay(Duration.ofMillis(0)).build();
var retryPolicy = RetryPolicy.builder().maxAttempts(2).delay(Duration.ZERO).build();
var backOffExecution = retryPolicy.getBackOff().start();
var throwable = mock(Throwable.class);

2
spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java

@ -209,7 +209,7 @@ class RetryPolicyTests { @@ -209,7 +209,7 @@ class RetryPolicyTests {
@Test
void maxDelayPreconditions() {
assertThatIllegalArgumentException()
.isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ofMillis(0)))
.isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ZERO))
.withMessage("Invalid duration (0ms): maxDelay must be positive.");
assertThatIllegalArgumentException()
.isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ofMillis(-1)))

8
spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

@ -51,7 +51,7 @@ class RetryTemplateTests { @@ -51,7 +51,7 @@ class RetryTemplateTests {
void configureRetryTemplate() {
var retryPolicy = RetryPolicy.builder()
.maxAttempts(3)
.delay(Duration.ofMillis(0))
.delay(Duration.ZERO)
.build();
retryTemplate.setRetryPolicy(retryPolicy);
@ -171,7 +171,7 @@ class RetryTemplateTests { @@ -171,7 +171,7 @@ class RetryTemplateTests {
var retryPolicy = RetryPolicy.builder()
.maxAttempts(Integer.MAX_VALUE)
.delay(Duration.ofMillis(0))
.delay(Duration.ZERO)
.includes(IOException.class)
.build();
@ -194,13 +194,13 @@ class RetryTemplateTests { @@ -194,13 +194,13 @@ class RetryTemplateTests {
argumentSet("Excludes",
RetryPolicy.builder()
.maxAttempts(Integer.MAX_VALUE)
.delay(Duration.ofMillis(0))
.delay(Duration.ZERO)
.excludes(FileNotFoundException.class)
.build()),
argumentSet("Includes & Excludes",
RetryPolicy.builder()
.maxAttempts(Integer.MAX_VALUE)
.delay(Duration.ofMillis(0))
.delay(Duration.ZERO)
.includes(IOException.class)
.excludes(FileNotFoundException.class)
.build())

4
spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java

@ -76,11 +76,11 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory { @@ -76,11 +76,11 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
/**
* Checks whether all the data buffers allocated by this factory have also been released.
* If not, then an {@link AssertionError} is thrown. Typically used from a JUnit <em>after</em>
* <p>If not, then an {@link AssertionError} is thrown. Typically used from a JUnit <em>after</em>
* method.
*/
public void checkForLeaks() {
checkForLeaks(Duration.ofSeconds(0));
checkForLeaks(Duration.ZERO);
}
/**

4
spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java

@ -71,7 +71,7 @@ class DispatcherHandlerTests { @@ -71,7 +71,7 @@ class DispatcherHandlerTests {
context.refresh();
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
new DispatcherHandler(context).handle(exchange).block(Duration.ZERO);
assertThat(exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5))).isEqualTo("1");
}
@ -94,7 +94,7 @@ class DispatcherHandlerTests { @@ -94,7 +94,7 @@ class DispatcherHandlerTests {
.build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
new DispatcherHandler(context).handle(exchange).block(Duration.ZERO);
verifyNoInteractions(webHandler);
}

2
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java

@ -91,7 +91,7 @@ class RequestParamMapMethodArgumentResolverTests { @@ -91,7 +91,7 @@ class RequestParamMapMethodArgumentResolverTests {
private Object resolve(MethodParameter parameter, ServerWebExchange exchange) {
return this.resolver.resolveArgument(parameter, null, exchange).block(Duration.ofMillis(0));
return this.resolver.resolveArgument(parameter, null, exchange).block(Duration.ZERO);
}

Loading…
Cancel
Save