Merge branch '6.0.x'

This commit is contained in:
Sam Brannen
2023-06-30 14:17:49 +02:00
5 changed files with 35 additions and 35 deletions

View File

@@ -212,10 +212,9 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
@Override
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
Duration initialDelay = Duration.between(this.clock.instant(), startTime);
Duration delay = Duration.between(this.clock.instant(), startTime);
try {
return this.scheduledExecutor.schedule(decorateTask(task, false),
NANO.convert(initialDelay), NANO);
return this.scheduledExecutor.schedule(decorateTask(task, false), NANO.convert(delay), NANO);
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);

View File

@@ -79,8 +79,8 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc
if (this.scheduledExecutionTime == null) {
return null;
}
Duration initialDelay = Duration.between(this.triggerContext.getClock().instant(), this.scheduledExecutionTime);
this.currentFuture = this.executor.schedule(this, initialDelay.toNanos(), TimeUnit.NANOSECONDS);
Duration delay = Duration.between(this.triggerContext.getClock().instant(), this.scheduledExecutionTime);
this.currentFuture = this.executor.schedule(this, delay.toNanos(), TimeUnit.NANOSECONDS);
return this;
}
}

View File

@@ -377,10 +377,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
@Override
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
ScheduledExecutorService executor = getScheduledExecutor();
Duration initialDelay = Duration.between(this.clock.instant(), startTime);
Duration delay = Duration.between(this.clock.instant(), startTime);
try {
return executor.schedule(errorHandlingTask(task, false),
NANO.convert(initialDelay), NANO);
return executor.schedule(errorHandlingTask(task, false), NANO.convert(delay), NANO);
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);

View File

@@ -62,7 +62,7 @@ public class PathResource extends AbstractResource implements WritableResource {
/**
* Create a new PathResource from a Path handle.
* Create a new {@code PathResource} from a {@link Path} handle.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" &rarr; "C:/dir1/dir2"!
@@ -74,7 +74,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* Create a new PathResource from a Path handle.
* Create a new {@code PathResource} from a path string.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" &rarr; "C:/dir1/dir2"!
@@ -87,7 +87,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* Create a new PathResource from a Path handle.
* Create a new {@code PathResource} from a {@link URI}.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" &rarr; "C:/dir1/dir2"!
@@ -128,7 +128,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation opens a InputStream for the underlying file.
* This implementation opens an {@link InputStream} for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newInputStream(Path, OpenOption...)
*/
@Override
@@ -174,7 +174,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation opens a OutputStream for the underlying file.
* This implementation opens an {@link OutputStream} for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...)
*/
@Override
@@ -186,7 +186,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation returns a URL for the underlying file.
* This implementation returns a {@link URL} for the underlying file.
* @see java.nio.file.Path#toUri()
* @see java.net.URI#toURL()
*/
@@ -196,7 +196,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation returns a URI for the underlying file.
* This implementation returns a {@link URI} for the underlying file.
* @see java.nio.file.Path#toUri()
*/
@Override
@@ -213,7 +213,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation returns the underlying File reference.
* This implementation returns the underlying {@link File} reference.
*/
@Override
public File getFile() throws IOException {
@@ -228,7 +228,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation opens a Channel for the underlying file.
* This implementation opens a {@link ReadableByteChannel} for the underlying file.
* @see Files#newByteChannel(Path, OpenOption...)
*/
@Override
@@ -242,7 +242,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation opens a Channel for the underlying file.
* This implementation opens a {@link WritableByteChannel} for the underlying file.
* @see Files#newByteChannel(Path, OpenOption...)
*/
@Override
@@ -259,7 +259,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation returns the underlying File's timestamp.
* This implementation returns the underlying file's timestamp.
* @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...)
*/
@Override
@@ -270,7 +270,7 @@ public class PathResource extends AbstractResource implements WritableResource {
}
/**
* This implementation creates a PathResource, applying the given path
* This implementation creates a {@link PathResource}, applying the given path
* relative to the path of the underlying file of this resource descriptor.
* @see java.nio.file.Path#resolve(String)
*/
@@ -295,7 +295,7 @@ public class PathResource extends AbstractResource implements WritableResource {
/**
* This implementation compares the underlying Path references.
* This implementation compares the underlying {@link Path} references.
*/
@Override
public boolean equals(@Nullable Object obj) {

View File

@@ -142,7 +142,7 @@ class PathResourceTests {
}
@Test
void doesNotExistIsNotReadable() {
void nonExistingFileIsNotReadable() {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThat(resource.isReadable()).isFalse();
}
@@ -157,7 +157,7 @@ class PathResourceTests {
void getInputStream() throws IOException {
PathResource resource = new PathResource(TEST_FILE);
byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
assertThat(bytes.length).isGreaterThan(0);
assertThat(bytes).hasSizeGreaterThan(0);
}
@Test
@@ -167,7 +167,7 @@ class PathResourceTests {
}
@Test
void getInputStreamDoesNotExist() throws IOException {
void getInputStreamForNonExistingFile() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
}
@@ -260,24 +260,26 @@ class PathResourceTests {
@Test
void equalsAndHashCode() {
Resource mr1 = new PathResource(TEST_FILE);
Resource mr2 = new PathResource(TEST_FILE);
Resource mr3 = new PathResource(TEST_DIR);
assertThat(mr1).isEqualTo(mr2);
assertThat(mr1).isNotEqualTo(mr3);
assertThat(mr1).hasSameHashCodeAs(mr2);
assertThat(mr1).doesNotHaveSameHashCodeAs(mr3);
Resource resource1 = new PathResource(TEST_FILE);
Resource resource2 = new PathResource(TEST_FILE);
Resource resource3 = new PathResource(TEST_DIR);
assertThat(resource1).isEqualTo(resource1);
assertThat(resource1).isEqualTo(resource2);
assertThat(resource2).isEqualTo(resource1);
assertThat(resource1).isNotEqualTo(resource3);
assertThat(resource1).hasSameHashCodeAs(resource2);
assertThat(resource1).doesNotHaveSameHashCodeAs(resource3);
}
@Test
void outputStream(@TempDir Path temporaryFolder) throws IOException {
void getOutputStreamForExistingFile(@TempDir Path temporaryFolder) throws IOException {
PathResource resource = new PathResource(temporaryFolder.resolve("test"));
FileCopyUtils.copy("test".getBytes(StandardCharsets.UTF_8), resource.getOutputStream());
assertThat(resource.contentLength()).isEqualTo(4L);
}
@Test
void doesNotExistOutputStream(@TempDir Path temporaryFolder) throws IOException {
void getOutputStreamForNonExistingFile(@TempDir Path temporaryFolder) throws IOException {
File file = temporaryFolder.resolve("test").toFile();
file.delete();
PathResource resource = new PathResource(file.toPath());
@@ -286,7 +288,7 @@ class PathResourceTests {
}
@Test
void directoryOutputStream() throws IOException {
void getOutputStreamForDirectory() {
PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
}
@@ -314,7 +316,7 @@ class PathResourceTests {
}
@Test
void getReadableByteChannelDoesNotExist() throws IOException {
void getReadableByteChannelForNonExistingFile() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
}