Update configuration properties to use Duration
Update appropriate configuration properties to use the `Duration` type, rather than an ad-hoc mix of milliseconds or seconds. Configuration properties can now be defined in a consistent and readable way. For example `server.session.timeout=5m`. Properties that were previously declared using seconds are annotated with `@DurationUnit` to ensure a smooth upgrade experience. For example `server.session.timeout=20` continues to mean 20 seconds. Fixes gh-11080
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.devtools.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -120,7 +121,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
public void resourceCachePeriodIsZero() throws Exception {
|
||||
this.context = initializeAndRun(WebResourcesConfig.class);
|
||||
ResourceProperties properties = this.context.getBean(ResourceProperties.class);
|
||||
assertThat(properties.getCachePeriod()).isEqualTo(0);
|
||||
assertThat(properties.getCachePeriod()).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.devtools.classpath;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -104,7 +105,8 @@ public class ClassPathFileSystemWatcherTests {
|
||||
|
||||
@Bean
|
||||
public ClassPathFileSystemWatcher watcher() {
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(false, 100, 10);
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(false,
|
||||
Duration.ofMillis(100), Duration.ofMillis(10));
|
||||
URL[] urls = this.environment.getProperty("urls", URL[].class);
|
||||
return new ClassPathFileSystemWatcher(
|
||||
new MockFileSystemWatcherFactory(watcher), restartStrategy(), urls);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -66,21 +67,21 @@ public class FileSystemWatcherTests {
|
||||
public void pollIntervalMustBePositive() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("PollInterval must be positive");
|
||||
new FileSystemWatcher(true, 0, 1);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(0), Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quietPeriodMustBePositive() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("QuietPeriod must be positive");
|
||||
new FileSystemWatcher(true, 1, 0);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pollIntervalMustBeGreaterThanQuietPeriod() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("PollInterval must be greater than QuietPeriod");
|
||||
new FileSystemWatcher(true, 1, 1);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,7 +273,8 @@ public class FileSystemWatcherTests {
|
||||
}
|
||||
|
||||
private void setupWatcher(long pollingInterval, long quietPeriod) {
|
||||
this.watcher = new FileSystemWatcher(false, pollingInterval, quietPeriod);
|
||||
this.watcher = new FileSystemWatcher(false, Duration.ofMillis(pollingInterval),
|
||||
Duration.ofMillis(quietPeriod));
|
||||
this.watcher.addListener(
|
||||
(changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user