13
13
* permissions and limitations under the License.
14
14
*/
15
15
16
- package software .amazon .awssdk .services .s3 .crt ;
16
+ package software .amazon .awssdk .services .s3 .multipart ;
17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
import static org .assertj .core .api .Fail .fail ;
24
24
import java .nio .ByteBuffer ;
25
25
import java .security .SecureRandom ;
26
26
import java .util .Base64 ;
27
- import java .util .UUID ;
28
27
import java .util .concurrent .CompletableFuture ;
29
28
import java .util .concurrent .ThreadLocalRandom ;
29
+ import java .util .concurrent .TimeUnit ;
30
+ import java .util .stream .Stream ;
30
31
import javax .crypto .KeyGenerator ;
31
32
import org .junit .jupiter .api .AfterAll ;
32
33
import org .junit .jupiter .api .BeforeAll ;
33
- import org .junit .jupiter .api .Test ;
34
+ import org .junit .jupiter .api .Disabled ;
35
+ import org .junit .jupiter .api .Timeout ;
36
+ import org .junit .jupiter .params .ParameterizedTest ;
37
+ import org .junit .jupiter .params .provider .MethodSource ;
34
38
import software .amazon .awssdk .core .ResponseBytes ;
35
39
import software .amazon .awssdk .core .async .AsyncRequestBody ;
36
40
import software .amazon .awssdk .core .sync .ResponseTransformer ;
37
41
import software .amazon .awssdk .services .s3 .S3AsyncClient ;
38
42
import software .amazon .awssdk .services .s3 .S3IntegrationTestBase ;
39
43
import software .amazon .awssdk .services .s3 .internal .crt .S3CrtAsyncClient ;
44
+ import software .amazon .awssdk .services .s3 .internal .multipart .MultipartS3AsyncClient ;
40
45
import software .amazon .awssdk .services .s3 .model .CopyObjectResponse ;
41
46
import software .amazon .awssdk .services .s3 .model .GetObjectResponse ;
42
47
import software .amazon .awssdk .services .s3 .model .MetadataDirective ;
43
48
import software .amazon .awssdk .utils .Md5Utils ;
44
49
45
- public class S3CrtClientCopyIntegrationTest extends S3IntegrationTestBase {
46
- private static final String BUCKET = temporaryBucketName (S3CrtClientCopyIntegrationTest .class );
50
+ @ Timeout (value = 3 , unit = TimeUnit .MINUTES )
51
+ public class S3ClientMultiPartCopyIntegrationTest extends S3IntegrationTestBase {
52
+ private static final String BUCKET = temporaryBucketName (S3ClientMultiPartCopyIntegrationTest .class );
47
53
private static final String ORIGINAL_OBJ = "test_file.dat" ;
48
54
private static final String COPIED_OBJ = "test_file_copy.dat" ;
49
55
private static final String ORIGINAL_OBJ_SPECIAL_CHARACTER = "original-special-chars-@$%" ;
50
56
private static final String COPIED_OBJ_SPECIAL_CHARACTER = "special-special-chars-@$%" ;
51
57
private static final long OBJ_SIZE = ThreadLocalRandom .current ().nextLong (8 * 1024 * 1024 , 16 * 1024 * 1024 + 1 );
52
58
private static final long SMALL_OBJ_SIZE = 1024 * 1024 ;
53
59
private static S3AsyncClient s3CrtAsyncClient ;
60
+ private static S3AsyncClient s3MpuClient ;
54
61
@ BeforeAll
55
62
public static void setUp () throws Exception {
56
63
S3IntegrationTestBase .setUp ();
@@ -59,40 +66,50 @@ public static void setUp() throws Exception {
59
66
.credentialsProvider (CREDENTIALS_PROVIDER_CHAIN )
60
67
.region (DEFAULT_REGION )
61
68
.build ();
69
+ s3MpuClient = new MultipartS3AsyncClient (s3Async );
62
70
}
63
71
64
72
@ AfterAll
65
73
public static void teardown () throws Exception {
66
74
s3CrtAsyncClient .close ();
75
+ s3MpuClient .close ();
67
76
deleteBucketAndAllContents (BUCKET );
68
77
}
69
78
70
- @ Test
71
- void copy_singlePart_hasSameContent () {
79
+ public static Stream <S3AsyncClient > s3AsyncClient () {
80
+ return Stream .of (s3MpuClient , s3CrtAsyncClient );
81
+ }
82
+
83
+ @ ParameterizedTest (autoCloseArguments = false )
84
+ @ MethodSource ("s3AsyncClient" )
85
+ void copy_singlePart_hasSameContent (S3AsyncClient s3AsyncClient ) {
72
86
byte [] originalContent = randomBytes (SMALL_OBJ_SIZE );
73
87
createOriginalObject (originalContent , ORIGINAL_OBJ );
74
- copyObject (ORIGINAL_OBJ , COPIED_OBJ );
88
+ copyObject (ORIGINAL_OBJ , COPIED_OBJ , s3AsyncClient );
75
89
validateCopiedObject (originalContent , ORIGINAL_OBJ );
76
90
}
77
91
78
- @ Test
79
- void copy_copiedObject_hasSameContent () {
92
+ @ ParameterizedTest (autoCloseArguments = false )
93
+ @ MethodSource ("s3AsyncClient" )
94
+ void copy_copiedObject_hasSameContent (S3AsyncClient s3AsyncClient ) {
80
95
byte [] originalContent = randomBytes (OBJ_SIZE );
81
96
createOriginalObject (originalContent , ORIGINAL_OBJ );
82
- copyObject (ORIGINAL_OBJ , COPIED_OBJ );
97
+ copyObject (ORIGINAL_OBJ , COPIED_OBJ , s3AsyncClient );
83
98
validateCopiedObject (originalContent , ORIGINAL_OBJ );
84
99
}
85
100
86
- @ Test
87
- void copy_specialCharacters_hasSameContent () {
101
+ @ ParameterizedTest (autoCloseArguments = false )
102
+ @ MethodSource ("s3AsyncClient" )
103
+ void copy_specialCharacters_hasSameContent (S3AsyncClient s3AsyncClient ) {
88
104
byte [] originalContent = randomBytes (OBJ_SIZE );
89
105
createOriginalObject (originalContent , ORIGINAL_OBJ_SPECIAL_CHARACTER );
90
- copyObject (ORIGINAL_OBJ_SPECIAL_CHARACTER , COPIED_OBJ_SPECIAL_CHARACTER );
106
+ copyObject (ORIGINAL_OBJ_SPECIAL_CHARACTER , COPIED_OBJ_SPECIAL_CHARACTER , s3AsyncClient );
91
107
validateCopiedObject (originalContent , COPIED_OBJ_SPECIAL_CHARACTER );
92
108
}
93
109
94
- @ Test
95
- void copy_ssecServerSideEncryption_shouldSucceed () {
110
+ @ ParameterizedTest (autoCloseArguments = false )
111
+ @ MethodSource ("s3AsyncClient" )
112
+ void copy_ssecServerSideEncryption_shouldSucceed (S3AsyncClient s3AsyncClient ) {
96
113
byte [] originalContent = randomBytes (OBJ_SIZE );
97
114
byte [] secretKey = generateSecretKey ();
98
115
String b64Key = Base64 .getEncoder ().encodeToString (secretKey );
@@ -102,16 +119,16 @@ void copy_ssecServerSideEncryption_shouldSucceed() {
102
119
String newB64Key = Base64 .getEncoder ().encodeToString (newSecretKey );
103
120
String newB64KeyMd5 = Md5Utils .md5AsBase64 (newSecretKey );
104
121
105
- // Java S3 client is used because CRT S3 client putObject fails with SSE-C
106
- // TODO: change back to S3CrtClient once the issue is fixed in CRT
122
+ // MPU S3 client gets stuck
123
+ // TODO: change back to s3AsyncClient once the issue is fixed in MPU S3 client
107
124
s3Async .putObject (r -> r .bucket (BUCKET )
108
125
.key (ORIGINAL_OBJ )
109
126
.sseCustomerKey (b64Key )
110
127
.sseCustomerAlgorithm (AES256 .name ())
111
128
.sseCustomerKeyMD5 (b64KeyMd5 ),
112
129
AsyncRequestBody .fromBytes (originalContent )).join ();
113
130
114
- CompletableFuture <CopyObjectResponse > future = s3CrtAsyncClient .copyObject (c -> c
131
+ CompletableFuture <CopyObjectResponse > future = s3AsyncClient .copyObject (c -> c
115
132
.sourceBucket (BUCKET )
116
133
.sourceKey (ORIGINAL_OBJ )
117
134
.metadataDirective (MetadataDirective .REPLACE )
@@ -147,8 +164,8 @@ private void createOriginalObject(byte[] originalContent, String originalKey) {
147
164
AsyncRequestBody .fromBytes (originalContent )).join ();
148
165
}
149
166
150
- private void copyObject (String original , String destination ) {
151
- CompletableFuture <CopyObjectResponse > future = s3CrtAsyncClient .copyObject (c -> c
167
+ private void copyObject (String original , String destination , S3AsyncClient s3AsyncClient ) {
168
+ CompletableFuture <CopyObjectResponse > future = s3AsyncClient .copyObject (c -> c
152
169
.sourceBucket (BUCKET )
153
170
.sourceKey (original )
154
171
.destinationBucket (BUCKET )
0 commit comments