1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+
16
+ package software .amazon .awssdk .transfer .s3 ;
17
+
18
+ import org .junit .AfterClass ;
19
+ import org .junit .Before ;
20
+ import org .junit .BeforeClass ;
21
+ import org .junit .Test ;
22
+ import software .amazon .awssdk .services .s3 .model .GetObjectRequest ;
23
+ import software .amazon .awssdk .services .s3 .model .NoSuchBucketException ;
24
+ import software .amazon .awssdk .services .s3 .model .NoSuchKeyException ;
25
+ import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
26
+ import software .amazon .awssdk .testutils .RandomTempFile ;
27
+ import software .amazon .awssdk .transfer .s3 .internal .S3CrtAsyncClient ;
28
+
29
+ import java .io .IOException ;
30
+ import java .nio .file .Files ;
31
+ import java .nio .file .Paths ;
32
+
33
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
34
+ import static software .amazon .awssdk .testutils .service .S3BucketUtils .temporaryBucketName ;
35
+
36
+ public class CrtExceptionTransformationIntegrationTest extends S3IntegrationTestBase {
37
+
38
+ private static final String BUCKET = temporaryBucketName (CrtExceptionTransformationIntegrationTest .class );
39
+
40
+ private static final String KEY = "some-key" ;
41
+
42
+ private static final int OBJ_SIZE = 8 * 1024 ;
43
+ private static RandomTempFile testFile ;
44
+ private S3TransferManager transferManager ;
45
+ private S3CrtAsyncClient s3Crt ;
46
+
47
+ @ BeforeClass
48
+ public static void setupFixture () {
49
+ createBucket (BUCKET );
50
+ }
51
+
52
+ @ AfterClass
53
+ public static void tearDownFixture () {
54
+ deleteBucketAndAllContents (BUCKET );
55
+ }
56
+
57
+ @ Before
58
+ public void methodSetup () throws IOException {
59
+ testFile = new RandomTempFile (BUCKET , OBJ_SIZE );
60
+ s3Crt = S3CrtAsyncClient .builder ()
61
+ .credentialsProvider (CREDENTIALS_PROVIDER_CHAIN )
62
+ .region (S3IntegrationTestBase .DEFAULT_REGION )
63
+ .build ();
64
+ transferManager =
65
+ S3TransferManager .builder ()
66
+ .s3ClientConfiguration (b -> b .credentialsProvider (CREDENTIALS_PROVIDER_CHAIN )
67
+ .region (S3IntegrationTestBase .DEFAULT_REGION )
68
+ .targetThroughputInGbps (20.0 )
69
+ .minimumPartSizeInBytes (1000L ))
70
+ .build ();
71
+ }
72
+
73
+ @ Test
74
+ public void getObjectNoSuchKey () throws IOException {
75
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
76
+ assertThatThrownBy (() -> s3Crt .getObject (GetObjectRequest .builder ().bucket (BUCKET ).key ("randomKey" ).build (),
77
+ Paths .get (randomBaseDirectory ).resolve ("testFile" )).get ())
78
+ .hasCauseInstanceOf (NoSuchKeyException .class )
79
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchKeyException: The specified key does not exist" );
80
+ }
81
+
82
+ @ Test
83
+ public void getObjectNoSuchBucket () throws IOException {
84
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
85
+ assertThatThrownBy (() -> s3Crt .getObject (GetObjectRequest .builder ().bucket ("nonExistingTestBucket" ).key (KEY ).build (),
86
+ Paths .get (randomBaseDirectory ).resolve ("testFile" )).get ())
87
+ .hasCauseInstanceOf (NoSuchBucketException .class )
88
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchBucketException: The specified bucket does not exist" );
89
+ }
90
+
91
+ @ Test
92
+ public void transferManagerDownloadObjectWithNoSuchKey () throws IOException {
93
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
94
+ assertThatThrownBy (() -> transferManager .download (DownloadRequest .builder ()
95
+ .getObjectRequest (GetObjectRequest .builder ().bucket (BUCKET ).key ("randomKey" ).build ())
96
+ .destination (Paths .get (randomBaseDirectory ).resolve ("testFile" ))
97
+ .build ()).completionFuture ().join ())
98
+ .hasCauseInstanceOf (NoSuchKeyException .class )
99
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchKeyException: The specified key does not exist" );
100
+ }
101
+
102
+ @ Test
103
+ public void transferManagerDownloadObjectWithNoSuchBucket () throws IOException {
104
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
105
+ assertThatThrownBy (() -> transferManager .download (DownloadRequest .builder ()
106
+ .getObjectRequest (GetObjectRequest .builder ().bucket ("nonExistingTestBucket" ).key (KEY ).build ())
107
+ .destination (Paths .get (randomBaseDirectory ).resolve ("testFile" ))
108
+ .build ()).completionFuture ().join ())
109
+ .hasCauseInstanceOf (NoSuchBucketException .class )
110
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchBucketException: The specified bucket does not exist" );
111
+ }
112
+
113
+ @ Test
114
+ public void putObjectNoSuchKey () throws IOException {
115
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
116
+ assertThatThrownBy (() -> s3Crt .getObject (GetObjectRequest .builder ().bucket (BUCKET ).key ("someRandomKey" ).build (),
117
+ Paths .get (randomBaseDirectory ).resolve ("testFile" )).get ())
118
+ .hasCauseInstanceOf (NoSuchKeyException .class )
119
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchKeyException: The specified key does not exist" );
120
+ }
121
+
122
+ @ Test
123
+ public void putObjectNoSuchBucket () throws IOException {
124
+
125
+ String randomBaseDirectory = Files .createTempDirectory (getClass ().getSimpleName ()).toString ();
126
+ assertThatThrownBy (() -> s3Crt .getObject (GetObjectRequest .builder ().bucket ("nonExistingTestBucket" ).key (KEY ).build (),
127
+ Paths .get (randomBaseDirectory ).resolve ("testFile" )).get ())
128
+ .hasCauseInstanceOf (NoSuchBucketException .class )
129
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchBucketException: The specified bucket does not exist" );
130
+ }
131
+
132
+ @ Test
133
+ public void transferManagerUploadObjectWithNoSuchObject () throws IOException {
134
+ assertThatThrownBy (() -> transferManager .upload (UploadRequest .builder ()
135
+ .putObjectRequest (PutObjectRequest .builder ().bucket ("nonExistingTestBucket" ).key ("someKey" ).build ())
136
+ .source (testFile .toPath ())
137
+ .build ()).completionFuture ().join ())
138
+ .hasCauseInstanceOf (NoSuchBucketException .class )
139
+ .hasMessageContaining ("software.amazon.awssdk.services.s3.model.NoSuchBucketException: The specified bucket does not exist" );
140
+ }
141
+ }
0 commit comments