You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2014/10/09 20:57:11 UTC

git commit: HBASE-12218 Make HBaseCommonTestingUtil#deleteDir try harder

Repository: hbase
Updated Branches:
  refs/heads/0.98 f31edd800 -> ee7a952f8


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/ee7a952f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ee7a952f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ee7a952f

Branch: refs/heads/0.98
Commit: ee7a952f83948870e0e388a4e2e60a51b84e698e
Parents: f31edd8
Author: Elliott Clark <ec...@apache.org>
Authored: Thu Oct 9 11:04:56 2014 -0700
Committer: Elliott Clark <ec...@apache.org>
Committed: Thu Oct 9 11:56:48 2014 -0700

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


http://git-wip-us.apache.org/repos/asf/hbase/blob/ee7a952f/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;
   }
 }