|
21 | 21 | import org.junit.jupiter.api.Test;
|
22 | 22 | import org.junit.jupiter.api.TestInstance;
|
23 | 23 |
|
24 |
| -import software.amazon.nio.spi.s3.config.S3NioSpiConfiguration; |
25 |
| - |
26 | 24 | @DisplayName("Files$newByteChannel* should read and write on S3")
|
27 | 25 | @TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
28 | 26 | public class FilesNewByteChannelTest {
|
@@ -76,34 +74,58 @@ public void newByteChannel_READ_WRITE() throws IOException {
|
76 | 74 | assertThat(path).hasContent(text);
|
77 | 75 | }
|
78 | 76 |
|
| 77 | + @Test |
| 78 | + @DisplayName("newByteChannel with CRC32 integrity check") |
| 79 | + public void newByteChannel_withIntegrityCheck_CRC32() throws Exception { |
| 80 | + String text = "we test the integrity check when closing the byte channel"; |
| 81 | + |
| 82 | + withEnvironmentVariable("S3_INTEGRITY_CHECK_ALGORITHM", "CRC32").execute(() -> { |
| 83 | + var path = Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/bc-integrity-check.txt")); |
| 84 | + try (var channel = Files.newByteChannel(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) { |
| 85 | + channel.write(ByteBuffer.wrap(text.getBytes())); |
| 86 | + } |
| 87 | + |
| 88 | + assertThat(path).hasContent(text); |
| 89 | + }); |
| 90 | + } |
| 91 | + |
79 | 92 | @Test
|
80 | 93 | @DisplayName("newByteChannel with CRC32C integrity check")
|
81 | 94 | public void newByteChannel_withIntegrityCheck_CRC32C() throws Exception {
|
82 |
| - var path = Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/bc-integrity-check.txt")); |
83 |
| - |
84 | 95 | String text = "we test the integrity check when closing the byte channel";
|
85 |
| - withEnvironmentVariable(S3NioSpiConfiguration.S3_INTEGRITY_CHECK_ALGORITHM_PROPERTY, "CRC32C").execute(() -> { |
| 96 | + |
| 97 | + withEnvironmentVariable("S3_INTEGRITY_CHECK_ALGORITHM", "CRC32C").execute(() -> { |
| 98 | + var path = Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/bc-integrity-check.txt")); |
86 | 99 | try (var channel = Files.newByteChannel(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
87 | 100 | channel.write(ByteBuffer.wrap(text.getBytes()));
|
88 | 101 | }
|
89 |
| - }); |
90 | 102 |
|
91 |
| - assertThat(path).hasContent(text); |
| 103 | + assertThat(path).hasContent(text); |
| 104 | + }); |
92 | 105 | }
|
93 | 106 |
|
94 | 107 | @Test
|
95 | 108 | @DisplayName("newByteChannel with CRC64NVME integrity check")
|
96 | 109 | public void newByteChannel_withIntegrityCheck_CRC64NVME() throws Exception {
|
97 |
| - var path = Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/bc-integrity-check.txt")); |
98 |
| - |
99 | 110 | String text = "we test the integrity check when closing the byte channel";
|
100 |
| - withEnvironmentVariable(S3NioSpiConfiguration.S3_INTEGRITY_CHECK_ALGORITHM_PROPERTY, "CRC64NVME").execute(() -> { |
| 111 | + |
| 112 | + withEnvironmentVariable("S3_INTEGRITY_CHECK_ALGORITHM", "CRC64NVME").execute(() -> { |
| 113 | + var path = (S3Path) Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/bc-integrity-check.txt")); |
101 | 114 | try (var channel = Files.newByteChannel(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
102 | 115 | channel.write(ByteBuffer.wrap(text.getBytes()));
|
103 | 116 | }
|
| 117 | + |
| 118 | + assertThat(path).hasContent(text); |
104 | 119 | });
|
| 120 | + } |
105 | 121 |
|
106 |
| - assertThat(path).hasContent(text); |
| 122 | + @Test |
| 123 | + @DisplayName("newByteChannel with invalid integrity check") |
| 124 | + public void newByteChannel_withIntegrityCheck_invalid() throws Exception { |
| 125 | + withEnvironmentVariable("S3_INTEGRITY_CHECK_ALGORITHM", "invalid").execute(() -> { |
| 126 | + var path = Paths.get(URI.create(localStackConnectionEndpoint() + "/" + bucketName + "/int-check-algo-test.txt")); |
| 127 | + assertThatThrownBy(() -> Files.newByteChannel(path)).hasMessage("unknown integrity check algorithm 'invalid'"); |
| 128 | + }); |
107 | 129 | }
|
108 | 130 |
|
109 | 131 | }
|
0 commit comments