Browse Source

HADOOP-7730. Allow TestCLI to be run against a cluster. Contributed by Tom White, Konstantin Boudnik.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.22@1182018 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Boudnik 13 years ago
parent
commit
fa82c7a1d6

+ 2 - 0
common/CHANGES.txt

@@ -549,6 +549,8 @@ Release 0.22.0 - Unreleased
     HADOOP-7697. Remove ivy dependency on different version of slf4j in avro.
     HADOOP-7697. Remove ivy dependency on different version of slf4j in avro.
     (shv)
     (shv)
 
 
+    HADOOP-7730. Allow TestCLI to be run against a cluster (cos)
+
 Release 0.21.1 - Unreleased
 Release 0.21.1 - Unreleased
 
 
   IMPROVEMENTS
   IMPROVEMENTS

+ 15 - 4
common/src/test/core/org/apache/hadoop/cli/CLITestHelper.java

@@ -59,7 +59,9 @@ public class CLITestHelper {
   public static final String TESTMODE_NOCOMPARE = "nocompare";
   public static final String TESTMODE_NOCOMPARE = "nocompare";
   public static final String TEST_CACHE_DATA_DIR =
   public static final String TEST_CACHE_DATA_DIR =
     System.getProperty("test.cache.data", "build/test/cache");
     System.getProperty("test.cache.data", "build/test/cache");
-  
+  public static final String TEST_DIR_ABSOLUTE = "/tmp/testcli";
+  protected static String testDirAbsolute = TEST_DIR_ABSOLUTE;
+
   //By default, run the tests. The other mode is to run the commands and not
   //By default, run the tests. The other mode is to run the commands and not
   // compare the output
   // compare the output
   protected String testMode = TESTMODE_TEST;
   protected String testMode = TESTMODE_TEST;
@@ -72,7 +74,7 @@ public class CLITestHelper {
   protected Configuration conf = null;
   protected Configuration conf = null;
   protected String clitestDataDir = null;
   protected String clitestDataDir = null;
   protected String username = null;
   protected String username = null;
-  
+
   /**
   /**
    * Read the test config file - testConfig.xml
    * Read the test config file - testConfig.xml
    */
    */
@@ -80,10 +82,16 @@ public class CLITestHelper {
     String testConfigFile = getTestFile();
     String testConfigFile = getTestFile();
     if (testsFromConfigFile == null) {
     if (testsFromConfigFile == null) {
       boolean success = false;
       boolean success = false;
-      testConfigFile = TEST_CACHE_DATA_DIR + File.separator + testConfigFile;
+      String configFile = System.getProperty("test.cli.config");
+      if (configFile == null) {
+        testConfigFile = TEST_CACHE_DATA_DIR + File.separator + testConfigFile;
+      } else {
+        testConfigFile = configFile;
+      }
       try {
       try {
         SAXParser p = (SAXParserFactory.newInstance()).newSAXParser();
         SAXParser p = (SAXParserFactory.newInstance()).newSAXParser();
         p.parse(testConfigFile, new TestConfigFileParser());
         p.parse(testConfigFile, new TestConfigFileParser());
+        LOG.info("Using test config file " + testConfigFile);
         success = true;
         success = true;
       } catch (Exception e) {
       } catch (Exception e) {
         LOG.info("File: " + testConfigFile + " not found");
         LOG.info("File: " + testConfigFile + " not found");
@@ -110,6 +118,8 @@ public class CLITestHelper {
 
 
     clitestDataDir = new File(TEST_CACHE_DATA_DIR).
     clitestDataDir = new File(TEST_CACHE_DATA_DIR).
     toURI().toString().replace(' ', '+');
     toURI().toString().replace(' ', '+');
+    // Many of the tests expect a replication value of 1 in the output
+    conf.setInt("dfs.replication", 1);
   }
   }
   
   
   /**
   /**
@@ -128,7 +138,8 @@ public class CLITestHelper {
     String expCmd = cmd;
     String expCmd = cmd;
     expCmd = expCmd.replaceAll("CLITEST_DATA", clitestDataDir);
     expCmd = expCmd.replaceAll("CLITEST_DATA", clitestDataDir);
     expCmd = expCmd.replaceAll("USERNAME", username);
     expCmd = expCmd.replaceAll("USERNAME", username);
-    
+    expCmd = expCmd.replaceAll("TEST_DIR_ABSOLUTE", testDirAbsolute);
+
     return expCmd;
     return expCmd;
   }
   }
   
   

+ 2 - 0
common/src/test/core/org/apache/hadoop/cli/util/CommandExecutor.java

@@ -43,6 +43,8 @@ public abstract class CommandExecutor {
       args[i] = args[i].replaceAll("CLITEST_DATA", 
       args[i] = args[i].replaceAll("CLITEST_DATA", 
         new File(CLITestHelper.TEST_CACHE_DATA_DIR).
         new File(CLITestHelper.TEST_CACHE_DATA_DIR).
         toURI().toString().replace(' ', '+'));
         toURI().toString().replace(' ', '+'));
+      args[i] = args[i].replaceAll("TEST_DIR_ABSOLUTE",
+        CLITestHelper.TEST_DIR_ABSOLUTE);
       args[i] = args[i].replaceAll("USERNAME", System.getProperty("user.name"));
       args[i] = args[i].replaceAll("USERNAME", System.getProperty("user.name"));
 
 
       i++;
       i++;