Skip to content

Commit d787b91

Browse files
committed
fix failing tests
1 parent 4506d43 commit d787b91

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.awssdk.core.retry.RetryUtils;
2525
import software.amazon.awssdk.services.s3.model.S3Exception;
2626
import software.amazon.awssdk.services.s3.model.S3Object;
27+
import software.amazon.encryption.s3.S3EncryptionClientException;
2728

2829
import org.apache.commons.lang3.StringUtils;
2930
import org.apache.hadoop.classification.InterfaceAudience;
@@ -170,6 +171,12 @@ public static IOException translateException(@Nullable String operation,
170171
operation,
171172
StringUtils.isNotEmpty(path)? (" on " + path) : "",
172173
exception);
174+
175+
// Exceptions from encryption client are wrapped in S3EncryptionClientException, so unwrap.
176+
if (exception instanceof S3EncryptionClientException) {
177+
exception = (SdkException) exception.getCause();
178+
}
179+
173180
if (!(exception instanceof AwsServiceException)) {
174181
// exceptions raised client-side: connectivity, auth, network problems...
175182

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/HeaderProcessing.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ private Map<String, byte[]> retrieveHeaders(
332332
maybeSetHeader(headers, XA_CONTENT_LENGTH,
333333
md.contentLength());
334334
}
335-
maybeSetHeader(headers, XA_CONTENT_LENGTH,
336-
md.contentLength());
335+
337336
if (md.sdkHttpResponse() != null && md.sdkHttpResponse().headers() != null
338337
&& md.sdkHttpResponse().headers().get("Content-Range") != null) {
339338
maybeSetHeader(headers, XA_CONTENT_RANGE,

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AClientSideEncryption.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ public void testEncryptionEnabledAndDisabledFS() throws Exception {
237237
assertEquals("Mismatch in content length bytes", SMALL_FILE_SIZE,
238238
encryptedFSFileStatus.getLen());
239239

240-
intercept(SecurityException.class, "",
241-
"SecurityException should be thrown",
240+
intercept(AWSClientIOException.class, "Instruction file not found!",
241+
"AWSClientIOException should be thrown",
242242
() -> {
243243
in.read(new byte[SMALL_FILE_SIZE]);
244244
return "Exception should be raised if unencrypted data is read by "

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public void shouldBeAbleToSwitchOnS3PathStyleAccessViaConfigProperty()
365365
throws Exception {
366366

367367
conf = new Configuration();
368+
unsetClientSideConfiguration(conf);
368369
conf.set(Constants.PATH_STYLE_ACCESS, Boolean.toString(true));
369370
assertTrue(conf.getBoolean(Constants.PATH_STYLE_ACCESS, false));
370371

@@ -403,6 +404,7 @@ public void shouldBeAbleToSwitchOnS3PathStyleAccessViaConfigProperty()
403404
@Test
404405
public void testDefaultUserAgent() throws Exception {
405406
conf = new Configuration();
407+
unsetClientSideConfiguration(conf);
406408
fs = S3ATestUtils.createTestFileSystem(conf);
407409
assertNotNull(fs);
408410
S3Client s3 = getS3Client("User Agent");
@@ -416,6 +418,7 @@ public void testDefaultUserAgent() throws Exception {
416418
@Test
417419
public void testCustomUserAgent() throws Exception {
418420
conf = new Configuration();
421+
unsetClientSideConfiguration(conf);
419422
conf.set(Constants.USER_AGENT_PREFIX, "MyApp");
420423
fs = S3ATestUtils.createTestFileSystem(conf);
421424
assertNotNull(fs);
@@ -431,6 +434,7 @@ public void testCustomUserAgent() throws Exception {
431434
public void testRequestTimeout() throws Exception {
432435
conf = new Configuration();
433436
conf.set(REQUEST_TIMEOUT, "120");
437+
unsetClientSideConfiguration(conf);
434438
fs = S3ATestUtils.createTestFileSystem(conf);
435439
S3Client s3 = getS3Client("Request timeout (ms)");
436440
SdkClientConfiguration clientConfiguration = getField(s3, SdkClientConfiguration.class,
@@ -575,6 +579,12 @@ public void testS3SpecificSignerOverride() throws Exception {
575579
.describedAs("Custom STS signer not called").isTrue();
576580
}
577581

582+
private void unsetClientSideConfiguration(Configuration conf) {
583+
removeBaseAndBucketOverrides(conf, S3_ENCRYPTION_ALGORITHM);
584+
conf.set(Constants.S3_ENCRYPTION_ALGORITHM,
585+
S3AEncryptionMethods.NONE.getMethod());
586+
}
587+
578588
public static final class CustomS3Signer implements Signer {
579589

580590
private static boolean s3SignerCalled = false;

0 commit comments

Comments
 (0)