diff --git a/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java b/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java index 8e16b0a..e4afe55 100644 --- a/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java +++ b/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java @@ -165,6 +165,46 @@ public class TestCatalogTracker { } @Test + public void testServerNotRunningIOException() + throws IOException, InterruptedException, KeeperException { + HConnection connection = + HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration()); + try { + // Mock an HRegionInterface. + final HRegionInterface implementation = Mockito.mock(HRegionInterface.class); + // If a 'getRegionInfo' is called on mocked interface, throw IOE. + Mockito.when(implementation.getRegionInfo((byte[]) Mockito.any())). + thenThrow(new IOException("Server not running, aborting")); + // Make it so our implementation is returned when we do a connection. + // Need to fake out the location lookup stuff first. + ServerName sn = new ServerName("example.com", 1234, System.currentTimeMillis()); + final HRegionLocation anyLocation = + new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn.getHostname(), + sn.getPort()); + Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(), + (byte[]) Mockito.any(), Mockito.anyBoolean())). + thenReturn(anyLocation); + Mockito.when(connection.getHRegionConnection(Mockito.anyString(), + Mockito.anyInt(), Matchers.anyBoolean())). + thenReturn(implementation); + // Now start up the catalogtracker with our doctored Connection. + final CatalogTracker ct = constructAndStartCatalogTracker(connection); + try { + RootLocationEditor.setRootLocation(this.watcher, sn); + ct.setMetaLocation(sn); + Assert.assertFalse(ct.waitForMetaServerConnectionDefault() == null); + } finally { + // Clean out root location or later tests will be confused... they + // presume start fresh in zk. + RootLocationEditor.deleteRootLocation(this.watcher); + } + } finally { + // Clear out our doctored connection or could mess up subsequent tests. + HConnectionManager.deleteConnection(UTIL.getConfiguration(), true); + } + } + + @Test public void testGetMetaServerConnectionFails() throws IOException, InterruptedException, KeeperException { HConnection connection =