From 8c3a7e4a7dc3a575720b6e812fc91b38cdd211c5 Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Tue, 2 Jul 2013 18:33:09 +0000 Subject: [PATCH] HBASE-8703 [WINDOWS] Timed-out processes exit with non-zero code causing HealthChecker to report incorrectly. ADDENDUM patch to fix flaky test git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1499047 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/TestNodeHealthCheckChore.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java index 9f36e7e5d50..17036bec5d1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; +import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -55,32 +56,38 @@ public class TestNodeHealthCheckChore { } @Test - public void testHealthChecker() throws Exception { + public void testHealthCheckerSuccess() throws Exception { + String normalScript = "echo \"I am all fine\""; + healthCheckerTest(normalScript, HealthCheckerExitStatus.SUCCESS); + } + + @Test + public void testHealthCheckerFail() throws Exception { + String errorScript = "echo ERROR" + eol + "echo \"Node not healthy\""; + healthCheckerTest(errorScript, HealthCheckerExitStatus.FAILED); + } + + @Test + public void testHealthCheckerTimeout() throws Exception { + String timeOutScript = "sleep 4" + eol + "echo \"I am fine\""; + healthCheckerTest(timeOutScript, HealthCheckerExitStatus.TIMED_OUT); + } + + public void healthCheckerTest(String script, HealthCheckerExitStatus expectedStatus) + throws Exception { Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 2000); + HealthChecker checker = new HealthChecker(); checker.init(location, timeout); - String normalScript = "echo \"I am all fine\""; - createScript(normalScript, true); + createScript(script, true); HealthReport report = checker.checkHealth(); + assertEquals(expectedStatus, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); - assertEquals(HealthCheckerExitStatus.SUCCESS, report.getStatus()); - - String errorScript = "echo ERROR" + eol + "echo \"Server not healthy\""; - createScript(errorScript, true); - report = checker.checkHealth(); - LOG.info("Health Status:" + report.getHealthReport()); - assertEquals(HealthCheckerExitStatus.FAILED, report.getStatus()); - - String timeOutScript = "sleep 4" + eol + "echo \"I am fine\""; - createScript(timeOutScript, true); - report = checker.checkHealth(); - LOG.info("Health Status:" + report.getHealthReport()); - assertEquals(HealthCheckerExitStatus.TIMED_OUT, report.getStatus()); this.healthScriptFile.delete(); } @@ -130,7 +137,8 @@ public class TestNodeHealthCheckChore { throw new IOException("Failed mkdirs " + tempDir); } } - String scriptName = Shell.WINDOWS ? "HealthScript.cmd" : "HealthScript.sh"; + String scriptName = "HealthScript" + UUID.randomUUID().toString() + + (Shell.WINDOWS ? ".cmd" : ".sh"); healthScriptFile = new File(tempDir.getAbsolutePath(), scriptName); conf.set(HConstants.HEALTH_SCRIPT_LOC, healthScriptFile.getAbsolutePath()); conf.setLong(HConstants.HEALTH_FAILURE_THRESHOLD, 3);