Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C9E5A179C9 for ; Thu, 9 Oct 2014 18:57:42 +0000 (UTC) Received: (qmail 53359 invoked by uid 500); 9 Oct 2014 18:57:42 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 53319 invoked by uid 500); 9 Oct 2014 18:57:42 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 53310 invoked by uid 99); 9 Oct 2014 18:57:42 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 18:57:42 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 695E5D041; Thu, 9 Oct 2014 18:57:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: eclark@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: HBASE-12218 Make HBaseCommonTestingUtil#deleteDir try harder Date: Thu, 9 Oct 2014 18:57:42 +0000 (UTC) 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 Authored: Thu Oct 9 11:04:56 2014 -0700 Committer: Elliott Clark 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; } }