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
This commit is contained in:
Suresh Srinivas 2013-06-06 04:02:24 +00:00
parent cda2564e1c
commit 8f201a070e
3 changed files with 30 additions and 9 deletions

View File

@ -746,6 +746,9 @@ Release 2.1.0-beta - UNRELEASED
HADOOP-9131. Turn off TestLocalFileSystem#testListStatusWithColons on HADOOP-9131. Turn off TestLocalFileSystem#testListStatusWithColons on
Windows. (Chris Nauroth via suresh) Windows. (Chris Nauroth via suresh)
HADOOP-9526. TestShellCommandFencer and TestShell fail on Windows.
(Arpit Agarwal via suresh)
Release 2.0.5-alpha - UNRELEASED Release 2.0.5-alpha - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.util.Shell;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -110,9 +111,9 @@ public class TestShellCommandFencer {
*/ */
@Test @Test
public void testStderrLogging() { 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.verify(ShellCommandFencer.LOG).warn(
Mockito.endsWith("echo hello >&2: hello")); Mockito.endsWith("echo hello>&2: hello"));
} }
/** /**
@ -121,9 +122,15 @@ public class TestShellCommandFencer {
*/ */
@Test @Test
public void testConfAsEnvironment() { public void testConfAsEnvironment() {
if (!Shell.WINDOWS) {
fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests"); fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests");
Mockito.verify(ShellCommandFencer.LOG).info( Mockito.verify(ShellCommandFencer.LOG).info(
Mockito.endsWith("echo $in...ing_tests: yessir")); 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 class TestShellCommandFencer {
*/ */
@Test @Test
public void testTargetAsEnvironment() { public void testTargetAsEnvironment() {
if (!Shell.WINDOWS) {
fencer.tryFence(TEST_TARGET, "echo $target_host $target_port $target_address"); fencer.tryFence(TEST_TARGET, "echo $target_host $target_port $target_address");
Mockito.verify(ShellCommandFencer.LOG).info( Mockito.verify(ShellCommandFencer.LOG).info(
Mockito.endsWith("echo $ta...t_address: host 1234 host:1234")); 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"));
}
} }

View File

@ -41,7 +41,12 @@ public class TestShell extends TestCase {
@Override @Override
protected String[] getExecString() { 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 @Override