-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(Files): Add integration tests for Files.copy / read* #252
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
432d640
test(Files): Add integration tests for Files.copy / read* from issue …
guicamest 7e95317
chore(S3ClientProvider): reformat
guicamest d6ca42f
rewrite: Extract `getRegionFromRegionName` and `endpointURI` methods
guicamest 63c07d8
chore: Use `isBlank` instead of `trim().isEmpty()`
guicamest 9bd8b4f
rewrite(S3ClientProvider): Extract method to configure and build clie…
guicamest 7677368
fix(236): Use non-crt async client for `S3ReadAheadByteChannel`
guicamest abd07fd
chore: extract configureCrtClientForRegion method
guicamest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/integrationTest/java/software/amazon/nio/spi/s3/FilesCopyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package software.amazon.nio.spi.s3; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.nio.spi.s3.Containers.localStackConnectionEndpoint; | ||
import static software.amazon.nio.spi.s3.Containers.putObject; | ||
|
||
@DisplayName("Files$copy should load file contents from localstack") | ||
public class FilesCopyTest | ||
{ | ||
@TempDir | ||
Path tempDir; | ||
|
||
@Test | ||
@DisplayName("when doing copy of existing file") | ||
public void fileCopyShouldCopyFileWhenFileFound() throws IOException { | ||
Containers.createBucket("sink"); | ||
putObject("sink", "files-copy.txt", "some content"); | ||
final Path path = Paths.get(URI.create(localStackConnectionEndpoint() + "/sink/files-copy.txt")); | ||
Path copiedFile = Files.copy(path, tempDir.resolve("sample-file-local.txt")); | ||
assertThat(copiedFile).hasContent("some content"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/integrationTest/java/software/amazon/nio/spi/s3/FilesReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package software.amazon.nio.spi.s3; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static software.amazon.nio.spi.s3.Containers.localStackConnectionEndpoint; | ||
import static software.amazon.nio.spi.s3.Containers.putObject; | ||
|
||
@DisplayName("Files$read* should load file contents from localstack") | ||
public class FilesReadTest | ||
{ | ||
private final Path path = Paths.get(URI.create(localStackConnectionEndpoint() + "/sink/files-read.txt")); | ||
|
||
@BeforeAll | ||
public static void createBucketAndFile(){ | ||
Containers.createBucket("sink"); | ||
putObject("sink", "files-read.txt", "some content"); | ||
} | ||
|
||
@Test | ||
@DisplayName("when doing readAllBytes from existing file in s3") | ||
public void fileReadAllBytesShouldReturnFileContentsWhenFileFound() throws IOException { | ||
then(Files.readAllBytes(path)).isEqualTo("some content".getBytes()); | ||
} | ||
|
||
@Test | ||
@DisplayName("when doing readAllLines from existing file in s3") | ||
public void fileReadAllLinesShouldReturnFileContentWhenFileFound() throws IOException { | ||
then(String.join("", Files.readAllLines(path))).isEqualTo("some content"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you wouldn't just overload
client()
withclient(boolean crtClient)
? Either way, it is probably worth documenting why a CRT client is not used in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
client()
method saves a reference of that client in the current class. Unlikeclient()
,readClient()
creates a new client every time aread
needs to be done. This client is later closed when the readChannel isclose()
. I think it'd be clearer to have them in separate methods for now, one is a general purpose and the other one isonly for reads
.