diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index e368ca27043..1acd2e4c362 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -1001,12 +1001,23 @@ public class HBaseAdmin implements Abortable, Closeable { return failed.toArray(new HTableDescriptor[failed.size()]); } + /* + * Checks whether table exists. If not, throws TableNotFoundException + * @param tableName + */ + private void checkTableExistence(TableName tableName) throws IOException { + if (!tableExists(tableName)) { + throw new TableNotFoundException(tableName); + } + } + /** * @param tableName name of table to check * @return true if table is on-line * @throws IOException if a remote or network exception occurs */ public boolean isTableEnabled(TableName tableName) throws IOException { + checkTableExistence(tableName); return connection.isTableEnabled(tableName); } @@ -1026,6 +1037,7 @@ public class HBaseAdmin implements Abortable, Closeable { * @throws IOException if a remote or network exception occurs */ public boolean isTableDisabled(TableName tableName) throws IOException { + checkTableExistence(tableName); return connection.isTableDisabled(tableName); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index 87568b40562..164c4773f62 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -1709,6 +1709,21 @@ public class TestAdmin { TEST_UTIL.getHBaseAdmin().createTable(htd); } + @Test + public void testIsEnabledOrDisabledOnUnknownTable() throws Exception { + try { + admin.isTableEnabled(Bytes.toBytes("unkownTable")); + fail("Test should fail if isTableEnabled called on unknown table."); + } catch (IOException e) { + } + + try { + admin.isTableDisabled(Bytes.toBytes("unkownTable")); + fail("Test should fail if isTableDisabled called on unknown table."); + } catch (IOException e) { + } + } + @Test (timeout=300000) public void testGetRegion() throws Exception { final String name = "testGetRegion";