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
This commit is contained in:
Zhihong Yu 2013-09-11 19:51:30 +00:00
parent f29b448419
commit e52a38d501
2 changed files with 27 additions and 0 deletions

View File

@ -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);
}

View File

@ -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";