-
Notifications
You must be signed in to change notification settings - Fork 1k
Pause/Resume Upload for Transfer Manager with Java S3Client #4886
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
Changes from 3 commits
745e402
65069fb
3dfa1c2
2fa0d9e
4d17804
fd010e4
069a00c
9aeba32
0fedea3
1089532
fce9bf9
1d99321
6afc377
007ee65
7a3589c
3212620
f323822
d10ddf6
cd207db
ca9b69b
f92e9f3
4275763
b020266
9597393
9ab7d51
2336fed
ccdd184
cc06b46
bab7f24
4580e26
6a83122
7ab1028
e16376e
9d8d4cf
d182576
0c2d4eb
4a81f88
a5b277b
4bc0a09
a963bdf
02e807c
ee01442
ab6113b
4ef752f
1548dd5
f3da726
2f2e6e1
1849320
207a10e
824d6ad
6411744
fcfc6a5
6bc4130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| package software.amazon.awssdk.transfer.s3; | ||
|
|
||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
| import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; | ||
| import static software.amazon.awssdk.transfer.s3.SizeConstant.MB; | ||
|
|
||
|
|
@@ -26,9 +25,12 @@ | |
| import java.time.Duration; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy; | ||
| import software.amazon.awssdk.core.waiters.AsyncWaiter; | ||
| import software.amazon.awssdk.core.waiters.Waiter; | ||
|
|
@@ -69,30 +71,42 @@ public static void cleanup() { | |
| executorService.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| void pause_singlePart_shouldResume() { | ||
| enum S3ClientType { | ||
| CRT, JAVA | ||
| } | ||
|
|
||
| private static Stream<Arguments> s3ClientType() { | ||
| return Stream.of(Arguments.of(S3ClientType.CRT), Arguments.of(S3ClientType.JAVA)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("s3ClientType") | ||
| void pause_singlePart_shouldResume(S3ClientType s3ClientType) { | ||
| S3TransferManager transferManager = s3ClientType == S3ClientType.CRT ? tmCrt : tmJava; | ||
| UploadFileRequest request = UploadFileRequest.builder() | ||
| .putObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
| .source(smallFile) | ||
| .build(); | ||
| FileUpload fileUpload = tmCrt.uploadFile(request); | ||
| FileUpload fileUpload = transferManager.uploadFile(request); | ||
| ResumableFileUpload resumableFileUpload = fileUpload.pause(); | ||
| log.debug(() -> "Paused: " + resumableFileUpload); | ||
|
|
||
| validateEmptyResumeToken(resumableFileUpload); | ||
|
|
||
| FileUpload resumedUpload = tmCrt.resumeUploadFile(resumableFileUpload); | ||
| FileUpload resumedUpload = transferManager.resumeUploadFile(resumableFileUpload); | ||
| resumedUpload.completionFuture().join(); | ||
| } | ||
|
|
||
| @Test | ||
| void pause_fileNotChanged_shouldResume() { | ||
| @ParameterizedTest | ||
| @MethodSource("s3ClientType") | ||
| void pause_fileNotChanged_shouldResume(S3ClientType s3ClientType) { | ||
| S3TransferManager transferManager = s3ClientType == S3ClientType.CRT ? tmCrt : tmJava; | ||
| UploadFileRequest request = UploadFileRequest.builder() | ||
| .putObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
| .addTransferListener(LoggingTransferListener.create()) | ||
| .source(largeFile) | ||
| .build(); | ||
| FileUpload fileUpload = tmCrt.uploadFile(request); | ||
| FileUpload fileUpload = transferManager.uploadFile(request); | ||
| waitUntilMultipartUploadExists(); | ||
| ResumableFileUpload resumableFileUpload = fileUpload.pause(); | ||
| log.debug(() -> "Paused: " + resumableFileUpload); | ||
|
|
@@ -103,33 +117,43 @@ void pause_fileNotChanged_shouldResume() { | |
|
|
||
| verifyMultipartUploadIdExists(resumableFileUpload); | ||
|
|
||
| FileUpload resumedUpload = tmCrt.resumeUploadFile(resumableFileUpload); | ||
| FileUpload resumedUpload = transferManager.resumeUploadFile(resumableFileUpload); | ||
| resumedUpload.completionFuture().join(); | ||
| } | ||
|
|
||
| @Test | ||
| void pauseImmediately_resume_shouldStartFromBeginning() { | ||
| @ParameterizedTest | ||
| @MethodSource("s3ClientType") | ||
| void pauseImmediately_resume_shouldStartFromBeginning(S3ClientType s3ClientType) { | ||
| S3TransferManager transferManager = s3ClientType == S3ClientType.CRT ? tmCrt : tmJava; | ||
| UploadFileRequest request = UploadFileRequest.builder() | ||
| .putObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
| .source(largeFile) | ||
| .build(); | ||
| FileUpload fileUpload = tmCrt.uploadFile(request); | ||
| FileUpload fileUpload = transferManager.uploadFile(request); | ||
| ResumableFileUpload resumableFileUpload = fileUpload.pause(); | ||
| log.debug(() -> "Paused: " + resumableFileUpload); | ||
|
|
||
| validateEmptyResumeToken(resumableFileUpload); | ||
| if (s3ClientType == S3ClientType.CRT) { | ||
| validateEmptyResumeToken(resumableFileUpload); | ||
| } else { | ||
| // join() is called on CreateMultipartUpload so resume token will be returned | ||
| assertThat(resumableFileUpload.transferredParts().isPresent()).isTrue(); | ||
| assertThat(resumableFileUpload.transferredParts().getAsLong()).isZero(); | ||
| } | ||
|
|
||
| FileUpload resumedUpload = tmCrt.resumeUploadFile(resumableFileUpload); | ||
| FileUpload resumedUpload = transferManager.resumeUploadFile(resumableFileUpload); | ||
| resumedUpload.completionFuture().join(); | ||
| } | ||
|
|
||
| @Test | ||
| void pause_fileChanged_resumeShouldStartFromBeginning() throws Exception { | ||
| @ParameterizedTest | ||
| @MethodSource("s3ClientType") | ||
| void pause_fileChanged_resumeShouldStartFromBeginning(S3ClientType s3ClientType) throws Exception { | ||
| S3TransferManager transferManager = s3ClientType == S3ClientType.CRT ? tmCrt : tmJava; | ||
| UploadFileRequest request = UploadFileRequest.builder() | ||
| .putObjectRequest(b -> b.bucket(BUCKET).key(KEY)) | ||
| .source(largeFile) | ||
| .build(); | ||
| FileUpload fileUpload = tmCrt.uploadFile(request); | ||
| FileUpload fileUpload = transferManager.uploadFile(request); | ||
| waitUntilMultipartUploadExists(); | ||
| ResumableFileUpload resumableFileUpload = fileUpload.pause(); | ||
| log.debug(() -> "Paused: " + resumableFileUpload); | ||
|
|
@@ -139,13 +163,16 @@ void pause_fileChanged_resumeShouldStartFromBeginning() throws Exception { | |
| assertThat(resumableFileUpload.totalParts()).isNotEmpty(); | ||
| verifyMultipartUploadIdExists(resumableFileUpload); | ||
|
|
||
| byte[] originalBytes = Files.readAllBytes(largeFile.toPath()); | ||
| byte[] bytes = "helloworld".getBytes(StandardCharsets.UTF_8); | ||
| Files.write(largeFile.toPath(), bytes); | ||
|
|
||
| FileUpload resumedUpload = tmCrt.resumeUploadFile(resumableFileUpload); | ||
| FileUpload resumedUpload = transferManager.resumeUploadFile(resumableFileUpload); | ||
| resumedUpload.completionFuture().join(); | ||
| verifyMultipartUploadIdNotExist(resumableFileUpload); | ||
| assertThat(resumedUpload.progress().snapshot().totalBytes()).hasValue(bytes.length); | ||
|
|
||
| Files.write(largeFile.toPath(), originalBytes); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintentional change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to write back the original largeFile , since we overwrote it with "helloworld" to test file changed,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do it in afterEach?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only overwrite it in this test, so dont need to write back for other tests |
||
| } | ||
|
|
||
| private void verifyMultipartUploadIdExists(ResumableFileUpload resumableFileUpload) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.