hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r828886 - in /hadoop/common/trunk: CHANGES.txt src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
Date Thu, 22 Oct 2009 22:46:40 GMT
Author: szetszwo
Date: Thu Oct 22 22:46:39 2009
New Revision: 828886

URL: http://svn.apache.org/viewvc?rev=828886&view=rev
Log:
HADOOP-6327. FileContext tests should not use /tmp and should clean up files.  Contributed
by Sanjay Radia

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=828886&r1=828885&r2=828886&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Thu Oct 22 22:46:39 2009
@@ -1114,6 +1114,9 @@
 
     HADOOP-6292. Update native libraries guide. (Corinne Chandel via cdouglas)
 
+    HADOOP-6327. FileContext tests should not use /tmp and should clean up
+    files.  (Sanjay Radia via szetszwo)
+
 Release 0.20.2 - Unreleased
 
   NEW FEATURES

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java?rev=828886&r1=828885&r2=828886&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
(original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
Thu Oct 22 22:46:39 2009
@@ -52,9 +52,10 @@
    
   protected static FileContext fc;
   static final String TEST_ROOT_DIR = new Path(System.getProperty(
-      "test.build.data", "/tmp")).toString().replace(' ', '_')
+      "test.build.data", "build/test/data")).toString().replace(' ', '_')
       + "/test";
   
+  
   protected Path getTestRootRelativePath(String pathString) {
     return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString));
   }

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java?rev=828886&r1=828885&r2=828886&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
(original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
Thu Oct 22 22:46:39 2009
@@ -56,11 +56,35 @@
   private static String TEST_DIR_AXA = "test/hadoop/axa";
   private static String TEST_DIR_AXX = "test/hadoop/axx";
   
-  private static String TEST_ROOT_DIR =
-    System.getProperty("test.build.data", "/tmp");
+  static  final String LOCAL_FS_ROOT_URI = "file:///tmp/test";
   
-  protected Path getTestRootPath(String pathString) {
-    return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString));
+  static final String TEST_ROOT_DIR = 
+    System.getProperty("test.build.data", "build/test/data").replace(' ', '_');
+  
+  
+  /** 
+   * we need to store the absRootDir because some tests may do a setWd and
+   * the TEST_ROOT_DIR may itself be relative.
+   */
+  String absTestRootDir = null;
+  protected String getAbsoluteTestRootDir() throws IOException {
+    if (absTestRootDir == null) {
+      if (TEST_ROOT_DIR.startsWith("/")) {
+        absTestRootDir = TEST_ROOT_DIR;
+      } else {
+        absTestRootDir = getDefaultWorkingDirectory().toString() +  "/"  + 
+                      TEST_ROOT_DIR; 
+      }
+    }
+    return absTestRootDir;
+  }
+  
+  protected Path getTestRootDir() throws IOException {
+    return fc.makeQualified(new Path(getAbsoluteTestRootDir()));
+  }
+  
+  protected Path getTestRootPath(String pathString) throws IOException {
+    return fc.makeQualified(new Path(getAbsoluteTestRootDir(), pathString));
   }
 
   
@@ -75,7 +99,7 @@
   //A test filter with returns any path containing a "b" 
   final private static PathFilter TEST_X_FILTER = new PathFilter() {
     public boolean accept(Path file) {
-      if(file.toString().contains("x") || file.toString().contains("X"))
+      if(file.getName().contains("x") || file.toString().contains("X"))
         return true;
       else
         return false;
@@ -97,6 +121,7 @@
   @After
   public void tearDown() throws Exception {
     fc.delete(getTestRootPath("test"), true);
+    fc.delete(new Path(LOCAL_FS_ROOT_URI), true);
   }
   
   protected static int getBlockSize() {
@@ -130,7 +155,9 @@
   @Test
   public void testWorkingDirectory() throws Exception {
 
-    Path workDir = getDefaultWorkingDirectory();
+    // First we cd to our test root
+    Path workDir = new Path(getTestRootDir(), new Path("test"));
+    fc.setWorkingDirectory(workDir);
     Assert.assertEquals(workDir, fc.getWorkingDirectory());
 
     fc.setWorkingDirectory(new Path("."));
@@ -140,8 +167,14 @@
     Assert.assertEquals(workDir.getParent(), fc.getWorkingDirectory());
     
     // cd using a relative path
+
+    // Go back to our test root
+    workDir = new Path(getTestRootDir(), new Path("test"));
+    fc.setWorkingDirectory(workDir);
+    Assert.assertEquals(workDir, fc.getWorkingDirectory());
+    
     Path relativeDir = new Path("existingDir1");
-    Path absoluteDir = new Path(workDir.getParent(),"existingDir1");
+    Path absoluteDir = new Path(workDir,"existingDir1");
     fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true);
     fc.setWorkingDirectory(relativeDir);
     Assert.assertEquals(absoluteDir,
@@ -166,7 +199,8 @@
     }
     
     // Try a URI
-    absoluteDir = new Path("file:///tmp/existingDir");
+
+    absoluteDir = new Path(LOCAL_FS_ROOT_URI + "/existingDir");
     fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true);
     fc.setWorkingDirectory(absoluteDir);
     Assert.assertEquals(absoluteDir, fc.getWorkingDirectory());
@@ -930,7 +964,8 @@
     Assert.assertEquals("Source exists", srcExists, fc.exists(src));
     Assert.assertEquals("Destination exists", dstExists, fc.exists(dst));
   }
-  private boolean containsPath(Path path, FileStatus[] filteredPaths) {
+  private boolean containsPath(Path path, FileStatus[] filteredPaths)
+    throws IOException {
     for(int i = 0; i < filteredPaths.length; i ++) { 
       if(getTestRootPath(path.toString()).equals(filteredPaths[i].getPath())) 
         return true;



Mime
View raw message