use of org.apache.hadoop.yarn.server.api.records.NodeHealthStatus in project hadoop by apache.
the class TestNodeHealthService method testNodeHealthService.
@Test
public void testNodeHealthService() throws Exception {
RecordFactory factory = RecordFactoryProvider.getRecordFactory(null);
NodeHealthStatus healthStatus = factory.newRecordInstance(NodeHealthStatus.class);
Configuration conf = getConfForNodeHealthScript();
conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
conf.addResource(nodeHealthConfigFile.getName());
writeNodeHealthScriptFile("", true);
LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
NodeHealthScriptRunner nodeHealthScriptRunner = spy(NodeManager.getNodeHealthScriptRunner(conf));
NodeHealthCheckerService nodeHealthChecker = new NodeHealthCheckerService(nodeHealthScriptRunner, dirsHandler);
nodeHealthChecker.init(conf);
doReturn(true).when(nodeHealthScriptRunner).isHealthy();
doReturn("").when(nodeHealthScriptRunner).getHealthReport();
setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(), nodeHealthChecker.getHealthReport(), nodeHealthChecker.getLastHealthReportTime());
LOG.info("Checking initial healthy condition");
// Check proper report conditions.
Assert.assertTrue("Node health status reported unhealthy", healthStatus.getIsNodeHealthy());
Assert.assertTrue("Node health status reported unhealthy", healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));
doReturn(false).when(nodeHealthScriptRunner).isHealthy();
// update health status
setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(), nodeHealthChecker.getHealthReport(), nodeHealthChecker.getLastHealthReportTime());
LOG.info("Checking Healthy--->Unhealthy");
Assert.assertFalse("Node health status reported healthy", healthStatus.getIsNodeHealthy());
Assert.assertTrue("Node health status reported healthy", healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));
doReturn(true).when(nodeHealthScriptRunner).isHealthy();
setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(), nodeHealthChecker.getHealthReport(), nodeHealthChecker.getLastHealthReportTime());
LOG.info("Checking UnHealthy--->healthy");
// Check proper report conditions.
Assert.assertTrue("Node health status reported unhealthy", healthStatus.getIsNodeHealthy());
Assert.assertTrue("Node health status reported unhealthy", healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));
// Healthy to timeout transition.
doReturn(false).when(nodeHealthScriptRunner).isHealthy();
doReturn(NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG).when(nodeHealthScriptRunner).getHealthReport();
setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(), nodeHealthChecker.getHealthReport(), nodeHealthChecker.getLastHealthReportTime());
LOG.info("Checking Healthy--->timeout");
Assert.assertFalse("Node health status reported healthy even after timeout", healthStatus.getIsNodeHealthy());
Assert.assertTrue("Node script time out message not propagated", healthStatus.getHealthReport().equals(NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG + NodeHealthCheckerService.SEPARATOR + nodeHealthChecker.getDiskHandler().getDisksHealthReport(false)));
}
Aggregations