|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.fs.s3a.impl;
|
20 | 20 |
|
| 21 | +import java.io.IOException; |
21 | 22 | import java.time.Duration;
|
22 | 23 | import java.util.Arrays;
|
23 | 24 |
|
|
28 | 29 |
|
29 | 30 | import org.apache.hadoop.conf.Configuration;
|
30 | 31 | import org.apache.hadoop.test.AbstractHadoopTestBase;
|
| 32 | +import org.apache.hadoop.util.Lists; |
31 | 33 |
|
| 34 | +import static org.apache.hadoop.fs.s3a.Constants.AWS_SERVICE_IDENTIFIER_S3; |
| 35 | +import static org.apache.hadoop.fs.s3a.Constants.AWS_SERVICE_IDENTIFIER_STS; |
32 | 36 | import static org.apache.hadoop.fs.s3a.Constants.CONNECTION_ACQUISITION_TIMEOUT;
|
33 | 37 | import static org.apache.hadoop.fs.s3a.Constants.CONNECTION_IDLE_TIME;
|
34 | 38 | import static org.apache.hadoop.fs.s3a.Constants.CONNECTION_KEEPALIVE;
|
35 | 39 | import static org.apache.hadoop.fs.s3a.Constants.CONNECTION_TTL;
|
| 40 | +import static org.apache.hadoop.fs.s3a.Constants.CUSTOM_HEADERS_S3; |
| 41 | +import static org.apache.hadoop.fs.s3a.Constants.CUSTOM_HEADERS_STS; |
36 | 42 | import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_CONNECTION_ACQUISITION_TIMEOUT_DURATION;
|
37 | 43 | import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_CONNECTION_IDLE_TIME_DURATION;
|
38 | 44 | import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_CONNECTION_KEEPALIVE;
|
|
47 | 53 | import static org.apache.hadoop.fs.s3a.Constants.REQUEST_TIMEOUT;
|
48 | 54 | import static org.apache.hadoop.fs.s3a.Constants.SOCKET_TIMEOUT;
|
49 | 55 | import static org.apache.hadoop.fs.s3a.impl.AWSClientConfig.createApiConnectionSettings;
|
| 56 | +import static org.apache.hadoop.fs.s3a.impl.AWSClientConfig.createClientConfigBuilder; |
50 | 57 | import static org.apache.hadoop.fs.s3a.impl.AWSClientConfig.createConnectionSettings;
|
51 | 58 | import static org.apache.hadoop.fs.s3a.impl.ConfigurationHelper.enforceMinimumDuration;
|
52 | 59 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -201,4 +208,122 @@ public void testCreateApiConnectionSettingsDefault() {
|
201 | 208 | private void setOptionsToValue(String value, Configuration conf, String... keys) {
|
202 | 209 | Arrays.stream(keys).forEach(key -> conf.set(key, value));
|
203 | 210 | }
|
| 211 | + |
| 212 | + /** |
| 213 | + * if {@link org.apache.hadoop.fs.s3a.Constants#CUSTOM_HEADERS_STS} is set, |
| 214 | + * verify that returned client configuration has desired headers set. |
| 215 | + */ |
| 216 | + @Test |
| 217 | + public void testInitRequestHeadersForSTS() throws IOException { |
| 218 | + final Configuration conf = new Configuration(); |
| 219 | + conf.set(CUSTOM_HEADERS_STS, "header1=value1;value2,header2=value3"); |
| 220 | + |
| 221 | + Assertions.assertThat(conf.get(CUSTOM_HEADERS_S3)) |
| 222 | + .describedAs("Custom client headers for s3 %s", CUSTOM_HEADERS_S3) |
| 223 | + .isNull(); |
| 224 | + |
| 225 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 226 | + .headers().size()) |
| 227 | + .describedAs("Count of S3 client headers") |
| 228 | + .isEqualTo(0); |
| 229 | + |
| 230 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_STS) |
| 231 | + .headers().size()) |
| 232 | + .describedAs("Count of STS client headers") |
| 233 | + .isEqualTo(2); |
| 234 | + |
| 235 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_STS) |
| 236 | + .headers().get("header1")) |
| 237 | + .describedAs("STS client 'header1' header value") |
| 238 | + .isEqualTo(Lists.newArrayList("value1", "value2")); |
| 239 | + |
| 240 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_STS) |
| 241 | + .headers().get("header2")) |
| 242 | + .describedAs("STS client 'header2' header value") |
| 243 | + .isEqualTo(Lists.newArrayList("value3")); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * if {@link org.apache.hadoop.fs.s3a.Constants#CUSTOM_HEADERS_S3} is set, |
| 248 | + * verify that returned client configuration has desired headers set. |
| 249 | + */ |
| 250 | + @Test |
| 251 | + public void testInitRequestHeadersForS3() throws IOException { |
| 252 | + final Configuration conf = new Configuration(); |
| 253 | + conf.set(CUSTOM_HEADERS_S3, "header1=value1;value2,header2=value3"); |
| 254 | + |
| 255 | + Assertions.assertThat(conf.get(CUSTOM_HEADERS_STS)) |
| 256 | + .describedAs("Custom client headers for STS %s", CUSTOM_HEADERS_STS) |
| 257 | + .isNull(); |
| 258 | + |
| 259 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_STS) |
| 260 | + .headers().size()) |
| 261 | + .describedAs("Count of STS client headers") |
| 262 | + .isEqualTo(0); |
| 263 | + |
| 264 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 265 | + .headers().size()) |
| 266 | + .describedAs("Count of S3 client headers") |
| 267 | + .isEqualTo(2); |
| 268 | + |
| 269 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 270 | + .headers().get("header1")) |
| 271 | + .describedAs("S3 client 'header1' header value") |
| 272 | + .isEqualTo(Lists.newArrayList("value1", "value2")); |
| 273 | + |
| 274 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 275 | + .headers().get("header2")) |
| 276 | + .describedAs("S3 client 'header2' header value") |
| 277 | + .isEqualTo(Lists.newArrayList("value3")); |
| 278 | + } |
| 279 | + |
| 280 | + /** |
| 281 | + * if {@link org.apache.hadoop.fs.s3a.Constants#CUSTOM_HEADERS_S3} is set, |
| 282 | + * verify that returned client configuration has desired headers set with |
| 283 | + * whitespaces trimmed for headers and values. |
| 284 | + */ |
| 285 | + @Test |
| 286 | + public void testInitRequestHeadersForS3WithWhitespace() throws IOException { |
| 287 | + final Configuration conf = new Configuration(); |
| 288 | + conf.set(CUSTOM_HEADERS_S3, " header1 = value1 ; value2 , header2= value3 "); |
| 289 | + |
| 290 | + Assertions.assertThat(conf.get(CUSTOM_HEADERS_STS)) |
| 291 | + .describedAs("Custom client headers for STS %s", CUSTOM_HEADERS_STS) |
| 292 | + .isNull(); |
| 293 | + |
| 294 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_STS) |
| 295 | + .headers().size()) |
| 296 | + .describedAs("Count of STS client headers") |
| 297 | + .isEqualTo(0); |
| 298 | + |
| 299 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 300 | + .headers().size()) |
| 301 | + .describedAs("Count of S3 client headers") |
| 302 | + .isEqualTo(2); |
| 303 | + |
| 304 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 305 | + .headers().get("header1")) |
| 306 | + .describedAs("S3 client 'header1' header value") |
| 307 | + .isEqualTo(Lists.newArrayList("value1", "value2")); |
| 308 | + |
| 309 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 310 | + .headers().get("header2")) |
| 311 | + .describedAs("S3 client 'header2' header value") |
| 312 | + .isEqualTo(Lists.newArrayList("value3")); |
| 313 | + } |
| 314 | + |
| 315 | + /** |
| 316 | + * if {@link org.apache.hadoop.fs.s3a.Constants#CUSTOM_HEADERS_S3} is set with duplicate values, |
| 317 | + * verify that returned client configuration has desired headers with both values. |
| 318 | + */ |
| 319 | + @Test |
| 320 | + public void testInitRequestHeadersForS3WithDuplicateValues() throws IOException { |
| 321 | + Configuration conf = new Configuration(); |
| 322 | + conf.set(CUSTOM_HEADERS_S3, "header1=duplicate;duplicate"); |
| 323 | + |
| 324 | + Assertions.assertThat(createClientConfigBuilder(conf, AWS_SERVICE_IDENTIFIER_S3) |
| 325 | + .headers().get("header1")) |
| 326 | + .describedAs("S3 client 'header1' header value") |
| 327 | + .isEqualTo(Lists.newArrayList("duplicate", "duplicate")); |
| 328 | + } |
204 | 329 | }
|
0 commit comments