16
16
package software .amazon .awssdk .transfer .s3 ;
17
17
18
18
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
19
- import static org .assertj .core .api .AssertionsForClassTypes .assertThatThrownBy ;
20
19
import static software .amazon .awssdk .testutils .service .S3BucketUtils .temporaryBucketName ;
21
20
import static software .amazon .awssdk .transfer .s3 .SizeConstant .MB ;
22
21
26
25
import java .time .Duration ;
27
26
import java .util .concurrent .Executors ;
28
27
import java .util .concurrent .ScheduledExecutorService ;
28
+ import java .util .stream .Stream ;
29
29
import org .junit .jupiter .api .AfterAll ;
30
30
import 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 ;
32
34
import software .amazon .awssdk .core .retry .backoff .FixedDelayBackoffStrategy ;
33
35
import software .amazon .awssdk .core .waiters .AsyncWaiter ;
34
36
import software .amazon .awssdk .core .waiters .Waiter ;
35
37
import software .amazon .awssdk .core .waiters .WaiterAcceptor ;
38
+ import software .amazon .awssdk .services .s3 .S3AsyncClient ;
36
39
import software .amazon .awssdk .services .s3 .model .ListMultipartUploadsResponse ;
37
40
import software .amazon .awssdk .services .s3 .model .ListPartsResponse ;
38
41
import software .amazon .awssdk .services .s3 .model .NoSuchUploadException ;
@@ -48,17 +51,25 @@ public class S3TransferManagerUploadPauseResumeIntegrationTest extends S3Integra
48
51
private static final String BUCKET = temporaryBucketName (S3TransferManagerUploadPauseResumeIntegrationTest .class );
49
52
private static final String KEY = "key" ;
50
53
// 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 ;
52
56
private static File largeFile ;
53
57
private static File smallFile ;
54
58
private static ScheduledExecutorService executorService ;
55
59
60
+ // TODO - switch to tmJava from TestBase once TransferListener fixed for MultipartClient
61
+ protected static S3TransferManager tmJavaMpu ;
62
+
56
63
@ BeforeAll
57
64
public static void setup () throws Exception {
58
65
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 );
61
68
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 ();
62
73
}
63
74
64
75
@ AfterAll
@@ -69,30 +80,42 @@ public static void cleanup() {
69
80
executorService .shutdown ();
70
81
}
71
82
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 ) {
74
95
UploadFileRequest request = UploadFileRequest .builder ()
75
96
.putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
76
97
.source (smallFile )
77
98
.build ();
78
- FileUpload fileUpload = tmCrt .uploadFile (request );
99
+ FileUpload fileUpload = uploadTm .uploadFile (request );
79
100
ResumableFileUpload resumableFileUpload = fileUpload .pause ();
80
101
log .debug (() -> "Paused: " + resumableFileUpload );
81
102
82
103
validateEmptyResumeToken (resumableFileUpload );
83
104
84
- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
105
+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
85
106
resumedUpload .completionFuture ().join ();
107
+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (SMALL_OBJ_SIZE );
86
108
}
87
109
88
- @ Test
89
- void pause_fileNotChanged_shouldResume () {
110
+ @ ParameterizedTest
111
+ @ MethodSource ("transferManagers" )
112
+ void pause_fileNotChanged_shouldResume (S3TransferManager uploadTm , S3TransferManager resumeTm ) throws Exception {
90
113
UploadFileRequest request = UploadFileRequest .builder ()
91
114
.putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
92
115
.addTransferListener (LoggingTransferListener .create ())
93
116
.source (largeFile )
94
117
.build ();
95
- FileUpload fileUpload = tmCrt .uploadFile (request );
118
+ FileUpload fileUpload = uploadTm .uploadFile (request );
96
119
waitUntilMultipartUploadExists ();
97
120
ResumableFileUpload resumableFileUpload = fileUpload .pause ();
98
121
log .debug (() -> "Paused: " + resumableFileUpload );
@@ -103,33 +126,37 @@ void pause_fileNotChanged_shouldResume() {
103
126
104
127
verifyMultipartUploadIdExists (resumableFileUpload );
105
128
106
- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
129
+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
107
130
resumedUpload .completionFuture ().join ();
131
+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (LARGE_OBJ_SIZE );
108
132
}
109
133
110
- @ Test
111
- void pauseImmediately_resume_shouldStartFromBeginning () {
134
+ @ ParameterizedTest
135
+ @ MethodSource ("transferManagers" )
136
+ void pauseImmediately_resume_shouldStartFromBeginning (S3TransferManager uploadTm , S3TransferManager resumeTm ) {
112
137
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 );
117
142
ResumableFileUpload resumableFileUpload = fileUpload .pause ();
118
143
log .debug (() -> "Paused: " + resumableFileUpload );
119
144
120
145
validateEmptyResumeToken (resumableFileUpload );
121
146
122
- FileUpload resumedUpload = tmCrt .resumeUploadFile (resumableFileUpload );
147
+ FileUpload resumedUpload = resumeTm .resumeUploadFile (resumableFileUpload );
123
148
resumedUpload .completionFuture ().join ();
149
+ assertThat (resumedUpload .progress ().snapshot ().totalBytes ()).hasValue (LARGE_OBJ_SIZE );
124
150
}
125
151
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 {
128
155
UploadFileRequest request = UploadFileRequest .builder ()
129
156
.putObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
130
157
.source (largeFile )
131
158
.build ();
132
- FileUpload fileUpload = tmCrt .uploadFile (request );
159
+ FileUpload fileUpload = uploadTm .uploadFile (request );
133
160
waitUntilMultipartUploadExists ();
134
161
ResumableFileUpload resumableFileUpload = fileUpload .pause ();
135
162
log .debug (() -> "Paused: " + resumableFileUpload );
@@ -139,13 +166,18 @@ void pause_fileChanged_resumeShouldStartFromBeginning() throws Exception {
139
166
assertThat (resumableFileUpload .totalParts ()).isNotEmpty ();
140
167
verifyMultipartUploadIdExists (resumableFileUpload );
141
168
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
+ }
149
181
}
150
182
151
183
private void verifyMultipartUploadIdExists (ResumableFileUpload resumableFileUpload ) {
0 commit comments