Skip to content

Commit 846e193

Browse files
committed
Add functional tests
1 parent f505213 commit 846e193

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.services.s3.functionaltests;
17+
18+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
20+
import static com.github.tomakehurst.wiremock.client.WireMock.head;
21+
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
22+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
23+
24+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
25+
import java.net.URI;
26+
import org.junit.Before;
27+
import org.junit.Rule;
28+
import org.junit.Test;
29+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
30+
import software.amazon.awssdk.regions.Region;
31+
import software.amazon.awssdk.services.s3.S3Client;
32+
import software.amazon.awssdk.services.s3.model.S3Exception;
33+
34+
public class HeadOperationsThrottlingTest {
35+
36+
@Rule
37+
public WireMockRule mockServer = new WireMockRule(0);
38+
39+
private S3Client client;
40+
41+
@Before
42+
public void setup() {
43+
client = S3Client.builder()
44+
.endpointOverride(URI.create("http://localhost:" + mockServer.port()))
45+
.credentialsProvider(() -> AwsBasicCredentials.create("test", "test"))
46+
.forcePathStyle(true)
47+
.region(Region.US_EAST_1)
48+
.build();
49+
}
50+
51+
@Test
52+
public void headObject503SlowDown_shouldBeThrottlingException() {
53+
stubFor(head(anyUrl()).willReturn(aResponse().withStatus(503).withStatusMessage("Slow Down")));
54+
55+
assertThatThrownBy(() -> client.headObject(r -> r.bucket("bucket").key("key")))
56+
.isInstanceOfSatisfying(S3Exception.class, e -> {
57+
assert e.statusCode() == 503;
58+
assert e.isThrottlingException();
59+
assert "SlowDown".equals(e.awsErrorDetails().errorCode());
60+
});
61+
}
62+
63+
@Test
64+
public void headBucket503SlowDown_shouldBeThrottlingException() {
65+
stubFor(head(anyUrl()).willReturn(aResponse().withStatus(503).withStatusMessage("Slow Down")));
66+
67+
assertThatThrownBy(() -> client.headBucket(r -> r.bucket("bucket")))
68+
.isInstanceOfSatisfying(S3Exception.class, e -> {
69+
assert e.statusCode() == 503;
70+
assert e.isThrottlingException();
71+
assert "SlowDown".equals(e.awsErrorDetails().errorCode());
72+
});
73+
}
74+
75+
@Test
76+
public void headObject503OtherException_shouldNotBeThrottlingException() {
77+
stubFor(head(anyUrl()).willReturn(aResponse().withStatus(503).withStatusMessage("Service Unavailable")));
78+
79+
assertThatThrownBy(() -> client.headObject(r -> r.bucket("bucket").key("key")))
80+
.isInstanceOfSatisfying(S3Exception.class, e -> {
81+
assert e.statusCode() == 503;
82+
assert !e.isThrottlingException();
83+
assert e.awsErrorDetails().errorCode() == null;
84+
});
85+
}
86+
}

0 commit comments

Comments
 (0)