Index: src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java (revision 1489690) +++ src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java (working copy) @@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.SmallTests; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.HealthChecker.HealthCheckerExitStatus; +import org.apache.hadoop.util.Shell; import org.junit.After; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -44,8 +45,8 @@ private static final Log LOG = LogFactory.getLog(TestNodeHealthCheckChore.class); private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private File healthScriptFile; + private String eol = System.getProperty("line.separator"); - @After public void cleanUp() throws IOException { UTIL.cleanupTestDir(); @@ -56,7 +57,7 @@ Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); - long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 200); + long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 2000); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); @@ -68,13 +69,13 @@ LOG.info("Health Status:" + checker); - String errorScript = "echo ERROR\n echo \"Node not healthy\""; + String errorScript = "echo ERROR" + eol + "echo \"Node not healthy\""; createScript(errorScript, true); report = checker.checkHealth(); assertEquals(HealthCheckerExitStatus.FAILED, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); - String timeOutScript = "sleep 4\n echo\"I am fine\""; + String timeOutScript = "sleep 4" + eol + "echo \"I am fine\""; createScript(timeOutScript, true); report = checker.checkHealth(); assertEquals(HealthCheckerExitStatus.TIMED_OUT, report.getStatus()); @@ -87,7 +88,7 @@ public void testNodeHealthChore() throws Exception{ Stoppable stop = new StoppableImplementation(); Configuration conf = getConfForNodeHealthScript(); - String errorScript = "echo ERROR\n echo \"Node not healthy\""; + String errorScript = "echo ERROR" + eol + " echo \"Node not healthy\""; createScript(errorScript, true); HealthCheckChore rsChore = new HealthCheckChore(100, stop, conf); //Default threshold is three. @@ -112,11 +113,12 @@ Configuration conf = UTIL.getConfiguration(); File tempDir = new File(UTIL.getDataTestDir().toString()); tempDir.mkdirs(); - healthScriptFile = new File(tempDir.getAbsolutePath(), "HealthScript.sh"); + String scriptName = Shell.WINDOWS ? "HealthScript.cmd" : "HealthScript.sh"; + healthScriptFile = new File(tempDir.getAbsolutePath(), scriptName); conf.set(HConstants.HEALTH_SCRIPT_LOC, healthScriptFile.getAbsolutePath()); conf.setLong(HConstants.HEALTH_FAILURE_THRESHOLD, 3); - conf.setLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 200); + conf.setLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 2000); return conf; } Index: src/main/java/org/apache/hadoop/hbase/HealthChecker.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HealthChecker.java (revision 1489690) +++ src/main/java/org/apache/hadoop/hbase/HealthChecker.java (working copy) @@ -73,17 +73,16 @@ shexec.execute(); } catch (ExitCodeException e) { // ignore the exit code of the script - LOG.warn("Caught exception : " + e); + LOG.warn("Caught exception : " + e + ",exit code:" + e.getExitCode()); status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; } catch (IOException e) { LOG.warn("Caught exception : " + e); - if (!shexec.isTimedOut()) { - status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; - exceptionStackTrace = org.apache.hadoop.util.StringUtils.stringifyException(e); - } else { + status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; + exceptionStackTrace = org.apache.hadoop.util.StringUtils.stringifyException(e); + } finally { + if (shexec.isTimedOut()) { status = HealthCheckerExitStatus.TIMED_OUT; } - } finally { if (status == HealthCheckerExitStatus.SUCCESS) { if (hasErrors(shexec.getOutput())) { status = HealthCheckerExitStatus.FAILED;