24
24
import org .junit .BeforeClass ;
25
25
import org .junit .Ignore ;
26
26
import org .junit .Test ;
27
+ import software .amazon .awssdk .core .interceptor .Context ;
28
+ import software .amazon .awssdk .core .interceptor .ExecutionAttributes ;
29
+ import software .amazon .awssdk .core .interceptor .ExecutionInterceptor ;
27
30
import software .amazon .awssdk .core .sync .RequestBody ;
28
31
import software .amazon .awssdk .regions .Region ;
29
32
import software .amazon .awssdk .services .s3 .model .AccelerateConfiguration ;
49
52
/**
50
53
* Integration tests for S3 bucket accelerate configuration.
51
54
*/
52
- // TODO: "These tests are a bit flaky. Looks like S3 returns 307 Temporary Redirect occasionally
53
- // for a newly accelerated bucket. Not sure what the right fix is without following redirects
54
- // which we don't want to do for other reasons.
55
- @ Ignore
56
55
public class BucketAccelerateIntegrationTest extends S3IntegrationTestBase {
57
56
58
57
private static final String US_BUCKET_NAME = temporaryBucketName ("s3-accelerate-us-east-1" );
@@ -70,6 +69,7 @@ public static void setup() throws Exception {
70
69
.serviceConfiguration (S3Configuration .builder ()
71
70
.accelerateModeEnabled (true )
72
71
.build ())
72
+ .overrideConfiguration (o -> o .addExecutionInterceptor (new AccelerateValidatingInterceptor ()))
73
73
.build ();
74
74
75
75
setUpBuckets ();
@@ -84,47 +84,6 @@ private static void setUpBuckets() {
84
84
createBucket (US_BUCKET_NAME );
85
85
}
86
86
87
- @ Test
88
- public void testControlPlaneOperationsUnderAccelerateMode () throws Exception {
89
- enableAccelerateOnBucket ();
90
-
91
- Tagging tags = Tagging .builder ()
92
- .tagSet (Tag .builder ()
93
- .key ("foo" )
94
- .value ("bar" )
95
- .build ())
96
- .build ();
97
-
98
- accelerateClient .putBucketTagging (PutBucketTaggingRequest .builder ().bucket (US_BUCKET_NAME ).tagging (tags ).build ());
99
- accelerateClient .putBucketVersioning (PutBucketVersioningRequest .builder ()
100
- .bucket (US_BUCKET_NAME )
101
- .versioningConfiguration (
102
- VersioningConfiguration .builder ()
103
- .status ("Enabled" )
104
- .build ())
105
- .build ());
106
-
107
- // Retry a couple of times due to eventual consistency
108
- RetryableAssertion .doRetryableAssert (new AssertCallable () {
109
- @ Override
110
- public void doAssert () {
111
- List <Tag > taggingConfiguration = accelerateClient
112
- .getBucketTagging (GetBucketTaggingRequest .builder ().bucket (US_BUCKET_NAME ).build ()).tagSet ();
113
-
114
- assertEquals ("foo" , taggingConfiguration .get (0 ).key ());
115
- assertEquals ("bar" , taggingConfiguration .get (0 ).value ());
116
- }
117
- }, new RetryableParams ().withMaxAttempts (30 ).withDelayInMs (200 ));
118
-
119
- assertEquals (BucketVersioningStatus .ENABLED ,
120
- accelerateClient .getBucketVersioning (GetBucketVersioningRequest .builder ()
121
- .bucket (US_BUCKET_NAME )
122
- .build ())
123
- .status ());
124
-
125
- accelerateClient .deleteBucketTagging (DeleteBucketTaggingRequest .builder ().bucket (US_BUCKET_NAME ).build ());
126
- }
127
-
128
87
@ Test
129
88
public void testUpdateAccelerateConfiguration () throws InterruptedException {
130
89
@@ -166,11 +125,15 @@ public void testAccelerateEndpoint() throws Exception {
166
125
167
126
// PutObject
168
127
File uploadFile = new RandomTempFile (KEY_NAME , 1000 );
169
- accelerateClient .putObject (PutObjectRequest .builder ()
170
- .bucket (US_BUCKET_NAME )
171
- .key (KEY_NAME )
172
- .build (),
173
- RequestBody .fromFile (uploadFile ));
128
+ try {
129
+ accelerateClient .putObject (PutObjectRequest .builder ()
130
+ .bucket (US_BUCKET_NAME )
131
+ .key (KEY_NAME )
132
+ .build (),
133
+ RequestBody .fromFile (uploadFile ));
134
+ } catch (Exception e ) {
135
+ // We really only need to verify the request is using the accelerate endpoint
136
+ }
174
137
}
175
138
176
139
private void enableAccelerateOnBucket () throws InterruptedException {
@@ -204,4 +167,14 @@ public void testUnsupportedOperationsUnderAccelerateMode() {
204
167
//fail("Exception is not expected!");
205
168
}
206
169
}
170
+
171
+ private static final class AccelerateValidatingInterceptor implements ExecutionInterceptor {
172
+
173
+ @ Override
174
+ public void beforeTransmission (Context .BeforeTransmission context , ExecutionAttributes executionAttributes ) {
175
+ if (!(context .request () instanceof ListBucketsRequest )) {
176
+ assertEquals (context .httpRequest ().host (), US_BUCKET_NAME + ".s3-accelerate.amazonaws.com" );
177
+ }
178
+ }
179
+ }
207
180
}
0 commit comments