From 21444151416e29518f8a6f9fa1e68b6a85509eb4 Mon Sep 17 00:00:00 2001 From: Jonathan Hsieh Date: Mon, 23 Jul 2012 07:18:32 +0000 Subject: [PATCH] HBASE-4470 ServerNotRunningException coming out of assignRootAndMeta kills the Master (Gregory Chanan) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1364532 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/catalog/TestCatalogTracker.java | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java index bf3c8f214e7..ecfcd9ffa76 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java @@ -62,6 +62,7 @@ import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.util.Progressable; import org.apache.zookeeper.KeeperException; +import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -265,15 +266,7 @@ public class TestCatalogTracker { } } - /** - * Test we survive a connection refused {@link ConnectException} - * @throws IOException - * @throws InterruptedException - * @throws KeeperException - * @throws ServiceException - */ - @Test - public void testGetMetaServerConnectionFails() + private void testVerifyMetaRegionLocationWithException(Exception ex) throws IOException, InterruptedException, KeeperException, ServiceException { // Mock an ClientProtocol. final ClientProtocol implementation = Mockito.mock(ClientProtocol.class); @@ -281,7 +274,7 @@ public class TestCatalogTracker { try { // If a 'get' is called on mocked interface, throw connection refused. Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())). - thenThrow(new ServiceException(new ConnectException("Connection refused"))); + thenThrow(new ServiceException(ex)); // Now start up the catalogtracker with our doctored Connection. final CatalogTracker ct = constructAndStartCatalogTracker(connection); try { @@ -300,6 +293,39 @@ public class TestCatalogTracker { } } + /** + * Test we survive a connection refused {@link ConnectException} + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + * @throws ServiceException + */ + @Test + public void testGetMetaServerConnectionFails() + throws IOException, InterruptedException, KeeperException, ServiceException { + testVerifyMetaRegionLocationWithException(new ConnectException("Connection refused")); + } + + /** + * Test that verifyMetaRegionLocation properly handles getting a + * ServerNotRunningException. See HBASE-4470. + * Note this doesn't check the exact exception thrown in the + * HBASE-4470 as there it is thrown from getHConnection() and + * here it is thrown from get() -- but those are both called + * from the same function anyway, and this way is less invasive than + * throwing from getHConnection would be. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + * @throws ServiceException + */ + @Test + public void testVerifyMetaRegionServerNotRunning() + throws IOException, InterruptedException, KeeperException, ServiceException { + testVerifyMetaRegionLocationWithException(new ServerNotRunningYetException("mock")); + } + /** * Test get of root region fails properly if nothing to connect to. * @throws IOException