HBASE-12218 Make HBaseCommonTestingUtil#deleteDir try harder

This commit is contained in:
Elliott Clark 2014-10-09 11:04:56 -07:00
parent 0eb0721fef
commit f75785af51

View File

@ -52,6 +52,7 @@ public class HBaseCommonTestingUtility {
/**
* Returns this classes's instance of {@link Configuration}.
*
* @return Instance of Configuration.
*/
public Configuration getConfiguration() {
@ -69,14 +70,15 @@ public class HBaseCommonTestingUtility {
*/
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.
* Creates it if it does not exist already.
* @see #getTestFileSystem()
*/
public Path getDataTestDir() {
if (this.dataTestDir == null) {
@ -166,7 +168,6 @@ 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(
@ -184,12 +185,18 @@ public class HBaseCommonTestingUtility {
if (dir == null || !dir.exists()) {
return true;
}
int ntries = 0;
do {
ntries += 1;
try {
if (deleteOnExit()) FileUtils.deleteDirectory(dir);
return true;
} catch (IOException ex) {
LOG.warn("Failed to delete " + dir.getAbsolutePath());
return false;
}
} catch (IllegalArgumentException ex) {
LOG.warn("Failed to delete " + dir.getAbsolutePath(), ex);
}
} while (ntries < 30);
return ntries < 30;
}
}