Преглед на файлове

HADOOP-14125 s3guard tool tests aren't isolated; can't run in parallel.
Contributed by Sean Mackrory.

Steve Loughran преди 8 години
родител
ревизия
0942c9f96d

+ 1 - 1
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java

@@ -64,7 +64,7 @@ public class ITestS3GuardToolDynamoDB extends S3GuardToolTestBase {
   public void testDynamoDBInitDestroyCycle() throws IOException,
   public void testDynamoDBInitDestroyCycle() throws IOException,
       InterruptedException {
       InterruptedException {
     String testTableName = "testDynamoDBInitDestroy" + new Random().nextInt();
     String testTableName = "testDynamoDBInitDestroy" + new Random().nextInt();
-    String testS3Url = getTestPath(testTableName);
+    String testS3Url = path(testTableName).toString();
     S3AFileSystem fs = getFs();
     S3AFileSystem fs = getFs();
     DynamoDB db = null;
     DynamoDB db = null;
     try {
     try {

+ 5 - 9
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardToolTestBase.java

@@ -21,6 +21,7 @@ package org.apache.hadoop.fs.s3a.s3guard;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
+import org.apache.hadoop.fs.s3a.AbstractS3ATestBase;
 import org.apache.hadoop.fs.s3a.Constants;
 import org.apache.hadoop.fs.s3a.Constants;
 import org.apache.hadoop.fs.s3a.S3AFileStatus;
 import org.apache.hadoop.fs.s3a.S3AFileStatus;
 import org.apache.hadoop.fs.s3a.S3AFileSystem;
 import org.apache.hadoop.fs.s3a.S3AFileSystem;
@@ -39,7 +40,7 @@ import static org.junit.Assert.assertEquals;
 /**
 /**
  * Common functionality for S3GuardTool test cases.
  * Common functionality for S3GuardTool test cases.
  */
  */
-public abstract class S3GuardToolTestBase {
+public abstract class S3GuardToolTestBase extends AbstractS3ATestBase {
 
 
   protected static final String OWNER = "hdfs";
   protected static final String OWNER = "hdfs";
 
 
@@ -59,11 +60,6 @@ public abstract class S3GuardToolTestBase {
     return fs;
     return fs;
   }
   }
 
 
-  /** Get test path of s3. */
-  protected String getTestPath(String path) {
-    return fs.qualify(new Path(path)).toString();
-  }
-
   protected abstract MetadataStore newMetadataStore();
   protected abstract MetadataStore newMetadataStore();
 
 
   @Before
   @Before
@@ -125,7 +121,7 @@ public abstract class S3GuardToolTestBase {
 
 
   private void testPruneCommand(Configuration cmdConf, String[] args)
   private void testPruneCommand(Configuration cmdConf, String[] args)
       throws Exception {
       throws Exception {
-    Path parent = new Path(getTestPath("/prune-cli"));
+    Path parent = path("prune-cli");
     try {
     try {
       fs.mkdirs(parent);
       fs.mkdirs(parent);
 
 
@@ -148,7 +144,7 @@ public abstract class S3GuardToolTestBase {
 
 
   @Test
   @Test
   public void testPruneCommandCLI() throws Exception {
   public void testPruneCommandCLI() throws Exception {
-    String testPath = getTestPath("testPruneCommandCLI");
+    String testPath = path("testPruneCommandCLI").toString();
     testPruneCommand(fs.getConf(), new String[]{"prune", "-S", "1", testPath});
     testPruneCommand(fs.getConf(), new String[]{"prune", "-S", "1", testPath});
   }
   }
 
 
@@ -156,7 +152,7 @@ public abstract class S3GuardToolTestBase {
   public void testPruneCommandConf() throws Exception {
   public void testPruneCommandConf() throws Exception {
     conf.setLong(Constants.S3GUARD_CLI_PRUNE_AGE,
     conf.setLong(Constants.S3GUARD_CLI_PRUNE_AGE,
         TimeUnit.SECONDS.toMillis(1));
         TimeUnit.SECONDS.toMillis(1));
-    String testPath = getTestPath("testPruneCommandConf");
+    String testPath = path("testPruneCommandConf").toString();
     testPruneCommand(conf, new String[]{"prune", testPath});
     testPruneCommand(conf, new String[]{"prune", testPath});
   }
   }
 }
 }

+ 9 - 7
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/TestS3GuardTool.java

@@ -51,8 +51,9 @@ public class TestS3GuardTool extends S3GuardToolTestBase {
   public void testImportCommand() throws IOException {
   public void testImportCommand() throws IOException {
     S3AFileSystem fs = getFs();
     S3AFileSystem fs = getFs();
     MetadataStore ms = getMetadataStore();
     MetadataStore ms = getMetadataStore();
-    fs.mkdirs(new Path("/test"));
-    Path dir = new Path("/test/a");
+    Path parent = path("test-import");
+    fs.mkdirs(parent);
+    Path dir = new Path(parent, "a");
     fs.mkdirs(dir);
     fs.mkdirs(dir);
     for (int i = 0; i < 10; i++) {
     for (int i = 0; i < 10; i++) {
       String child = String.format("file-%d", i);
       String child = String.format("file-%d", i);
@@ -65,10 +66,10 @@ public class TestS3GuardTool extends S3GuardToolTestBase {
     cmd.setMetadataStore(ms);
     cmd.setMetadataStore(ms);
 
 
     assertEquals("Import command did not exit successfully - see output",
     assertEquals("Import command did not exit successfully - see output",
-        SUCCESS, cmd.run(new String[]{"import", getTestPath("/test/a")}));
+        SUCCESS, cmd.run(new String[]{"import", dir.toString()}));
 
 
     DirListingMetadata children =
     DirListingMetadata children =
-        ms.listChildren(new Path(getTestPath("/test/a")));
+        ms.listChildren(dir);
     assertEquals("Unexpected number of paths imported", 10, children
     assertEquals("Unexpected number of paths imported", 10, children
         .getListing().size());
         .getListing().size());
     // assertTrue(children.isAuthoritative());
     // assertTrue(children.isAuthoritative());
@@ -81,8 +82,8 @@ public class TestS3GuardTool extends S3GuardToolTestBase {
     Set<Path> filesOnS3 = new HashSet<>(); // files on S3.
     Set<Path> filesOnS3 = new HashSet<>(); // files on S3.
     Set<Path> filesOnMS = new HashSet<>(); // files on metadata store.
     Set<Path> filesOnMS = new HashSet<>(); // files on metadata store.
 
 
-    String testPath = getTestPath("/test-diff");
-    mkdirs(new Path(testPath), true, true);
+    Path testPath = path("test-diff");
+    mkdirs(testPath, true, true);
 
 
     Path msOnlyPath = new Path(testPath, "ms_only");
     Path msOnlyPath = new Path(testPath, "ms_only");
     mkdirs(msOnlyPath, false, true);
     mkdirs(msOnlyPath, false, true);
@@ -107,7 +108,8 @@ public class TestS3GuardTool extends S3GuardToolTestBase {
     Diff cmd = new Diff(fs.getConf());
     Diff cmd = new Diff(fs.getConf());
     cmd.setMetadataStore(ms);
     cmd.setMetadataStore(ms);
     assertEquals("Diff command did not exit successfully - see output", SUCCESS,
     assertEquals("Diff command did not exit successfully - see output", SUCCESS,
-        cmd.run(new String[]{"diff", "-m", "local://metadata", testPath}, out));
+        cmd.run(new String[]{"diff", "-m", "local://metadata",
+            testPath.toString()}, out));
 
 
     Set<Path> actualOnS3 = new HashSet<>();
     Set<Path> actualOnS3 = new HashSet<>();
     Set<Path> actualOnMS = new HashSet<>();
     Set<Path> actualOnMS = new HashSet<>();