Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/testMRConf.xml URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/testMRConf.xml?rev=771635&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/testMRConf.xml (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/testMRConf.xml Tue May 5 09:16:51 2009 @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-stylesheet type="text/xsl" href="testConf.xsl"?> + +<configuration> + <!-- Normal mode is test. To run just the commands and dump the output + to the log, set it to nocompare --> + <mode>test</mode> + + <!-- Comparator types: + ExactComparator + SubstringComparator + RegexpComparator + TokenComparator + --> + <tests> + <test> <!--Tested --> + <description>refreshServiceAcl: refreshing security authorization policy for jobtracker</description> + <test-commands> + <mr-admin-command>-jt JOBTRACKER -refreshServiceAcl </mr-admin-command> + </test-commands> + <cleanup-commands> + <!-- No cleanup --> + </cleanup-commands> + <comparators> + <comparator> + <type>ExactComparator</type> + <expected-output></expected-output> + </comparator> + </comparators> + </test> + + <test> <!--Tested --> + <description>refreshServiceAcl: verifying error message while refreshing security authorization policy for jobtracker</description> + <test-commands> + <!-- hadoop-policy.xml for tests has + security.refresh.policy.protocol.acl = ${user.name} --> + <mr-admin-command>-jt JOBTRACKER -Dhadoop.job.ugi=blah,blah -refreshServiceAcl </mr-admin-command> + </test-commands> + <cleanup-commands> + <!-- No cleanup --> + </cleanup-commands> + <comparators> + <comparator> + <type>SubstringComparator</type> + <expected-output>access denied</expected-output> + </comparator> + </comparators> + </test> + </tests> +</configuration>
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java?rev=771635&r1=771634&r2=771635&view=diff ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java (original) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java Tue May 5 09:16:51 2009 @@ -24,24 +24,13 @@ import java.util.StringTokenizer; import org.apache.hadoop.cli.TestCLI; -import org.apache.hadoop.cli.util.CLITestData.TestCmd; -import org.apache.hadoop.cli.util.CLITestData.TestCmd.CommandType; -import org.apache.hadoop.fs.FsShell; -import org.apache.hadoop.hdfs.tools.DFSAdmin; -import org.apache.hadoop.mapred.tools.MRAdmin; -import org.apache.hadoop.util.ToolRunner; /** * - * This class executed commands and captures the output + * This class execute commands and captures the output */ -public class CommandExecutor { - private static String commandOutput = null; - private static int exitCode = 0; - private static Exception lastException = null; - private static String cmdExecuted = null; - - private static String[] getCommandAsArgs(final String cmd, final String masterKey, +public abstract class CommandExecutor { + protected String[] getCommandAsArgs(final String cmd, final String masterKey, final String master) { StringTokenizer tokenizer = new StringTokenizer(cmd, " "); String[] args = new String[tokenizer.countTokens()]; @@ -62,84 +51,10 @@ return args; } - public static int executeCommand(final TestCmd cmd, - final String namenode, final String jobtracker) - throws Exception { - switch(cmd.getType()) { - case DFSADMIN: - return CommandExecutor.executeDFSAdminCommand(cmd.getCmd(), namenode); - case MRADMIN: - return CommandExecutor.executeMRAdminCommand(cmd.getCmd(), jobtracker); - case FS: - return CommandExecutor.executeFSCommand(cmd.getCmd(), namenode); - default: - throw new Exception("Unknow type of Test command:"+ cmd.getType()); - } - } - - public static int executeDFSAdminCommand(final String cmd, final String namenode) { - exitCode = 0; - - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - PrintStream origOut = System.out; - PrintStream origErr = System.err; - - System.setOut(new PrintStream(bao)); - System.setErr(new PrintStream(bao)); - - DFSAdmin shell = new DFSAdmin(); - String[] args = getCommandAsArgs(cmd, "NAMENODE", namenode); - cmdExecuted = cmd; - - try { - ToolRunner.run(shell, args); - } catch (Exception e) { - e.printStackTrace(); - lastException = e; - exitCode = -1; - } finally { - System.setOut(origOut); - System.setErr(origErr); - } - - commandOutput = bao.toString(); - - return exitCode; - } - - public static int executeMRAdminCommand(final String cmd, - final String jobtracker) { - exitCode = 0; - - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - PrintStream origOut = System.out; - PrintStream origErr = System.err; - - System.setOut(new PrintStream(bao)); - System.setErr(new PrintStream(bao)); - - MRAdmin mradmin = new MRAdmin(); - String[] args = getCommandAsArgs(cmd, "JOBTRACKER", jobtracker); - cmdExecuted = cmd; - - try { - ToolRunner.run(mradmin, args); - } catch (Exception e) { - e.printStackTrace(); - lastException = e; - exitCode = -1; - } finally { - System.setOut(origOut); - System.setErr(origErr); - } + public Result executeCommand(final String cmd) throws Exception { + int exitCode = 0; + Exception lastException = null; - commandOutput = bao.toString(); - - return exitCode; - } - - public static int executeFSCommand(final String cmd, final String namenode) { - exitCode = 0; ByteArrayOutputStream bao = new ByteArrayOutputStream(); PrintStream origOut = System.out; @@ -148,12 +63,8 @@ System.setOut(new PrintStream(bao)); System.setErr(new PrintStream(bao)); - FsShell shell = new FsShell(); - String[] args = getCommandAsArgs(cmd, "NAMENODE", namenode); - cmdExecuted = cmd; - try { - ToolRunner.run(shell, args); + execute(cmd); } catch (Exception e) { e.printStackTrace(); lastException = e; @@ -162,25 +73,39 @@ System.setOut(origOut); System.setErr(origErr); } - - commandOutput = bao.toString(); - - return exitCode; + return new Result(bao.toString(), exitCode, lastException, cmd); } - public static String getLastCommandOutput() { - return commandOutput; - } + protected abstract void execute(final String cmd) throws Exception; + + public static class Result { + final String commandOutput; + final int exitCode; + final Exception exception; + final String cmdExecuted; + public Result(String commandOutput, int exitCode, Exception exception, + String cmdExecuted) { + this.commandOutput = commandOutput; + this.exitCode = exitCode; + this.exception = exception; + this.cmdExecuted = cmdExecuted; + } + + public String getCommandOutput() { + return commandOutput; + } - public static int getLastExitCode() { - return exitCode; - } + public int getExitCode() { + return exitCode; + } - public static Exception getLastException() { - return lastException; - } + public Exception getException() { + return exception; + } - public static String getLastCommand() { - return cmdExecuted; + public String getCommand() { + return cmdExecuted; + } } + } Modified: hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java?rev=771635&r1=771634&r2=771635&view=diff ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java (original) +++ hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java Tue May 5 09:16:51 2009 @@ -33,6 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.cli.TestHDFSCLI; import org.apache.hadoop.cli.util.CommandExecutor; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; @@ -328,7 +329,7 @@ * Test dfsadmin -restoreFailedStorage command * @throws Exception */ - public void testDfsAdminCmd() throws IOException { + public void testDfsAdminCmd() throws Exception { int numDatanodes = 2; @@ -347,25 +348,26 @@ String cmd = "-fs NAMENODE -restoreFailedStorage false"; String namenode = config.get("fs.default.name", "file:///"); - CommandExecutor.executeDFSAdminCommand(cmd, namenode); + CommandExecutor executor = new TestHDFSCLI.DFSAdminCmdExecutor(namenode); + executor.executeCommand(cmd); restore = fsi.getRestoreFailedStorage(); LOG.info("After set true call restore is " + restore); assertEquals(restore, false); // run one more time - to set it to true again cmd = "-fs NAMENODE -restoreFailedStorage true"; - CommandExecutor.executeDFSAdminCommand(cmd, namenode); + executor.executeCommand(cmd); restore = fsi.getRestoreFailedStorage(); LOG.info("After set false call restore is " + restore); assertEquals(restore, true); // run one more time - no change in value cmd = "-fs NAMENODE -restoreFailedStorage check"; - CommandExecutor.executeDFSAdminCommand(cmd, namenode); + CommandExecutor.Result cmdResult = executor.executeCommand(cmd); restore = fsi.getRestoreFailedStorage(); LOG.info("After check call restore is " + restore); assertEquals(restore, true); - String commandOutput = CommandExecutor.getLastCommandOutput(); + String commandOutput = cmdResult.getCommandOutput(); commandOutput.trim(); assertTrue(commandOutput.contains("restoreFailedStorage is set to true"));
