use of org.apache.hadoop.ha.HealthCheckFailedException in project hadoop by apache.
the class TestDFSHAAdmin method testCheckHealth.
@Test
public void testCheckHealth() throws Exception {
assertEquals(0, runTool("-checkHealth", "nn1"));
Mockito.verify(mockProtocol).monitorHealth();
Mockito.doThrow(new HealthCheckFailedException("fake health check failure")).when(mockProtocol).monitorHealth();
assertEquals(-1, runTool("-checkHealth", "nn1"));
assertOutputContains("Health check failed: fake health check failure");
}
use of org.apache.hadoop.ha.HealthCheckFailedException in project hadoop by apache.
the class TestNNHealthCheck method doNNHealthCheckTest.
private void doNNHealthCheckTest() throws IOException {
MockNameNodeResourceChecker mockResourceChecker = new MockNameNodeResourceChecker(conf);
cluster.getNameNode(0).getNamesystem().setNNResourceChecker(mockResourceChecker);
NNHAServiceTarget haTarget = new NNHAServiceTarget(conf, DFSUtil.getNamenodeNameServiceId(conf), "nn1");
final String expectedTargetString;
if (conf.get(DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY + "." + DFSUtil.getNamenodeNameServiceId(conf) + ".nn1") != null) {
expectedTargetString = haTarget.getHealthMonitorAddress().toString();
} else {
expectedTargetString = haTarget.getAddress().toString();
}
assertTrue("Expected haTarget " + haTarget + " containing " + expectedTargetString, haTarget.toString().contains(expectedTargetString));
HAServiceProtocol rpc = haTarget.getHealthMonitorProxy(conf, conf.getInt(HA_HM_RPC_TIMEOUT_KEY, HA_HM_RPC_TIMEOUT_DEFAULT));
// Should not throw error, which indicates healthy.
rpc.monitorHealth();
mockResourceChecker.setResourcesAvailable(false);
try {
// Should throw error - NN is unhealthy.
rpc.monitorHealth();
fail("Should not have succeeded in calling monitorHealth");
} catch (HealthCheckFailedException hcfe) {
GenericTestUtils.assertExceptionContains("The NameNode has no resources available", hcfe);
} catch (RemoteException re) {
GenericTestUtils.assertExceptionContains("The NameNode has no resources available", re.unwrapRemoteException(HealthCheckFailedException.class));
}
}
Aggregations