From e52a38d50111d7b5ea6d4dd8860e9475e024a69d Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Wed, 11 Sep 2013 19:51:30 +0000 Subject: [PATCH] HBASE-9462 HBaseAdmin#isTableEnabled() should throw exception for non-existent table git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1522010 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/client/HBaseAdmin.java | 12 ++++++++++++ .../org/apache/hadoop/hbase/client/TestAdmin.java | 15 +++++++++++++++ 2 files changed, 27 insertions(+) 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";