Skip to content

Commit

Permalink
Merge branch '6.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 30, 2023
2 parents 41f8b69 + 3c05679 commit b8f091e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public ScheduledFuture<?> schedule() {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,9 @@ public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"!
Expand All @@ -74,7 +74,7 @@ public PathResource(Path path) {
}

/**
* 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"!
Expand All @@ -87,7 +87,7 @@ public PathResource(String path) {
}

/**
* 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"!
Expand Down Expand Up @@ -128,7 +128,7 @@ public boolean isReadable() {
}

/**
* 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
Expand Down Expand Up @@ -174,7 +174,7 @@ public boolean isWritable() {
}

/**
* 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
Expand All @@ -186,7 +186,7 @@ public OutputStream getOutputStream() throws IOException {
}

/**
* 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()
*/
Expand All @@ -196,7 +196,7 @@ public URL getURL() throws IOException {
}

/**
* 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
Expand All @@ -213,7 +213,7 @@ public boolean isFile() {
}

/**
* This implementation returns the underlying File reference.
* This implementation returns the underlying {@link File} reference.
*/
@Override
public File getFile() throws IOException {
Expand All @@ -228,7 +228,7 @@ public File getFile() throws IOException {
}

/**
* 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
Expand All @@ -242,7 +242,7 @@ public ReadableByteChannel readableChannel() throws IOException {
}

/**
* 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
Expand All @@ -259,7 +259,7 @@ public long contentLength() throws IOException {
}

/**
* 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
Expand All @@ -270,7 +270,7 @@ public long lastModified() throws IOException {
}

/**
* 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)
*/
Expand All @@ -295,7 +295,7 @@ public String getDescription() {


/**
* This implementation compares the underlying Path references.
* This implementation compares the underlying {@link Path} references.
*/
@Override
public boolean equals(@Nullable Object obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void fileIsReadable() {
}

@Test
void doesNotExistIsNotReadable() {
void nonExistingFileIsNotReadable() {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThat(resource.isReadable()).isFalse();
}
Expand All @@ -157,7 +157,7 @@ void directoryIsNotReadable() {
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
Expand All @@ -167,7 +167,7 @@ void getInputStreamForDir() throws IOException {
}

@Test
void getInputStreamDoesNotExist() throws IOException {
void getInputStreamForNonExistingFile() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
}
Expand Down Expand Up @@ -260,24 +260,26 @@ void directoryIsNotWritable() {

@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());
Expand All @@ -286,7 +288,7 @@ void doesNotExistOutputStream(@TempDir Path temporaryFolder) throws IOException
}

@Test
void directoryOutputStream() throws IOException {
void getOutputStreamForDirectory() {
PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
}
Expand Down Expand Up @@ -314,7 +316,7 @@ void getReadableByteChannelForDir() throws IOException {
}

@Test
void getReadableByteChannelDoesNotExist() throws IOException {
void getReadableByteChannelForNonExistingFile() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
}
Expand Down

0 comments on commit b8f091e

Please sign in to comment.