Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/testConf.xsl URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/testConf.xsl?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/testConf.xsl (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/testConf.xsl Tue Jul 1 14:08:24 2008 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:template match="/"> + <html> + <body> + <h2>Hadoop DFS command-line tests</h2> + <table border="1"> + <tr bgcolor="#9acd32"> + <th align="left">ID</th> + <th align="left">Command</th> + <th align="left">Description</th> + </tr> + <xsl:for-each select="configuration/tests/test"> + <!-- <xsl:sort select="description"/> --> + <tr> + <td><xsl:value-of select="position()"/></td> + <td><xsl:value-of select="substring-before(description,':')"/></td> + <td><xsl:value-of select="substring-after(description,':')"/></td> + </tr> + </xsl:for-each> + </table> + </body> + </html> + </xsl:template> + +</xsl:stylesheet>
Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +import java.util.ArrayList; + +/** + * + * Class to store CLI Test Data + */ +public class CLITestData { + private String testDesc = null; + private ArrayList<String> testCommands = null; + private ArrayList<String> cleanupCommands = null; + private ArrayList<ComparatorData> comparatorData = null; + private boolean testResult = false; + + public CLITestData() { + + } + + /** + * @return the testDesc + */ + public String getTestDesc() { + return testDesc; + } + + /** + * @param testDesc the testDesc to set + */ + public void setTestDesc(String testDesc) { + this.testDesc = testDesc; + } + + /** + * @return the testCommands + */ + public ArrayList<String> getTestCommands() { + return testCommands; + } + + /** + * @param testCommands the testCommands to set + */ + public void setTestCommands(ArrayList<String> testCommands) { + this.testCommands = testCommands; + } + + /** + * @return the comparatorData + */ + public ArrayList<ComparatorData> getComparatorData() { + return comparatorData; + } + + /** + * @param comparatorData the comparatorData to set + */ + public void setComparatorData(ArrayList<ComparatorData> comparatorData) { + this.comparatorData = comparatorData; + } + + /** + * @return the testResult + */ + public boolean getTestResult() { + return testResult; + } + + /** + * @param testResult the testResult to set + */ + public void setTestResult(boolean testResult) { + this.testResult = testResult; + } + + /** + * @return the cleanupCommands + */ + public ArrayList<String> getCleanupCommands() { + return cleanupCommands; + } + + /** + * @param cleanupCommands the cleanupCommands to set + */ + public void setCleanupCommands(ArrayList<String> cleanupCommands) { + this.cleanupCommands = cleanupCommands; + } +} Added: 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=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,109 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.io.PrintStream; +import java.util.StringTokenizer; + +import org.apache.hadoop.fs.FsShell; +import org.apache.hadoop.util.ToolRunner; +import org.apache.hadoop.conf.Configuration; + + +/** + * + * This class executed 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[] getFSCommandAsArgs(final String cmd, + final String namenode) { + StringTokenizer tokenizer = new StringTokenizer(cmd, " "); + String[] args = new String[tokenizer.countTokens()]; + + int i = 0; + while (tokenizer.hasMoreTokens()) { + args[i] = tokenizer.nextToken(); + + args[i] = args[i].replaceAll("NAMENODE", namenode); + args[i] = args[i].replaceAll("CLITEST_DATA", + new File(System.getProperty("test.cache.data")). + toURI().toString().replace(' ', '+')); + args[i] = args[i].replaceAll("USERNAME", System.getProperty("user.name")); + + i++; + } + + return args; + } + + public static int executeFSCommand(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)); + + FsShell shell = new FsShell(); + String[] args = getFSCommandAsArgs(cmd, 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 String getLastCommandOutput() { + return commandOutput; + } + + public static int getLastExitCode() { + return exitCode; + } + + public static Exception getLastException() { + return lastException; + } + + public static String getLastCommand() { + return cmdExecuted; + } +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorBase.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorBase.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorBase.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorBase.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +/** + * + * Comparator interface. To define a new comparator, implement the compare + * method + */ +public abstract class ComparatorBase { + public ComparatorBase() { + + } + + /** + * Compare method for the comparator class. + * @param actual output. can be null + * @param expected output. can be null + * @return true if expected output compares with the actual output, else + * return false. If actual or expected is null, return false + */ + public abstract boolean compare(String actual, String expected); +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorData.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorData.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorData.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ComparatorData.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,108 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +import java.util.Vector; + +/** + * + * Class to store CLI Test Comparators Data + */ +public class ComparatorData { + private String expectedOutput = null; + private String actualOutput = null; + private boolean testResult = false; + private int exitCode = 0; + private String comparatorType = null; + + public ComparatorData() { + + } + + /** + * @return the expectedOutput + */ + public String getExpectedOutput() { + return expectedOutput; + } + + /** + * @param expectedOutput the expectedOutput to set + */ + public void setExpectedOutput(String expectedOutput) { + this.expectedOutput = expectedOutput; + } + + /** + * @return the actualOutput + */ + public String getActualOutput() { + return actualOutput; + } + + /** + * @param actualOutput the actualOutput to set + */ + public void setActualOutput(String actualOutput) { + this.actualOutput = actualOutput; + } + + /** + * @return the testResult + */ + public boolean getTestResult() { + return testResult; + } + + /** + * @param testResult the testResult to set + */ + public void setTestResult(boolean testResult) { + this.testResult = testResult; + } + + /** + * @return the exitCode + */ + public int getExitCode() { + return exitCode; + } + + /** + * @param exitCode the exitCode to set + */ + public void setExitCode(int exitCode) { + this.exitCode = exitCode; + } + + /** + * @return the comparatorType + */ + public String getComparatorType() { + return comparatorType; + } + + /** + * @param comparatorType the comparatorType to set + */ + public void setComparatorType(String comparatorType) { + this.comparatorType = comparatorType; + } + +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ExactComparator.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ExactComparator.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ExactComparator.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/ExactComparator.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +/** + * Comparator for the Command line tests. + * + * This comparator compares the actual to the expected and + * returns true only if they are the same + * + */ +public class ExactComparator extends ComparatorBase { + + @Override + public boolean compare(String actual, String expected) { + return actual.equals(expected); + } +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/RegexpComparator.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/RegexpComparator.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/RegexpComparator.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/RegexpComparator.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Comparator for the Command line tests. + * + * This comparator searches for the regular expression specified in 'expected' + * in the string 'actual' and returns true if the regular expression match is + * done + * + */ +public class RegexpComparator extends ComparatorBase { + + @Override + public boolean compare(String actual, String expected) { + boolean success = false; + Pattern p = Pattern.compile(expected); + + StringTokenizer tokenizer = new StringTokenizer(actual, "\n\r"); + while (tokenizer.hasMoreTokens() && !success) { + String actualToken = tokenizer.nextToken(); + Matcher m = p.matcher(actualToken); + success = m.matches(); + } + + return success; + } + +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/SubstringComparator.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/SubstringComparator.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/SubstringComparator.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/SubstringComparator.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +public class SubstringComparator extends ComparatorBase { + + @Override + public boolean compare(String actual, String expected) { + int compareOutput = actual.indexOf(expected); + if (compareOutput == -1) { + return false; + } + + return true; + } + +} Added: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/TokenComparator.java URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/TokenComparator.java?rev=673209&view=auto ============================================================================== --- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/TokenComparator.java (added) +++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/TokenComparator.java Tue Jul 1 14:08:24 2008 @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.cli.util; + +import java.util.StringTokenizer; + +/** + * Comparator for the Command line tests. + * + * This comparator compares each token in the expected output and returns true + * if all tokens are in the actual output + * + */ +public class TokenComparator extends ComparatorBase { + + @Override + public boolean compare(String actual, String expected) { + boolean compareOutput = true; + + StringTokenizer tokenizer = new StringTokenizer(expected, ",\n\r"); + + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + if (actual.indexOf(token) != -1) { + compareOutput &= true; + } else { + compareOutput &= false; + } + } + + return compareOutput; + } +}
