1616package software .amazon .awssdk .transfer .s3 ;
1717
1818import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
19- import static org .assertj .core .api .AssertionsForClassTypes .assertThatThrownBy ;
2019import static software .amazon .awssdk .testutils .service .S3BucketUtils .temporaryBucketName ;
2120import static software .amazon .awssdk .transfer .s3 .SizeConstant .MB ;
2221
2625import java .time .Duration ;
2726import java .util .concurrent .Executors ;
2827import java .util .concurrent .ScheduledExecutorService ;
28+ import java .util .stream .Stream ;
2929import org .junit .jupiter .api .AfterAll ;
3030import org .junit .jupiter .api .BeforeAll ;
31- import org .junit .jupiter .api .Test ;
31+ import org .junit .jupiter .params .ParameterizedTest ;
32+ import org .junit .jupiter .params .provider .Arguments ;
33+ import org .junit .jupiter .params .provider .MethodSource ;
3234import software .amazon .awssdk .core .retry .backoff .FixedDelayBackoffStrategy ;
3335import software .amazon .awssdk .core .waiters .AsyncWaiter ;
3436import software .amazon .awssdk .core .waiters .Waiter ;
3537import software .amazon .awssdk .core .waiters .WaiterAcceptor ;
38+ import software .amazon .awssdk .services .s3 .S3AsyncClient ;
3639import software .amazon .awssdk .services .s3 .model .ListMultipartUploadsResponse ;
3740import software .amazon .awssdk .services .s3 .model .ListPartsResponse ;
3841import software .amazon .awssdk .services .s3 .model .NoSuchUploadException ;
@@ -48,17 +51,25 @@ public class S3TransferManagerUploadPauseResumeIntegrationTest extends S3Integra
4851 private static final String BUCKET = temporaryBucketName (S3TransferManagerUploadPauseResumeIntegrationTest .class );
4952 private static final String KEY = "key" ;
5053 // 24 * MB is chosen to make sure we have data written in the file already upon pausing.
51- private static final long OBJ_SIZE = 24 * MB ;
54+ private static final long LARGE_OBJ_SIZE = 24 * MB ;
55+ private static final long SMALL_OBJ_SIZE = 2 * MB ;
5256 private static File largeFile ;
5357 private static File smallFile ;
5458 private static ScheduledExecutorService executorService ;
5559
60+ // TODO - switch to tmJava from TestBase once TransferListener fixed for MultipartClient
61+ protected static S3TransferManager tmJavaMpu ;
62+
5663 @ BeforeAll
5764 public static void setup () throws Exception {
5865 createBucket (BUCKET );
59- largeFile = new RandomTempFile (OBJ_SIZE );
60- smallFile = new RandomTempFile (2 * MB );
66+ largeFile = new RandomTempFile (LARGE_OBJ_SIZE );
67+ smallFile = new RandomTempFile (SMALL_OBJ_SIZE );
6168 executorService = Executors .newScheduledThreadPool (3 );
69+
70+ // TODO - switch to tmJava from TestBase once TransferListener fixed for MultipartClient
71+ S3AsyncClient s3AsyncMpu = s3AsyncClientBuilder ().multipartEnabled (true ).build ();
72+ tmJavaMpu = S3TransferManager .builder ().s3Client (s3AsyncMpu ).build ();
6273 }
6374
6475 @ AfterAll
@@ -69,30 +80,42 @@ public static void cleanup() {
6980 executorService .shutdown ();
7081 }
7182
72- @ Test
73- void pause_singlePart_shouldResume () {
83+ private static Stream <Arguments > transferManagers () {
84+ return Stream .of (
85+ Arguments .of (tmJavaMpu , tmJavaMpu ),
86+ Arguments .of (tmCrt , tmCrt ),
87+ Arguments .of (tmCrt , tmJavaMpu ),
88+ Arguments .of (tmJavaMpu , tmCrt )
89+ );
90+ }
91+
92+ @ ParameterizedTest
93+ @ MethodSource ("transferManagers" )
94+ void pause_singlePart_shouldResume (S3TransferManager uploadTm , S3TransferManager resumeTm ) {
7495 UploadFileRequest request = UploadFileRequest .builder ()
7596 .putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
7697 .source (smallFile )
7798 .build ();
78- FileUpload fileUpload = tmCrt .uploadFile (request );
99+ FileUpload fileUpload = uploadTm .uploadFile (request );
79100 ResumableFileUpload resumableFileUpload = fileUpload .pause ();
80101 log .debug (() -> "Paused: " + resumableFileUpload );
81102
82103 validateEmptyResumeToken (resumableFileUpload );
83104
84- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
105+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
85106 resumedUpload .completionFuture ().join ();
107+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (SMALL_OBJ_SIZE );
86108 }
87109
88- @ Test
89- void pause_fileNotChanged_shouldResume () {
110+ @ ParameterizedTest
111+ @ MethodSource ("transferManagers" )
112+ void pause_fileNotChanged_shouldResume (S3TransferManager uploadTm , S3TransferManager resumeTm ) throws Exception {
90113 UploadFileRequest request = UploadFileRequest .builder ()
91114 .putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
92115 .addTransferListener (LoggingTransferListener .create ())
93116 .source (largeFile )
94117 .build ();
95- FileUpload fileUpload = tmCrt .uploadFile (request );
118+ FileUpload fileUpload = uploadTm .uploadFile (request );
96119 waitUntilMultipartUploadExists ();
97120 ResumableFileUpload resumableFileUpload = fileUpload .pause ();
98121 log .debug (() -> "Paused: " + resumableFileUpload );
@@ -103,33 +126,37 @@ void pause_fileNotChanged_shouldResume() {
103126
104127 verifyMultipartUploadIdExists (resumableFileUpload );
105128
106- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
129+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
107130 resumedUpload .completionFuture ().join ();
131+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (LARGE_OBJ_SIZE );
108132 }
109133
110- @ Test
111- void pauseImmediately_resume_shouldStartFromBeginning () {
134+ @ ParameterizedTest
135+ @ MethodSource ("transferManagers" )
136+ void pauseImmediately_resume_shouldStartFromBeginning (S3TransferManager uploadTm , S3TransferManager resumeTm ) {
112137 UploadFileRequest request = UploadFileRequest .builder ()
113- .putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
114- .source (largeFile )
115- .build ();
116- FileUpload fileUpload = tmCrt .uploadFile (request );
138+ .putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
139+ .source (largeFile )
140+ .build ();
141+ FileUpload fileUpload = uploadTm .uploadFile (request );
117142 ResumableFileUpload resumableFileUpload = fileUpload .pause ();
118143 log .debug (() -> "Paused: " + resumableFileUpload );
119144
120145 validateEmptyResumeToken (resumableFileUpload );
121146
122- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
147+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
123148 resumedUpload .completionFuture ().join ();
149+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (LARGE_OBJ_SIZE );
124150 }
125151
126- @ Test
127- void pause_fileChanged_resumeShouldStartFromBeginning () throws Exception {
152+ @ ParameterizedTest
153+ @ MethodSource ("transferManagers" )
154+ void pause_fileChanged_resumeShouldStartFromBeginning (S3TransferManager uploadTm , S3TransferManager resumeTm ) throws Exception {
128155 UploadFileRequest request = UploadFileRequest .builder ()
129156 .putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
130157 .source (largeFile )
131158 .build ();
132- FileUpload fileUpload = tmCrt .uploadFile (request );
159+ FileUpload fileUpload = uploadTm .uploadFile (request );
133160 waitUntilMultipartUploadExists ();
134161 ResumableFileUpload resumableFileUpload = fileUpload .pause ();
135162 log .debug (() -> "Paused: " + resumableFileUpload );
@@ -139,13 +166,18 @@ void pause_fileChanged_resumeShouldStartFromBeginning() throws Exception {
139166 assertThat (resumableFileUpload .totalParts ()).isNotEmpty ();
140167 verifyMultipartUploadIdExists (resumableFileUpload );
141168
142- byte [] bytes = "helloworld" .getBytes (StandardCharsets .UTF_8 );
143- Files .write (largeFile .toPath (), bytes );
144-
145- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
146- resumedUpload .completionFuture ().join ();
147- verifyMultipartUploadIdNotExist (resumableFileUpload );
148- assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (bytes .length );
169+ byte [] originalBytes = Files .readAllBytes (largeFile .toPath ());
170+ try {
171+ byte [] bytes = "helloworld" .getBytes (StandardCharsets .UTF_8 );
172+ Files .write (largeFile .toPath (), bytes );
173+
174+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
175+ resumedUpload .completionFuture ().join ();
176+ verifyMultipartUploadIdNotExist (resumableFileUpload );
177+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (bytes .length );
178+ } finally {
179+ Files .write (largeFile .toPath (), originalBytes );
180+ }
149181 }
150182
151183 private void verifyMultipartUploadIdExists (ResumableFileUpload resumableFileUpload ) {
0 commit comments