From 0d81636b8556183211db9fec240337a8cab0c60b Mon Sep 17 00:00:00 2001 From: mbautin Date: Wed, 3 Aug 2011 17:00:13 -0700 Subject: [PATCH] rev 2 of fixing TestHRegionInfo.testGetSetOfHTD by removing the temporary table directory if it already exists. --- .../java/org/apache/hadoop/hbase/util/FSUtils.java | 12 ++++++++++++ .../hadoop/hbase/regionserver/TestHRegionInfo.java | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java b/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java index 3c361de..81978d2 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java +++ b/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java @@ -1004,6 +1004,18 @@ public class FSUtils { } /** + * Deletes a table's directory from the file system if exists. Used in unit + * tests. + */ + public static void deleteTableDescriptorIfExists(String tableName, + Configuration conf) throws IOException { + FileSystem fs = getCurrentFileSystem(conf); + Path tableInfoPath = getTableInfoPath(getRootDir(conf), tableName); + if (fs.exists(tableInfoPath)) + deleteDirectory(fs, tableInfoPath); + } + + /** * Called when we are creating a table to write out the tables' descriptor. * @param fs * @param hTableDescriptor diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java b/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index fcd5518..6d83b00 100644 --- a/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ b/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java @@ -25,6 +25,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; + import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -60,9 +62,15 @@ public class TestHRegionInfo { } @Test - public void testGetSetOfHTD() { + public void testGetSetOfHTD() throws IOException { HBaseTestingUtility HTU = new HBaseTestingUtility(); final String tablename = "testGetSetOfHTD"; + + // Delete the temporary table directory that might still be there from the + // previous test run. + FSUtils.deleteTableDescriptorIfExists(tablename, + HTU.getConfiguration()); + HTableDescriptor htd = new HTableDescriptor(tablename); FSUtils.createTableDescriptor(htd, HTU.getConfiguration()); HRegionInfo hri = new HRegionInfo(Bytes.toBytes("testGetSetOfHTD"), -- 1.7.4.4