From 8f201a070e8a27f68d409ee27e4c8ca6d45c16f8 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Thu, 6 Jun 2013 04:02:24 +0000 Subject: [PATCH] HADOOP-9526. TestShellCommandFencer and TestShell fail on Windows. Contributed by Arpit Agarwal. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1490120 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../hadoop/ha/TestShellCommandFencer.java | 29 ++++++++++++++----- .../org/apache/hadoop/util/TestShell.java | 7 ++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 1f6a7e7907..c7554d4d7a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -746,6 +746,9 @@ Release 2.1.0-beta - UNRELEASED HADOOP-9131. Turn off TestLocalFileSystem#testListStatusWithColons on Windows. (Chris Nauroth via suresh) + HADOOP-9526. TestShellCommandFencer and TestShell fail on Windows. + (Arpit Agarwal via suresh) + Release 2.0.5-alpha - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java index 491e149dba..8a652b5b95 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java @@ -23,6 +23,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; +import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.StringUtils; import org.junit.Before; import org.junit.BeforeClass; @@ -110,9 +111,9 @@ public void testStdoutLogging() { */ @Test public void testStderrLogging() { - assertTrue(fencer.tryFence(TEST_TARGET, "echo hello >&2")); + assertTrue(fencer.tryFence(TEST_TARGET, "echo hello>&2")); Mockito.verify(ShellCommandFencer.LOG).warn( - Mockito.endsWith("echo hello >&2: hello")); + Mockito.endsWith("echo hello>&2: hello")); } /** @@ -121,9 +122,15 @@ public void testStderrLogging() { */ @Test public void testConfAsEnvironment() { - fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests"); - Mockito.verify(ShellCommandFencer.LOG).info( - Mockito.endsWith("echo $in...ing_tests: yessir")); + if (!Shell.WINDOWS) { + fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests"); + Mockito.verify(ShellCommandFencer.LOG).info( + Mockito.endsWith("echo $in...ing_tests: yessir")); + } else { + fencer.tryFence(TEST_TARGET, "echo %in_fencing_tests%"); + Mockito.verify(ShellCommandFencer.LOG).info( + Mockito.endsWith("echo %in...ng_tests%: yessir")); + } } /** @@ -132,9 +139,15 @@ public void testConfAsEnvironment() { */ @Test public void testTargetAsEnvironment() { - fencer.tryFence(TEST_TARGET, "echo $target_host $target_port $target_address"); - Mockito.verify(ShellCommandFencer.LOG).info( - Mockito.endsWith("echo $ta...t_address: host 1234 host:1234")); + if (!Shell.WINDOWS) { + fencer.tryFence(TEST_TARGET, "echo $target_host $target_port $target_address"); + Mockito.verify(ShellCommandFencer.LOG).info( + Mockito.endsWith("echo $ta...t_address: host 1234 host:1234")); + } else { + fencer.tryFence(TEST_TARGET, "echo %target_host% %target_port% %target_address%"); + Mockito.verify(ShellCommandFencer.LOG).info( + Mockito.endsWith("echo %ta..._address%: host 1234 host:1234")); + } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java index 76b0d54933..d9dc9ef5fe 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java @@ -41,7 +41,12 @@ private Command(long interval) { @Override protected String[] getExecString() { - return new String[] {"echo", "hello"}; + // There is no /bin/echo equivalent on Windows so just launch it as a + // shell built-in. + // + return Shell.WINDOWS ? + (new String[] {"cmd.exe", "/c", "echo", "hello"}) : + (new String[] {"echo", "hello"}); } @Override