hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r1094093 - in /hadoop/mapreduce/trunk: ./ src/test/mapred/org/apache/hadoop/cli/ src/test/mapred/org/apache/hadoop/cli/util/
Date Sun, 17 Apr 2011 02:20:07 GMT
Author: cos
Date: Sun Apr 17 02:20:07 2011
New Revision: 1094093

URL: http://svn.apache.org/viewvc?rev=1094093&view=rev
Log:
MAPREDUCE-2202. Generalize CLITest structure and interfaces to facilitate upstream adoption
(e.g. for web or system testing). Contributed by Konstantin Boudnik

Added:
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/CLITestCmdMR.java
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandArchive.java
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandMRAdmin.java
Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/TestMRCLI.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=1094093&r1=1094092&r2=1094093&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Sun Apr 17 02:20:07 2011
@@ -62,6 +62,9 @@ Trunk (unreleased changes)
 
     MAPREDUCE-2367. Allow using a file to exclude certain tests from build.
     (todd)
+
+    MAPREDUCE-2202. Generalize CLITest structure and interfaces to faciliate
+    upstream adoption (e.g. for web or system testing). (cos)
     
   OPTIMIZATIONS
     

Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/CLITestCmdMR.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/CLITestCmdMR.java?rev=1094093&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/CLITestCmdMR.java (added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/CLITestCmdMR.java Sun Apr
17 02:20:07 2011
@@ -0,0 +1,41 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import org.apache.hadoop.cli.util.CLICommandTypes;
+import org.apache.hadoop.cli.util.CLITestCmd;
+import org.apache.hadoop.cli.util.CommandExecutor;
+
+public class CLITestCmdMR extends CLITestCmd {
+  public CLITestCmdMR(String str, CLICommandTypes type) {
+    super(str, type);
+  }
+
+  /**
+   * This is not implemented because HadoopArchive constructor requires JobConf
+   * to create an archive object. Because TestMRCLI uses setup method from
+   * TestHDFSCLI the initialization of executor objects happens before a config
+   * is created and updated. Thus, actual calls to executors happen in the body
+   * of the test method.
+   */
+  @Override
+  public CommandExecutor getExecutor(String tag)
+      throws IllegalArgumentException {
+    throw new IllegalArgumentException("Method isn't supported");
+  }
+}

Modified: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/TestMRCLI.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/TestMRCLI.java?rev=1094093&r1=1094092&r2=1094093&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/TestMRCLI.java (original)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/TestMRCLI.java Sun Apr 17
02:20:07 2011
@@ -18,8 +18,7 @@
 
 package org.apache.hadoop.cli;
 
-import org.apache.hadoop.cli.util.CommandExecutor;
-import org.apache.hadoop.cli.util.CLITestData.TestCmd;
+import org.apache.hadoop.cli.util.*;
 import org.apache.hadoop.cli.util.CommandExecutor.Result;
 import org.apache.hadoop.tools.HadoopArchives;
 import org.apache.hadoop.mapred.JobConf;
@@ -29,51 +28,59 @@ import org.apache.hadoop.mapreduce.serve
 import org.apache.hadoop.security.authorize.HadoopPolicyProvider;
 import org.apache.hadoop.security.authorize.PolicyProvider;
 import org.apache.hadoop.util.ToolRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.SAXException;
 
-public class TestMRCLI extends TestHDFSCLI{
+public class TestMRCLI extends TestHDFSCLI {
 
   protected MiniMRCluster mrCluster = null;
   protected String jobtracker = null;
-  protected MRCmdExecutor cmdExecutor = null;
-  protected ArchiveCmdExecutor archiveCmdExecutor = null;
-  
+  private JobConf mrConf;
+
+  @Before
   public void setUp() throws Exception {
     super.setUp();
     conf.setClass(PolicyProvider.POLICY_PROVIDER_CONFIG,
         HadoopPolicyProvider.class, PolicyProvider.class);
-    JobConf mrConf = new JobConf(conf);
+    mrConf = new JobConf(conf);
     mrCluster = new MiniMRCluster(1, dfsCluster.getFileSystem().getUri().toString(), 1, 
                            null, null, mrConf);
     jobtracker = mrCluster.createJobConf().get(JTConfig.JT_IPC_ADDRESS, "local");
-    cmdExecutor = new MRCmdExecutor(jobtracker);
-    archiveCmdExecutor = new ArchiveCmdExecutor(namenode, mrConf);
   }
 
-  
+  @After
   public void tearDown() throws Exception {
     mrCluster.shutdown();
     super.tearDown();
   }
-  
-  protected String getTestFile() {
+
+    @Override
+    protected TestConfigFileParser getConfigParser() {
+        return new TestConfigFileParserMR();
+    }
+
+    protected String getTestFile() {
     return "testMRConf.xml";
   }
-  
+
+  @Override
   protected String expandCommand(final String cmd) {
     String expCmd = cmd;
     expCmd = expCmd.replaceAll("JOBTRACKER", jobtracker);
-    expCmd = super.expandCommand(cmd);
+    expCmd = super.expandCommand(expCmd);
     return expCmd;
   }
-  
-  protected Result execute(TestCmd cmd) throws Exception {
-    if(cmd.getType() == TestCmd.CommandType.MRADMIN) {
-      return cmdExecutor.executeCommand(cmd.getCmd());
-    } else if(cmd.getType() == TestCmd.CommandType.ARCHIVE) {
-      return archiveCmdExecutor.executeCommand(cmd.getCmd());
-    } else {
+
+  @Override
+  protected Result execute(CLICommand cmd) throws Exception {
+    if (cmd.getType() instanceof CLICommandMRAdmin)
+      return new TestMRCLI.MRCmdExecutor(jobtracker).executeCommand(cmd.getCmd());
+    else if (cmd.getType() instanceof CLICommandArchive)
+      return new TestMRCLI.ArchiveCmdExecutor(namenode, mrConf).executeCommand(cmd.getCmd());
+    else
       return super.execute(cmd);
-    }
   }
   
   public static class MRCmdExecutor extends CommandExecutor {
@@ -81,11 +88,13 @@ public class TestMRCLI extends TestHDFSC
     public MRCmdExecutor(String jobtracker) {
       this.jobtracker = jobtracker;
     }
+    @Override
     protected void execute(final String cmd) throws Exception{
       MRAdmin mradmin = new MRAdmin();
       String[] args = getCommandAsArgs(cmd, "JOBTRACKER", jobtracker);
       ToolRunner.run(mradmin, args);
     }
+
   }
   
   public static class ArchiveCmdExecutor extends CommandExecutor {
@@ -95,11 +104,43 @@ public class TestMRCLI extends TestHDFSC
       this.namenode = namenode;
       this.jobConf = jobConf;
     }
+    @Override
     protected void execute(final String cmd) throws Exception {
-//      JobConf job=new JobConf(conf);
       HadoopArchives archive = new HadoopArchives(jobConf);
       String[] args = getCommandAsArgs(cmd, "NAMENODE", namenode);
       ToolRunner.run(archive, args);
     }
   }
+
+  @Test
+  @Override
+  public void testAll () {
+    super.testAll();
+  }
+
+  class TestConfigFileParserMR extends CLITestHelper.TestConfigFileParser {
+    @Override
+    public void endElement(String uri, String localName, String qName)
+        throws SAXException {
+      if (qName.equals("mr-admin-command")) {
+        if (testCommands != null) {
+          testCommands.add(new CLITestCmdMR(charString,
+              new CLICommandMRAdmin()));
+        } else if (cleanupCommands != null) {
+          cleanupCommands.add(new CLITestCmdMR(charString,
+              new CLICommandMRAdmin()));
+        }
+      } else if (qName.equals("archive-command")) {
+        if (testCommands != null) {
+          testCommands.add(new CLITestCmdMR(charString,
+              new CLICommandArchive()));
+        } else if (cleanupCommands != null) {
+          cleanupCommands.add(new CLITestCmdMR(charString,
+              new CLICommandArchive()));
+        }
+      } else {
+        super.endElement(uri, localName, qName);
+      }
+    }
+  }
 }

Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandArchive.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandArchive.java?rev=1094093&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandArchive.java
(added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandArchive.java
Sun Apr 17 02:20:07 2011
@@ -0,0 +1,21 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 CLICommandArchive implements CLICommandTypes {
+}

Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandMRAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandMRAdmin.java?rev=1094093&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandMRAdmin.java
(added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/cli/util/CLICommandMRAdmin.java
Sun Apr 17 02:20:07 2011
@@ -0,0 +1,21 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 CLICommandMRAdmin implements CLICommandTypes {
+}



Mime
View raw message