浏览代码

HDFS-4741. TestStorageRestore#testStorageRestoreFailure fails on Windows. Contributed by Arpit Agarwal.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1476585 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 12 年之前
父节点
当前提交
b7afde6d52

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -311,6 +311,9 @@ Trunk (Unreleased)
     HDFS-4584. Skip TestNNWithQJM.testNewNamenodeTakesOverWriter() on Windows.
     (Arpit Agarwal via szetszwo)
 
+    HDFS-4741. TestStorageRestore#testStorageRestoreFailure fails on Windows.
+    (Arpit Agarwal via suresh)
+
   BREAKDOWN OF HDFS-347 SUBTASKS AND RELATED JIRAS
 
     HDFS-4353. Encapsulate connections to peers in Peer and PeerServer classes.

+ 17 - 8
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java

@@ -47,6 +47,7 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
 import org.apache.hadoop.hdfs.server.namenode.JournalSet.JournalAndStream;
+import org.apache.hadoop.util.Shell;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -362,7 +363,7 @@ public class TestStorageRestore {
       }
     }
   }
-  
+
   /**
    * 1. create DFS cluster with 3 storage directories
    *    - 2 EDITS_IMAGE(name1, name2), 1 EDITS(name3)
@@ -379,8 +380,16 @@ public class TestStorageRestore {
    */
   @Test
   public void testStorageRestoreFailure() throws Exception {
-
     SecondaryNameNode secondary = null;
+
+    // On windows, revoking write+execute permission on name2 does not
+    // prevent us from creating files in name2\current. Hence we revoke
+    // permissions on name2\current for the test.
+    String nameDir2 = Shell.WINDOWS ?
+        (new File(path2, "current").getAbsolutePath()) : path2.toString();
+    String nameDir3 = Shell.WINDOWS ?
+        (new File(path3, "current").getAbsolutePath()) : path3.toString();
+
     try {
       cluster = new MiniDFSCluster.Builder(config).numDataNodes(0)
           .manageNameDfsDirs(false).build();
@@ -394,8 +403,8 @@ public class TestStorageRestore {
       assertTrue(fs.mkdirs(path));
 
       // invalidate storage by removing rwx permission from name2 and name3
-      FileUtil.chmod(path2.toString(), "000");
-      FileUtil.chmod(path3.toString(), "000");
+      assertTrue(FileUtil.chmod(nameDir2, "000") == 0);
+      assertTrue(FileUtil.chmod(nameDir3, "000") == 0);
       secondary.doCheckpoint(); // should remove name2 and name3
 
       printStorages(cluster.getNameNode().getFSImage());
@@ -409,18 +418,18 @@ public class TestStorageRestore {
       assert (cluster.getNameNode().getFSImage().getStorage()
           .getNumStorageDirs() == 1);
 
-      FileUtil.chmod(path2.toString(), "755");
-      FileUtil.chmod(path3.toString(), "755");
+      assertTrue(FileUtil.chmod(nameDir2, "755") == 0);
+      assertTrue(FileUtil.chmod(nameDir3, "755") == 0);
       secondary.doCheckpoint(); // should restore name 2 and 3
       assert (cluster.getNameNode().getFSImage().getStorage()
           .getNumStorageDirs() == 3);
 
     } finally {
       if (path2.exists()) {
-        FileUtil.chmod(path2.toString(), "755");
+        FileUtil.chmod(nameDir2, "755");
       }
       if (path3.exists()) {
-        FileUtil.chmod(path3.toString(), "755");
+        FileUtil.chmod(nameDir3, "755");
       }
       if (cluster != null) {
         cluster.shutdown();