-
Notifications
You must be signed in to change notification settings - Fork 916
Pause and resume for multipart download #5258
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0f717a9
add completed to ResumableFileDownload ser/des
L-Applin bca31d4
pause/resume for multipart download
L-Applin e8f9871
Pause and Resume logic for multipart GET
L-Applin e9553f8
Merge branch 'feature/master/s3mpu' into olapplin/pause-resume-multi
L-Applin 121fcf4
update S3TransferManagerListenerTest for DownloadFileRequest with add…
L-Applin 14ccbfc
Gracefully handles resuming a download when download already is compl…
L-Applin 747d56c
checkstyle
L-Applin 7f77b7c
clean-up
L-Applin c55bec1
add test
L-Applin 7098e7a
clean-up
L-Applin 84572a5
correctly set total parts in MultipartDownloadResumeContext. Add LogC…
L-Applin a27baf4
update pause-resume integ test to work around the new execution attri…
L-Applin 4ff5aca
update pause-resume integ test to work around the new execution attri…
L-Applin 23eb70d
actually compare GetObjectRequest instance
L-Applin 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 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
121 changes: 121 additions & 0 deletions
121
...azon/awssdk/transfer/s3/S3TransferManagerMultipartDownloadPauseResumeIntegrationTest.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,121 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.transfer.s3; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; | ||
import static software.amazon.awssdk.transfer.s3.SizeConstant.MB; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy; | ||
import software.amazon.awssdk.core.waiters.Waiter; | ||
import software.amazon.awssdk.core.waiters.WaiterAcceptor; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.testutils.LogCaptor; | ||
import software.amazon.awssdk.testutils.RandomTempFile; | ||
import software.amazon.awssdk.transfer.s3.model.DownloadFileRequest; | ||
import software.amazon.awssdk.transfer.s3.model.FileDownload; | ||
import software.amazon.awssdk.transfer.s3.model.ResumableFileDownload; | ||
import software.amazon.awssdk.transfer.s3.progress.TransferProgressSnapshot; | ||
|
||
public class S3TransferManagerMultipartDownloadPauseResumeIntegrationTest extends S3IntegrationTestBase { | ||
private static final String BUCKET = temporaryBucketName(S3TransferManagerMultipartDownloadPauseResumeIntegrationTest.class); | ||
private static final String KEY = "key"; | ||
|
||
private static final long OBJ_SIZE = 32 * MB; // 32mib for 4 parts of 8 mib | ||
private static File sourceFile; | ||
|
||
@BeforeAll | ||
public static void setup() throws Exception { | ||
createBucket(BUCKET); | ||
sourceFile = new RandomTempFile(OBJ_SIZE); | ||
|
||
// use async client for multipart upload (with default part size) | ||
s3Async.putObject(PutObjectRequest.builder() | ||
.bucket(BUCKET) | ||
.key(KEY) | ||
.build(), sourceFile.toPath()) | ||
.join(); | ||
} | ||
|
||
@AfterAll | ||
public static void cleanup() { | ||
deleteBucketAndAllContents(BUCKET); | ||
sourceFile.delete(); | ||
} | ||
|
||
@Test | ||
void pauseAndResume_shouldResumeDownload() { | ||
Path path = RandomTempFile.randomUncreatedFile().toPath(); | ||
DownloadFileRequest request = DownloadFileRequest.builder() | ||
.getObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
.destination(path) | ||
.build(); | ||
FileDownload download = tmJava.downloadFile(request); | ||
|
||
// wait until we receive enough byte to stop somewhere between part 2 and 3, 18 Mib should do it | ||
waitUntilAmountTransferred(download, 18 * MB); | ||
ResumableFileDownload resumableFileDownload = download.pause(); | ||
FileDownload resumed = tmJava.resumeDownloadFile(resumableFileDownload); | ||
resumed.completionFuture().join(); | ||
assertThat(path.toFile()).hasSameBinaryContentAs(sourceFile); | ||
} | ||
|
||
@Test | ||
void pauseAndResume_whenAlreadyComplete_shouldHandleGracefully() { | ||
Path path = RandomTempFile.randomUncreatedFile().toPath(); | ||
DownloadFileRequest request = DownloadFileRequest.builder() | ||
.getObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
.destination(path) | ||
.build(); | ||
FileDownload download = tmJava.downloadFile(request); | ||
download.completionFuture().join(); | ||
ResumableFileDownload resume = download.pause(); | ||
try (LogCaptor logCaptor = LogCaptor.create(Level.DEBUG)) { | ||
FileDownload resumedDownload = tmJava.resumeDownloadFile(resume); | ||
assertThat(resumedDownload.completionFuture()).isCompleted(); | ||
assertThat(path.toFile()).hasSameBinaryContentAs(sourceFile); | ||
|
||
List<LogEvent> logEvents = logCaptor.loggedEvents(); | ||
assertThat(logEvents).noneMatch( | ||
event -> event.getMessage().getFormattedMessage().contains("Sending downloadFileRequest")); | ||
LogEvent firstLog = logEvents.get(0); | ||
assertThat(firstLog.getMessage().getFormattedMessage()) | ||
.contains("The multipart download associated to the provided ResumableFileDownload is already completed, " | ||
+ "nothing to resume"); | ||
} | ||
} | ||
|
||
private void waitUntilAmountTransferred(FileDownload download, long amountTransferred) { | ||
Waiter<TransferProgressSnapshot> waiter = | ||
Waiter.builder(TransferProgressSnapshot.class) | ||
.addAcceptor(WaiterAcceptor.successOnResponseAcceptor(r -> r.transferredBytes() > amountTransferred)) | ||
.addAcceptor(WaiterAcceptor.retryOnResponseAcceptor(r -> true)) | ||
.overrideConfiguration(o -> o.waitTimeout(Duration.ofMinutes(5)) | ||
.maxAttempts(Integer.MAX_VALUE) | ||
.backoffStrategy(FixedDelayBackoffStrategy.create(Duration.ofMillis(100)))) | ||
.build(); | ||
waiter.run(() -> download.progress().snapshot()); | ||
} | ||
} |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.