Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 84787 invoked from network); 16 Apr 2011 00:24:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Apr 2011 00:24:12 -0000 Received: (qmail 3343 invoked by uid 500); 16 Apr 2011 00:24:12 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 3312 invoked by uid 500); 16 Apr 2011 00:24:12 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 3305 invoked by uid 99); 16 Apr 2011 00:24:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2011 00:24:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2011 00:24:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E36C7238890A; Sat, 16 Apr 2011 00:23:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1092847 - in /hadoop/common/trunk: CHANGES.txt src/test/core/org/apache/hadoop/cli/CLITestHelper.java src/test/core/org/apache/hadoop/cli/TestCLI.java src/test/core/org/apache/hadoop/cli/util/CLITestData.java Date: Sat, 16 Apr 2011 00:23:46 -0000 To: common-commits@hadoop.apache.org From: cos@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110416002346.E36C7238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cos Date: Sat Apr 16 00:23:46 2011 New Revision: 1092847 URL: http://svn.apache.org/viewvc?rev=1092847&view=rev Log: HADOOP-7014. Generalize CLITest structure and interfaces to facilitate upstream adoption (e.g. for web testing). Contributed by Konstantin Boudnik Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/CLITestHelper.java hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/TestCLI.java hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/util/CLITestData.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1092847&r1=1092846&r2=1092847&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Sat Apr 16 00:23:46 2011 @@ -90,6 +90,9 @@ Trunk (unreleased changes) HADOOP-7224. Add CommandFactory to shell. (Daryn Sharp via szetszwo) + HADOOP-7014. Generalize CLITest structure and interfaces to facilitate + upstream adoption (e.g. for web testing). (cos) + OPTIMIZATIONS BUG FIXES Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/CLITestHelper.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/CLITestHelper.java?rev=1092847&r1=1092846&r2=1092847&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/CLITestHelper.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/CLITestHelper.java Sat Apr 16 00:23:46 2011 @@ -20,16 +20,12 @@ package org.apache.hadoop.cli; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.cli.util.CLITestData; -import org.apache.hadoop.cli.util.CLITestData.TestCmd; -import org.apache.hadoop.cli.util.CLITestData.TestCmd.CommandType; -import org.apache.hadoop.cli.util.CommandExecutor; +import org.apache.hadoop.cli.util.*; +import org.apache.hadoop.cli.util.CLITestCmd; +import org.apache.hadoop.cli.util.CLICommand; import org.apache.hadoop.cli.util.CommandExecutor.Result; -import org.apache.hadoop.cli.util.ComparatorBase; -import org.apache.hadoop.cli.util.ComparatorData; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; -import org.apache.hadoop.security.authorize.ServiceAuthorizationManager; import org.apache.hadoop.util.StringUtils; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -72,7 +68,6 @@ public class CLITestHelper { protected Configuration conf = null; protected String clitestDataDir = null; protected String username = null; - /** * Read the test config file - testConfig.xml */ @@ -83,7 +78,7 @@ public class CLITestHelper { testConfigFile = TEST_CACHE_DATA_DIR + File.separator + testConfigFile; try { SAXParser p = (SAXParserFactory.newInstance()).newSAXParser(); - p.parse(testConfigFile, new TestConfigFileParser()); + p.parse(testConfigFile, getConfigParser()); success = true; } catch (Exception e) { LOG.info("File: " + testConfigFile + " not found"); @@ -92,7 +87,19 @@ public class CLITestHelper { assertTrue("Error reading test config file", success); } } - + + /** + * Method decides what is a proper configuration file parser for this type + * of CLI tests. + * Ancestors need to override the implementation if a parser with additional + * features is needed. Also, such ancestor has to provide its own + * TestConfigParser implementation + * @return an instance of TestConfigFileParser class + */ + protected TestConfigFileParser getConfigParser () { + return new TestConfigFileParser(); + } + protected String getTestFile() { return ""; } @@ -151,15 +158,15 @@ public class CLITestHelper { LOG.info(" Test Description: [" + td.getTestDesc() + "]"); LOG.info(""); - ArrayList testCommands = td.getTestCommands(); - for (TestCmd cmd : testCommands) { + ArrayList testCommands = td.getTestCommands(); + for (CLICommand cmd : testCommands) { LOG.info(" Test Commands: [" + expandCommand(cmd.getCmd()) + "]"); } LOG.info(""); - ArrayList cleanupCommands = td.getCleanupCommands(); - for (TestCmd cmd : cleanupCommands) { + ArrayList cleanupCommands = td.getCleanupCommands(); + for (CLICommand cmd : cleanupCommands) { LOG.info(" Cleanup Commands: [" + expandCommand(cmd.getCmd()) + "]"); } @@ -303,12 +310,12 @@ public class CLITestHelper { // Run the tests defined in the testConf.xml config file. for (int index = 0; index < testsFromConfigFile.size(); index++) { - CLITestData testdata = (CLITestData) testsFromConfigFile.get(index); + CLITestData testdata = testsFromConfigFile.get(index); // Execute the test commands - ArrayList testCommands = testdata.getTestCommands(); + ArrayList testCommands = testdata.getTestCommands(); Result cmdResult = null; - for (TestCmd cmd : testCommands) { + for (CLICommand cmd : testCommands) { try { cmdResult = execute(cmd); } catch (Exception e) { @@ -336,8 +343,8 @@ public class CLITestHelper { testdata.setTestResult(overallTCResult); // Execute the cleanup commands - ArrayList cleanupCommands = testdata.getCleanupCommands(); - for (TestCmd cmd : cleanupCommands) { + ArrayList cleanupCommands = testdata.getCleanupCommands(); + for (CLICommand cmd : cleanupCommands) { try { execute(cmd); } catch (Exception e) { @@ -346,9 +353,12 @@ public class CLITestHelper { } } } - - protected CommandExecutor.Result execute(TestCmd cmd) throws Exception { - throw new Exception("Unknow type of Test command:"+ cmd.getType()); + + /** + * this method has to be overridden by an ancestor + */ + protected CommandExecutor.Result execute(CLICommand cmd) throws Exception { + throw new Exception("Unknown type of test command:"+ cmd.getType()); } /* @@ -357,8 +367,8 @@ public class CLITestHelper { class TestConfigFileParser extends DefaultHandler { String charString = null; CLITestData td = null; - ArrayList testCommands = null; - ArrayList cleanupCommands = null; + ArrayList testCommands = null; + ArrayList cleanupCommands = null; @Override public void startDocument() throws SAXException { @@ -373,9 +383,9 @@ public class CLITestHelper { if (qName.equals("test")) { td = new CLITestData(); } else if (qName.equals("test-commands")) { - testCommands = new ArrayList(); + testCommands = new ArrayList(); } else if (qName.equals("cleanup-commands")) { - cleanupCommands = new ArrayList(); + cleanupCommands = new ArrayList(); } else if (qName.equals("comparators")) { testComparators = new ArrayList(); } else if (qName.equals("comparator")) { @@ -385,9 +395,8 @@ public class CLITestHelper { } @Override - public void endElement(String uri, - String localName, - String qName) throws SAXException { + public void endElement(String uri, String localName,String qName) + throws SAXException { if (qName.equals("description")) { td.setTestDesc(charString); } else if (qName.equals("test-commands")) { @@ -398,27 +407,9 @@ public class CLITestHelper { cleanupCommands = null; } else if (qName.equals("command")) { if (testCommands != null) { - testCommands.add(new TestCmd(charString, CommandType.FS)); - } else if (cleanupCommands != null) { - cleanupCommands.add(new TestCmd(charString, CommandType.FS)); - } - } else if (qName.equals("dfs-admin-command")) { - if (testCommands != null) { - testCommands.add(new TestCmd(charString, CommandType.DFSADMIN)); - } else if (cleanupCommands != null) { - cleanupCommands.add(new TestCmd(charString, CommandType.DFSADMIN)); - } - } else if (qName.equals("mr-admin-command")) { - if (testCommands != null) { - testCommands.add(new TestCmd(charString, CommandType.MRADMIN)); - } else if (cleanupCommands != null) { - cleanupCommands.add(new TestCmd(charString, CommandType.MRADMIN)); - } - } else if (qName.equals("archive-command")) { - if (testCommands != null) { - testCommands.add(new TestCmd(charString, CommandType.ARCHIVE)); + testCommands.add(new CLITestCmd(charString, new CLICommandFS())); } else if (cleanupCommands != null) { - cleanupCommands.add(new TestCmd(charString, CommandType.ARCHIVE)); + cleanupCommands.add(new CLITestCmd(charString, new CLICommandFS())); } } else if (qName.equals("comparators")) { td.setComparatorData(testComparators); Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/TestCLI.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/TestCLI.java?rev=1092847&r1=1092846&r2=1092847&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/TestCLI.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/TestCLI.java Sat Apr 16 00:23:46 2011 @@ -18,8 +18,7 @@ package org.apache.hadoop.cli; -import org.apache.hadoop.cli.util.CLITestData; -import org.apache.hadoop.cli.util.CmdFactory; +import org.apache.hadoop.cli.util.CLICommand; import org.apache.hadoop.cli.util.CommandExecutor; import org.junit.After; import org.junit.Before; @@ -42,8 +41,9 @@ public class TestCLI extends CLITestHelp } @Override - protected CommandExecutor.Result execute(CLITestData.TestCmd cmd) throws Exception { - return CmdFactory.getCommandExecutor(cmd, "").executeCommand(cmd.getCmd()); + protected CommandExecutor.Result execute(CLICommand cmd) throws Exception { + return cmd.getExecutor("").executeCommand(cmd.getCmd()); + } @Override Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/util/CLITestData.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/util/CLITestData.java?rev=1092847&r1=1092846&r2=1092847&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/util/CLITestData.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/cli/util/CLITestData.java Sat Apr 16 00:23:46 2011 @@ -26,8 +26,8 @@ import java.util.ArrayList; */ public class CLITestData { private String testDesc = null; - private ArrayList testCommands = null; - private ArrayList cleanupCommands = null; + private ArrayList testCommands = null; + private ArrayList cleanupCommands = null; private ArrayList comparatorData = null; private boolean testResult = false; @@ -36,35 +36,6 @@ public class CLITestData { } /** - * Class to define Test Command. includes type of the command and command itself - * Valid types FS, DFSADMIN, MRADMIN and ARCHIVE. - */ - static public class TestCmd { - public enum CommandType { - FS, - DFSADMIN, - MRADMIN, - ARCHIVE - } - private final CommandType type; - private final String cmd; - - public TestCmd(String str, CommandType type) { - cmd = str; - this.type = type; - } - public CommandType getType() { - return type; - } - public String getCmd() { - return cmd; - } - public String toString() { - return cmd; - } - } - - /** * @return the testDesc */ public String getTestDesc() { @@ -81,14 +52,14 @@ public class CLITestData { /** * @return the testCommands */ - public ArrayList getTestCommands() { + public ArrayList getTestCommands() { return testCommands; } /** * @param testCommands the testCommands to set */ - public void setTestCommands(ArrayList testCommands) { + public void setTestCommands(ArrayList testCommands) { this.testCommands = testCommands; } @@ -123,14 +94,14 @@ public class CLITestData { /** * @return the cleanupCommands */ - public ArrayList getCleanupCommands() { + public ArrayList getCleanupCommands() { return cleanupCommands; } /** * @param cleanupCommands the cleanupCommands to set */ - public void setCleanupCommands(ArrayList cleanupCommands) { + public void setCleanupCommands(ArrayList cleanupCommands) { this.cleanupCommands = cleanupCommands; } }