-
Notifications
You must be signed in to change notification settings - Fork 3k
AWS: add more S3FileIO tests, cleanup related codebase #1900
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
192 changes: 192 additions & 0 deletions
192
aws/src/integration/java/org/apache/iceberg/aws/s3/S3MultipartUploadTest.java
This file contains hidden or 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,192 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iceberg.aws.s3; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Random; | ||
| import java.util.UUID; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.iceberg.aws.AwsClientUtil; | ||
| import org.apache.iceberg.aws.AwsIntegTestUtil; | ||
| import org.apache.iceberg.aws.AwsProperties; | ||
| import org.apache.iceberg.io.InputFile; | ||
| import org.apache.iceberg.io.PositionOutputStream; | ||
| import org.apache.iceberg.io.SeekableInputStream; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import software.amazon.awssdk.services.s3.S3Client; | ||
|
|
||
| /** | ||
| * Long-running tests to ensure multipart upload logic is resilient | ||
| */ | ||
| public class S3MultipartUploadTest { | ||
|
|
||
| private final Random random = new Random(1); | ||
| private static S3Client s3; | ||
| private static String bucketName; | ||
| private static String prefix; | ||
| private String objectUri; | ||
|
|
||
| @BeforeClass | ||
| public static void beforeClass() { | ||
| s3 = AwsClientUtil.defaultS3Client(); | ||
| bucketName = AwsIntegTestUtil.testBucketName(); | ||
| prefix = UUID.randomUUID().toString(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void afterClass() { | ||
| AwsIntegTestUtil.cleanS3Bucket(s3, bucketName, prefix); | ||
| } | ||
|
|
||
| @Before | ||
| public void before() { | ||
| String objectKey = String.format("%s/%s", prefix, UUID.randomUUID().toString()); | ||
| objectUri = String.format("s3://%s/%s", bucketName, objectKey); | ||
| } | ||
|
|
||
| @Test | ||
| public void testManyParts_writeWithInt() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri).create(); | ||
| for (int i = 0; i < 100; i++) { | ||
| for (int j = 0; j < AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN; j++) { | ||
| outputStream.write(random.nextInt()); | ||
| } | ||
| } | ||
| outputStream.close(); | ||
| Assert.assertEquals(100 * (long) AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN, | ||
| io.newInputFile(objectUri).getLength()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testManyParts_writeWithBytes() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri).create(); | ||
| byte[] bytes = new byte[AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN]; | ||
| for (int i = 0; i < 100; i++) { | ||
| random.nextBytes(bytes); | ||
| outputStream.write(bytes); | ||
| } | ||
| outputStream.close(); | ||
| Assert.assertEquals(100 * (long) AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN, | ||
| io.newInputFile(objectUri).getLength()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testContents_writeWithInt() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri).create(); | ||
| for (int i = 0; i < 10; i++) { | ||
| for (int j = 0; j < AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN; j++) { | ||
| outputStream.write(6); | ||
| } | ||
| } | ||
| outputStream.close(); | ||
| SeekableInputStream inputStream = io.newInputFile(objectUri).newStream(); | ||
| int cur; | ||
| while ((cur = inputStream.read()) != -1) { | ||
| Assert.assertEquals(6, cur); | ||
| } | ||
| inputStream.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testContents_writeWithBytes() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri).create(); | ||
| byte[] bytes = new byte[AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN]; | ||
| for (int i = 0; i < AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN; i++) { | ||
| bytes[i] = 6; | ||
| } | ||
| for (int i = 0; i < 10; i++) { | ||
| outputStream.write(bytes); | ||
| } | ||
| outputStream.close(); | ||
| SeekableInputStream inputStream = io.newInputFile(objectUri).newStream(); | ||
| int cur; | ||
| while ((cur = inputStream.read()) != -1) { | ||
| Assert.assertEquals(6, cur); | ||
| } | ||
| inputStream.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUploadRemainder() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| properties.setS3FileIoMultipartThresholdFactor(1); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri).create(); | ||
| long length = 3 * AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN + 2 * 1024 * 1024; | ||
| for (int i = 0; i < length; i++) { | ||
| outputStream.write(random.nextInt()); | ||
| } | ||
| outputStream.close(); | ||
| Assert.assertEquals(length, io.newInputFile(objectUri).getLength()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParallelUpload() throws IOException { | ||
| AwsProperties properties = new AwsProperties(); | ||
| properties.setS3FileIoMultiPartSize(AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN); | ||
| properties.setS3FileIoMultipartUploadThreads(16); | ||
| S3FileIO io = new S3FileIO(() -> s3, properties); | ||
| IntStream.range(0, 16).parallel().forEach(d -> { | ||
| byte[] bytes = new byte[AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN]; | ||
| for (int i = 0; i < AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN; i++) { | ||
| bytes[i] = (byte) d; | ||
| } | ||
| PositionOutputStream outputStream = io.newOutputFile(objectUri + "_" + d).create(); | ||
| try { | ||
| for (int i = 0; i < 3; i++) { | ||
| outputStream.write(bytes); | ||
| } | ||
| outputStream.close(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
|
|
||
| for (int i = 0; i < 16; i++) { | ||
| String fileUri = objectUri + "_" + i; | ||
| InputFile inputFile = io.newInputFile(fileUri); | ||
| Assert.assertEquals(3 * (long) AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN, inputFile.getLength()); | ||
| int cur; | ||
| InputStream stream = inputFile.newStream(); | ||
| while ((cur = stream.read()) != -1) { | ||
| Assert.assertEquals(i, cur); | ||
| } | ||
| stream.close(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Maybe I'm missing something, but I don't think these are actually testing the multipart upload. If we're writing with the OutputStream::write interface, that would only be writing a single byte, so 100 bytes in this case. That wouldn't be enough to trigger the multipart behavior.
I think that's the case for most of the tests I see here. You might want to look at the S3Outputstream test because you can actually validate the operations performed like this: https://github.com/apache/iceberg/blob/master/aws/src/test/java/org/apache/iceberg/aws/s3/S3OutputStreamTest.java#L109
Uh oh!
There was an error while loading. Please reload this page.
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.
There is an internal loop
for (int j = 0; j < AwsProperties.S3FILEIO_MULTIPART_SIZE_MIN; j++).the tests here are trying to verify against actual result in s3 instead of verifying the number of calls, because I know those are verified in the tests you referenced. But I think I am being very not DRY here, let me refactor the tests a little bit
Uh oh!
There was an error while loading. Please reload this page.
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.
No, I just mixed up this test and the next one and missed the inner loop here. However, you might be able to combine some of the upload and content validation into a single test, but it looks like you already have some thoughts on it, so I'll wait.
I guess there's two minor questions I have:
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.
I don't expect this to be run for every actual build, and the tests take quite a while to complete, so it's mostly for users to run in their own account. With that being said, I am in progress of potentially getting an account to run these tests for all PRs committing to the aws module with cost covered.
It is hard to say how different is the actual S3 compared to S3mock, so this serves as a line of defense to catch potentially different behaviors and potential errors during non-local network calls.
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.
@danielcweeks refactored tests, please let me know if it looks good to you.
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.
Yeah, looks good. It seems for #2 there are a number of things we won't be able to test against s3mock (like sts) so it makes sense to add these integration tests once we have an account.
Thanks!