소스 검색

HADOOP-14129. ITestS3ACredentialsInURL sometimes fails. Contributed by Sean Mackrory and Mingliang Liu

Mingliang Liu 8 년 전
부모
커밋
220414fcf9

+ 6 - 4
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ACredentialsInURL.java

@@ -37,6 +37,7 @@ import java.net.URLEncoder;
 import java.nio.file.AccessDeniedException;
 
 import static org.apache.hadoop.fs.s3a.S3ATestConstants.TEST_FS_S3A_NAME;
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.assumeS3GuardNotEnabled;
 
 /**
  * Tests that credentials can go into the URL. This includes a valid
@@ -63,6 +64,11 @@ public class ITestS3ACredentialsInURL extends Assert {
   public void testInstantiateFromURL() throws Throwable {
 
     Configuration conf = new Configuration();
+
+    // Skip in the case of S3Guard with DynamoDB because it cannot get
+    // credentials for its own use if they're only in S3 URLs
+    assumeS3GuardNotEnabled(conf);
+
     String accessKey = conf.get(Constants.ACCESS_KEY);
     String secretKey = conf.get(Constants.SECRET_KEY);
     String fsname = conf.getTrimmed(TEST_FS_S3A_NAME, "");
@@ -85,10 +91,6 @@ public class ITestS3ACredentialsInURL extends Assert {
     conf.unset(Constants.SECRET_KEY);
     fs = S3ATestUtils.createTestFileSystem(conf);
 
-    // Skip in the case of S3Guard with DynamoDB because it cannot get
-    // credentials for its own use if they're only in S3 URLs
-    Assume.assumeFalse(fs.hasMetadataStore());
-
     String fsURI = fs.getUri().toString();
     assertFalse("FS URI contains a @ symbol", fsURI.contains("@"));
     assertFalse("FS URI contains a % symbol", fsURI.contains("%"));

+ 18 - 0
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/S3ATestUtils.java

@@ -33,11 +33,13 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 
 import static org.apache.hadoop.fs.contract.ContractTestUtils.skip;
 import static org.apache.hadoop.fs.s3a.S3ATestConstants.*;
 import static org.apache.hadoop.fs.s3a.Constants.*;
+import static org.apache.hadoop.fs.s3a.S3AUtils.propagateBucketOptions;
 import static org.junit.Assert.*;
 
 /**
@@ -322,6 +324,22 @@ public final class S3ATestUtils {
         new Path("/" + testUniqueForkId, "test");
   }
 
+  /**
+   * Assume testing S3Guard is not enabled.
+   */
+  public static void assumeS3GuardNotEnabled(Configuration originalConf)
+      throws URISyntaxException {
+    Assume.assumeFalse(getTestPropertyBool(originalConf, TEST_S3GUARD_ENABLED,
+        originalConf.getBoolean(TEST_S3GUARD_ENABLED, false)));
+
+    final String fsname = originalConf.getTrimmed(TEST_FS_S3A_NAME);
+    Assume.assumeNotNull(fsname);
+    final String bucket = new URI(fsname).getHost();
+    final Configuration conf = propagateBucketOptions(originalConf, bucket);
+    Assume.assumeTrue(S3GUARD_METASTORE_NULL.equals(
+        conf.getTrimmed(S3_METADATA_STORE_IMPL, S3GUARD_METASTORE_NULL)));
+  }
+
   /**
    * Conditionally set the S3Guard options from test properties.
    * @param conf configuration