pvary commented on code in PR #13997:
URL: https://github.com/apache/iceberg/pull/13997#discussion_r2371701836
##########
aws/src/integration/java/org/apache/iceberg/aws/s3/TestS3FileIO.java:
##########
@@ -966,6 +970,135 @@ public void
noStorageCredentialConfiguredWithoutCredentialsInProperties() {
.hasMessageContaining("Unable to load credentials from any of the
providers");
}
+ @Test
+ public void testVectoredRead() throws Exception {
+ String location = "s3://bucket/path/to/vectored-read.dat";
+ int dataSize = 1024 * 1024;
+
+ byte[] expected = new byte[dataSize];
+ random.nextBytes(expected);
+
+ InputFile inputFile = s3FileIO.newInputFile(location);
+ assertThat(inputFile.exists()).isFalse();
+
+ OutputFile out = s3FileIO.newOutputFile(location);
+ try (OutputStream os = out.createOrOverwrite()) {
+ IOUtil.writeFully(os, ByteBuffer.wrap(expected));
+ }
+
+ try (InputStream inputStream = inputFile.newStream()) {
+ assertThat(inputStream instanceof RangeReadable);
+ RangeReadable in = (RangeReadable) inputStream;
+
+ IntFunction<ByteBuffer> allocate = ByteBuffer::allocate;
+
+ List<FileRange> ranges = Lists.newArrayList();
+ CompletableFuture<ByteBuffer> future1 = new CompletableFuture<>();
+ CompletableFuture<ByteBuffer> future2 = new CompletableFuture<>();
+ CompletableFuture<ByteBuffer> future3 = new CompletableFuture<>();
+
+ // First range: first 1024 bytes
+ int range1Offset = 0;
+ int range1Length = 1024;
+ ranges.add(new FileRange(future1, range1Offset, range1Length));
+
+ // Second range: middle 2048 bytes
+ int range2Offset = dataSize / 2;
+ int range2Length = 2048;
+ ranges.add(new FileRange(future2, range2Offset, range2Length));
+
+ // Third range: last 1024 bytes
+ int range3Offset = dataSize - 1024;
+ int range3Length = 1024;
+ ranges.add(new FileRange(future3, range3Offset, range3Length));
+
+ in.readVectored(ranges, allocate);
+
+ ByteBuffer buffer1 = future1.get();
+ ByteBuffer buffer2 = future2.get();
+ ByteBuffer buffer3 = future3.get();
+
+ assertThat(future1.isDone()).isTrue();
+ assertThat(future2.isDone()).isTrue();
+ assertThat(future3.isDone()).isTrue();
+
+ assertThat(buffer1.limit()).isEqualTo(range1Length);
+ assertThat(buffer2.limit()).isEqualTo(range2Length);
+ assertThat(buffer3.limit()).isEqualTo(range3Length);
+
+ byte[] range1Data = new byte[range1Length];
+ byte[] range2Data = new byte[range2Length];
+ byte[] range3Data = new byte[range3Length];
+
+ buffer1.get(range1Data);
+ buffer2.get(range2Data);
+ buffer3.get(range3Data);
+ }
+ }
+
+ @Test
+ public void testVectoredReadWithNonContinuousRanges() throws Exception {
+
+ String location = "s3://bucket/path/to/vectored-read-overlapping.dat";
+ int dataSize = 1024 * 1024;
+
+ byte[] expected = new byte[dataSize];
+ random.nextBytes(expected);
+
+ InputFile inputFile = s3FileIO.newInputFile(location);
+ assertThat(inputFile.exists()).isFalse();
+
+ OutputFile out = s3FileIO.newOutputFile(location);
+ try (OutputStream os = out.createOrOverwrite()) {
+ IOUtil.writeFully(os, ByteBuffer.wrap(expected));
+ }
+
+ try (InputStream inputStream = inputFile.newStream()) {
+ assertThat(inputStream instanceof RangeReadable);
Review Comment:
```
assertInstanceOf(RangeReadable.class, inputStream);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]