assertTrue("Node health script should start", NodeHealthCheckerService
.shouldRun(conf));
}
public void testNodeHealthScript() throws Exception {
TaskTrackerHealthStatus healthStatus = new TaskTrackerHealthStatus();
String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
String normalScript = "echo \"I am all fine\"";
String timeOutScript = "sleep 4\n echo\"I am fine\"";
Configuration conf = getConfForNodeHealthScript();
conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
NodeHealthCheckerService nodeHealthChecker = new NodeHealthCheckerService(
conf);
TimerTask timer = nodeHealthChecker.getTimer();
writeNodeHealthScriptFile(normalScript, true);
timer.run();
nodeHealthChecker.setHealthStatus(healthStatus);
LOG.info("Checking initial healthy condition");
// Check proper report conditions.
assertTrue("Node health status reported unhealthy", healthStatus
.isNodeHealthy());
assertTrue("Node health status reported unhealthy", healthStatus
.getHealthReport().isEmpty());
// write out error file.
// Healthy to unhealthy transition
writeNodeHealthScriptFile(errorScript, true);
// Run timer
timer.run();
// update health status
nodeHealthChecker.setHealthStatus(healthStatus);
LOG.info("Checking Healthy--->Unhealthy");
assertFalse("Node health status reported healthy", healthStatus
.isNodeHealthy());
assertFalse("Node health status reported healthy", healthStatus
.getHealthReport().isEmpty());
// Check unhealthy to healthy transitions.
writeNodeHealthScriptFile(normalScript, true);
timer.run();
nodeHealthChecker.setHealthStatus(healthStatus);
LOG.info("Checking UnHealthy--->healthy");
// Check proper report conditions.
assertTrue("Node health status reported unhealthy", healthStatus
.isNodeHealthy());
assertTrue("Node health status reported unhealthy", healthStatus
.getHealthReport().isEmpty());
// Healthy to timeout transition.
writeNodeHealthScriptFile(timeOutScript, true);
timer.run();
nodeHealthChecker.setHealthStatus(healthStatus);
LOG.info("Checking Healthy--->timeout");
assertFalse("Node health status reported healthy even after timeout",
healthStatus.isNodeHealthy());
assertEquals("Node time out message not propogated", healthStatus
.getHealthReport(),
NodeHealthCheckerService.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG);
}