hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject git commit: HBASE-12218 Make HBaseCommonTestingUtil#deleteDir try harder
Date Thu, 09 Oct 2014 18:57:42 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 b19db7996 -> 8b167e4c9


HBASE-12218 Make HBaseCommonTestingUtil#deleteDir try harder


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/8b167e4c
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/8b167e4c
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/8b167e4c

Branch: refs/heads/branch-1
Commit: 8b167e4c9493162e9c0a9cc0e8185d8306ee5ac5
Parents: b19db79
Author: Elliott Clark <eclark@apache.org>
Authored: Thu Oct 9 11:04:56 2014 -0700
Committer: Elliott Clark <eclark@apache.org>
Committed: Thu Oct 9 11:57:33 2014 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/HBaseCommonTestingUtility.java | 45 +++++++++++---------
 1 file changed, 26 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/8b167e4c/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
index 5ccc8c4..18ca35c 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
@@ -52,6 +52,7 @@ public class HBaseCommonTestingUtility {
 
   /**
    * Returns this classes's instance of {@link Configuration}.
+   *
    * @return Instance of Configuration.
    */
   public Configuration getConfiguration() {
@@ -62,24 +63,25 @@ public class HBaseCommonTestingUtility {
    * System property key to get base test directory value
    */
   public static final String BASE_TEST_DIRECTORY_KEY =
-    "test.build.data.basedirectory";
+      "test.build.data.basedirectory";
 
   /**
    * Default base directory for test output.
    */
   public static final String DEFAULT_BASE_TEST_DIRECTORY = "target/test-data";
 
-  /** Directory where we put the data for this instance of HBaseTestingUtility*/
+  /**
+   * Directory where we put the data for this instance of HBaseTestingUtility
+   */
   private File dataTestDir = null;
 
   /**
    * @return Where to write test data on local filesystem, specific to
-   *  the test.  Useful for tests that do not use a cluster.
+   * the test.  Useful for tests that do not use a cluster.
    * Creates it if it does not exist already.
-   * @see #getTestFileSystem()
    */
   public Path getDataTestDir() {
-    if (this.dataTestDir == null){
+    if (this.dataTestDir == null) {
       setupDataTestDir();
     }
     return new Path(this.dataTestDir.getAbsolutePath());
@@ -103,7 +105,7 @@ public class HBaseCommonTestingUtility {
   protected Path setupDataTestDir() {
     if (this.dataTestDir != null) {
       LOG.warn("Data test dir already setup in " +
-        dataTestDir.getAbsolutePath());
+          dataTestDir.getAbsolutePath());
       return null;
     }
 
@@ -120,8 +122,8 @@ public class HBaseCommonTestingUtility {
     return testPath;
   }
 
-  protected void createSubDir(String propertyName, Path parent, String subDirName){
-    Path newPath= new Path(parent, subDirName);
+  protected void createSubDir(String propertyName, Path parent, String subDirName) {
+    Path newPath = new Path(parent, subDirName);
     File newDir = new File(newPath.toString()).getAbsoluteFile();
     if (deleteOnExit()) newDir.deleteOnExit();
     conf.set(propertyName, newDir.getAbsolutePath());
@@ -133,7 +135,7 @@ public class HBaseCommonTestingUtility {
   boolean deleteOnExit() {
     String v = System.getProperty("hbase.testing.preserve.testdir");
     // Let default be true, to delete on exit.
-    return v == null? true: !Boolean.parseBoolean(v);
+    return v == null ? true : !Boolean.parseBoolean(v);
   }
 
   /**
@@ -154,7 +156,7 @@ public class HBaseCommonTestingUtility {
    * @throws IOException
    */
   boolean cleanupTestDir(final String subdir) throws IOException {
-    if (this.dataTestDir == null){
+    if (this.dataTestDir == null) {
       return false;
     }
     return deleteDir(new File(this.dataTestDir, subdir));
@@ -166,11 +168,10 @@ public class HBaseCommonTestingUtility {
    * Should not be used by the unit tests, hence its's private.
    * Unit test will use a subdirectory of this directory.
    * @see #setupDataTestDir()
-   * @see #getTestFileSystem()
    */
   private Path getBaseTestDir() {
     String PathName = System.getProperty(
-      BASE_TEST_DIRECTORY_KEY, DEFAULT_BASE_TEST_DIRECTORY);
+        BASE_TEST_DIRECTORY_KEY, DEFAULT_BASE_TEST_DIRECTORY);
 
     return new Path(PathName);
   }
@@ -184,12 +185,18 @@ public class HBaseCommonTestingUtility {
     if (dir == null || !dir.exists()) {
       return true;
     }
-    try {
-      if (deleteOnExit()) FileUtils.deleteDirectory(dir);
-      return true;
-    } catch (IOException ex) {
-      LOG.warn("Failed to delete " + dir.getAbsolutePath());
-      return false;
-    }
+    int ntries = 0;
+    do {
+      ntries += 1;
+      try {
+        if (deleteOnExit()) FileUtils.deleteDirectory(dir);
+        return true;
+      } catch (IOException ex) {
+        LOG.warn("Failed to delete " + dir.getAbsolutePath());
+      } catch (IllegalArgumentException ex) {
+        LOG.warn("Failed to delete " + dir.getAbsolutePath(), ex);
+      }
+    } while (ntries < 30);
+    return ntries < 30;
   }
 }


Mime
View raw message