Merge branch '6.0.x'
This commit is contained in:
@@ -212,10 +212,9 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
|
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
|
||||||
Duration initialDelay = Duration.between(this.clock.instant(), startTime);
|
Duration delay = Duration.between(this.clock.instant(), startTime);
|
||||||
try {
|
try {
|
||||||
return this.scheduledExecutor.schedule(decorateTask(task, false),
|
return this.scheduledExecutor.schedule(decorateTask(task, false), NANO.convert(delay), NANO);
|
||||||
NANO.convert(initialDelay), NANO);
|
|
||||||
}
|
}
|
||||||
catch (RejectedExecutionException ex) {
|
catch (RejectedExecutionException ex) {
|
||||||
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
|
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc
|
|||||||
if (this.scheduledExecutionTime == null) {
|
if (this.scheduledExecutionTime == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Duration initialDelay = Duration.between(this.triggerContext.getClock().instant(), this.scheduledExecutionTime);
|
Duration delay = Duration.between(this.triggerContext.getClock().instant(), this.scheduledExecutionTime);
|
||||||
this.currentFuture = this.executor.schedule(this, initialDelay.toNanos(), TimeUnit.NANOSECONDS);
|
this.currentFuture = this.executor.schedule(this, delay.toNanos(), TimeUnit.NANOSECONDS);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -377,10 +377,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||||||
@Override
|
@Override
|
||||||
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
|
public ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
|
||||||
ScheduledExecutorService executor = getScheduledExecutor();
|
ScheduledExecutorService executor = getScheduledExecutor();
|
||||||
Duration initialDelay = Duration.between(this.clock.instant(), startTime);
|
Duration delay = Duration.between(this.clock.instant(), startTime);
|
||||||
try {
|
try {
|
||||||
return executor.schedule(errorHandlingTask(task, false),
|
return executor.schedule(errorHandlingTask(task, false), NANO.convert(delay), NANO);
|
||||||
NANO.convert(initialDelay), NANO);
|
|
||||||
}
|
}
|
||||||
catch (RejectedExecutionException ex) {
|
catch (RejectedExecutionException ex) {
|
||||||
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
|
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
|
||||||
|
|||||||
@@ -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
|
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
|
||||||
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
||||||
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"!
|
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "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
|
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
|
||||||
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
||||||
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"!
|
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "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
|
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
|
||||||
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
|
||||||
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"!
|
* the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "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...)
|
* @see java.nio.file.spi.FileSystemProvider#newInputStream(Path, OpenOption...)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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...)
|
* @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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.nio.file.Path#toUri()
|
||||||
* @see java.net.URI#toURL()
|
* @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()
|
* @see java.nio.file.Path#toUri()
|
||||||
*/
|
*/
|
||||||
@Override
|
@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
|
@Override
|
||||||
public File getFile() throws IOException {
|
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...)
|
* @see Files#newByteChannel(Path, OpenOption...)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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...)
|
* @see Files#newByteChannel(Path, OpenOption...)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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...)
|
* @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...)
|
||||||
*/
|
*/
|
||||||
@Override
|
@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.
|
* relative to the path of the underlying file of this resource descriptor.
|
||||||
* @see java.nio.file.Path#resolve(String)
|
* @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
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class PathResourceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doesNotExistIsNotReadable() {
|
void nonExistingFileIsNotReadable() {
|
||||||
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
||||||
assertThat(resource.isReadable()).isFalse();
|
assertThat(resource.isReadable()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ class PathResourceTests {
|
|||||||
void getInputStream() throws IOException {
|
void getInputStream() throws IOException {
|
||||||
PathResource resource = new PathResource(TEST_FILE);
|
PathResource resource = new PathResource(TEST_FILE);
|
||||||
byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
|
byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
|
||||||
assertThat(bytes.length).isGreaterThan(0);
|
assertThat(bytes).hasSizeGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -167,7 +167,7 @@ class PathResourceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getInputStreamDoesNotExist() throws IOException {
|
void getInputStreamForNonExistingFile() throws IOException {
|
||||||
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
||||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
|
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
|
||||||
}
|
}
|
||||||
@@ -260,24 +260,26 @@ class PathResourceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void equalsAndHashCode() {
|
void equalsAndHashCode() {
|
||||||
Resource mr1 = new PathResource(TEST_FILE);
|
Resource resource1 = new PathResource(TEST_FILE);
|
||||||
Resource mr2 = new PathResource(TEST_FILE);
|
Resource resource2 = new PathResource(TEST_FILE);
|
||||||
Resource mr3 = new PathResource(TEST_DIR);
|
Resource resource3 = new PathResource(TEST_DIR);
|
||||||
assertThat(mr1).isEqualTo(mr2);
|
assertThat(resource1).isEqualTo(resource1);
|
||||||
assertThat(mr1).isNotEqualTo(mr3);
|
assertThat(resource1).isEqualTo(resource2);
|
||||||
assertThat(mr1).hasSameHashCodeAs(mr2);
|
assertThat(resource2).isEqualTo(resource1);
|
||||||
assertThat(mr1).doesNotHaveSameHashCodeAs(mr3);
|
assertThat(resource1).isNotEqualTo(resource3);
|
||||||
|
assertThat(resource1).hasSameHashCodeAs(resource2);
|
||||||
|
assertThat(resource1).doesNotHaveSameHashCodeAs(resource3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void outputStream(@TempDir Path temporaryFolder) throws IOException {
|
void getOutputStreamForExistingFile(@TempDir Path temporaryFolder) throws IOException {
|
||||||
PathResource resource = new PathResource(temporaryFolder.resolve("test"));
|
PathResource resource = new PathResource(temporaryFolder.resolve("test"));
|
||||||
FileCopyUtils.copy("test".getBytes(StandardCharsets.UTF_8), resource.getOutputStream());
|
FileCopyUtils.copy("test".getBytes(StandardCharsets.UTF_8), resource.getOutputStream());
|
||||||
assertThat(resource.contentLength()).isEqualTo(4L);
|
assertThat(resource.contentLength()).isEqualTo(4L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doesNotExistOutputStream(@TempDir Path temporaryFolder) throws IOException {
|
void getOutputStreamForNonExistingFile(@TempDir Path temporaryFolder) throws IOException {
|
||||||
File file = temporaryFolder.resolve("test").toFile();
|
File file = temporaryFolder.resolve("test").toFile();
|
||||||
file.delete();
|
file.delete();
|
||||||
PathResource resource = new PathResource(file.toPath());
|
PathResource resource = new PathResource(file.toPath());
|
||||||
@@ -286,7 +288,7 @@ class PathResourceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void directoryOutputStream() throws IOException {
|
void getOutputStreamForDirectory() {
|
||||||
PathResource resource = new PathResource(TEST_DIR);
|
PathResource resource = new PathResource(TEST_DIR);
|
||||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
|
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
|
||||||
}
|
}
|
||||||
@@ -314,7 +316,7 @@ class PathResourceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getReadableByteChannelDoesNotExist() throws IOException {
|
void getReadableByteChannelForNonExistingFile() throws IOException {
|
||||||
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
||||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
|
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user