17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
20
- import java .util .Arrays ;
21
20
import java .util .List ;
22
- import java .util .stream .Collectors ;
23
21
import java .util .stream .IntStream ;
24
22
import org .junit .jupiter .api .Test ;
25
23
import software .amazon .awssdk .core .ResponseBytes ;
26
24
import software .amazon .awssdk .core .sync .RequestBody ;
27
- import software .amazon .awssdk .http .SdkHttpMethod ;
28
25
import software .amazon .awssdk .regions .Region ;
29
26
import software .amazon .awssdk .services .s3 .S3IntegrationTestBase ;
30
27
import software .amazon .awssdk .services .s3 .model .ChecksumAlgorithm ;
@@ -50,20 +47,14 @@ public abstract class S3CrossRegionIntegrationTestBase extends S3IntegrationTest
50
47
51
48
private static final String KEY = "key" ;
52
49
53
- protected CaptureInterceptor captureInterceptor ;
54
-
55
50
@ Test
56
51
void getApi_CrossRegionCall () {
57
52
s3 .putObject (p -> p .bucket (bucketName ()).checksumAlgorithm (ChecksumAlgorithm .CRC32 ).key (KEY ), RequestBody .fromString (
58
53
"TEST_STRING" ));
59
54
GetObjectRequest getObjectRequest =
60
55
GetObjectRequest .builder ().bucket (bucketName ()).checksumMode (ChecksumMode .ENABLED ).key (KEY ).build ();
61
56
ResponseBytes <GetObjectResponse > response = getAPICall (getObjectRequest );
62
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
63
- DEFAULT_REGION .id ()));
64
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .GET , SdkHttpMethod .GET ));
65
57
assertThat (new String (response .asByteArray ())).isEqualTo ("TEST_STRING" );
66
- assertThat (captureInterceptor .getServiceCalls ()).isEqualTo (2 );
67
58
}
68
59
69
60
@ Test
@@ -73,11 +64,7 @@ void putApi_CrossRegionCall() {
73
64
PutObjectRequest putObjectRequest =
74
65
PutObjectRequest .builder ().bucket (bucketName ()).checksumAlgorithm (ChecksumAlgorithm .CRC32 ).key (KEY ).build ();
75
66
PutObjectResponse response = putAPICall (putObjectRequest , "TEST_STRING" );
76
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
77
- DEFAULT_REGION .id ()));
78
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .PUT , SdkHttpMethod .PUT ));
79
67
assertThat (response .checksumCRC32 ()).isEqualTo ("S9ke8w==" );
80
- assertThat (captureInterceptor .getServiceCalls ()).isEqualTo (2 );
81
68
}
82
69
83
70
@ Test
@@ -86,11 +73,8 @@ void deleteApi_CrossRegionCall() {
86
73
"TEST_STRING" ));
87
74
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest .builder ().bucket (bucketName ()).key (KEY ).build ();
88
75
DeleteObjectResponse response = deleteObjectAPICall (deleteObjectRequest );
89
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
90
- DEFAULT_REGION .id ()));
91
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .DELETE , SdkHttpMethod .DELETE ));
76
+ System .out .println (response );
92
77
assertThat (response ).isNotNull ();
93
- assertThat (captureInterceptor .getServiceCalls ()).isEqualTo (2 );
94
78
}
95
79
96
80
@ Test
@@ -102,25 +86,18 @@ void postApi_CrossRegionCall() {
102
86
DeleteObjectsRequest deleteObjectsRequest =
103
87
DeleteObjectsRequest .builder ().bucket (bucketName ()).delete (d -> d .objects (o -> o .key (KEY ), o -> o .key (KEY + "_1" ))).build ();
104
88
DeleteObjectsResponse response = postObjectAPICall (deleteObjectsRequest );
105
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
106
- DEFAULT_REGION .id ()));
107
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .POST , SdkHttpMethod .POST ));
108
89
assertThat (response ).isNotNull ();
109
- assertThat ( captureInterceptor . getServiceCalls ()). isEqualTo ( 2 );
90
+ System . out . println ( response );
110
91
}
111
92
112
93
@ Test
113
94
void cachedRegionGetsUsed_when_CrossRegionCall () {
114
95
putAPICall (PutObjectRequest .builder ().bucket (bucketName ()).checksumAlgorithm (ChecksumAlgorithm .CRC32 ).key (KEY ).build (),
115
96
"TEST_STRING" );
116
- getAPICall (GetObjectRequest .builder ().bucket (bucketName ()).checksumMode (ChecksumMode .ENABLED ).key (KEY ).build ());
117
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
118
- DEFAULT_REGION .id (),
119
- DEFAULT_REGION .id ()));
120
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .PUT ,
121
- SdkHttpMethod .PUT ,
122
- SdkHttpMethod .GET ));
123
- assertThat (captureInterceptor .getServiceCalls ()).isEqualTo (3 );
97
+ GetObjectRequest getObjectRequest =
98
+ GetObjectRequest .builder ().bucket (bucketName ()).checksumMode (ChecksumMode .ENABLED ).key (KEY ).build ();
99
+ ResponseBytes <GetObjectResponse > response = getAPICall (getObjectRequest );
100
+ assertThat (new String (response .asByteArray ())).isEqualTo ("TEST_STRING" );
124
101
}
125
102
126
103
@ Test
@@ -136,10 +113,7 @@ void paginatedApi_CrossRegionCall() {
136
113
);
137
114
ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request .builder ().bucket (bucketName ()).maxKeys (maxKeys ).build ();
138
115
List <S3Object > s3ObjectList = paginatedAPICall (listObjectsV2Request );
139
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
140
- DEFAULT_REGION .id (),
141
- DEFAULT_REGION .id ()));
142
-
116
+ assertThat (s3ObjectList ).hasSize (totalKeys );
143
117
IntStream .range (0 , totalKeys ).forEach (i -> s3 .deleteObject (p -> p .bucket (bucketName ()).key (KEY + "_" + i )));
144
118
}
145
119
@@ -149,11 +123,8 @@ void headApi_CrossRegionCall() {
149
123
"TEST_STRING" ));
150
124
HeadBucketRequest headBucketRequest = HeadBucketRequest .builder ().bucket (bucketName ()).build ();
151
125
HeadBucketResponse response = headAPICall (headBucketRequest );
152
- assertThat (regionsIntercepted (captureInterceptor .hosts ())).isEqualTo (Arrays .asList (CROSS_REGION .id (),
153
- DEFAULT_REGION .id ()));
154
- assertThat (captureInterceptor .httpMethods ()).isEqualTo (Arrays .asList (SdkHttpMethod .HEAD , SdkHttpMethod .HEAD ));
155
126
assertThat (response ).isNotNull ();
156
- assertThat ( captureInterceptor . getServiceCalls ()). isEqualTo ( 2 );
127
+ System . out . println ( response );
157
128
}
158
129
159
130
protected abstract List <S3Object > paginatedAPICall (ListObjectsV2Request listObjectsV2Request );
@@ -170,10 +141,4 @@ void headApi_CrossRegionCall() {
170
141
171
142
protected abstract String bucketName ();
172
143
173
- private List <String > regionsIntercepted (List <String > hosts ) {
174
- return hosts .stream ()
175
- .map (req -> req .substring (bucketName ().length () + 4 , req .length () - 14 ))
176
- .collect (Collectors .toList ());
177
- }
178
-
179
144
}
0 commit comments