hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1372728 - in /hadoop/common/branches/branch-1-win: CHANGES.branch-1-win.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
Date Tue, 14 Aug 2012 04:58:05 GMT
Author: suresh
Date: Tue Aug 14 04:58:04 2012
New Revision: 1372728

URL: http://svn.apache.org/viewvc?rev=1372728&view=rev
Log:
HDFS-3763. TestNameNodeMXBean fails on Windows. Contributed by Brandon Li

Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1372728&r1=1372727&r2=1372728&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Tue Aug 14 04:58:04 2012
@@ -69,3 +69,5 @@ BUG FIXES
 
     HADOOP-8618. Fix build failures due to release 1.0.3 merge.
     (Bikas Saha via suresh)
+
+    HDFS-3763. TestNameNodeMXBean fails on Windows. (Brandon Li via suresh)

Modified: hadoop/common/branches/branch-1-win/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java?rev=1372728&r1=1372727&r2=1372728&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java
(original)
+++ hadoop/common/branches/branch-1-win/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java
Tue Aug 14 04:58:04 2012
@@ -118,7 +118,7 @@ public class FSEditLog {
    * An implementation of the abstract class {@link EditLogOutputStream},
    * which stores edits in a local file.
    */
-  static private class EditLogFileOutputStream extends EditLogOutputStream {
+  static class EditLogFileOutputStream extends EditLogOutputStream {
     private File file;
     private FileOutputStream fp;    // file stream for storing edit logs 
     private FileChannel fc;         // channel of the file stream for sync
@@ -417,6 +417,31 @@ public class FSEditLog {
     // Namedir is the parent of current which is the parent of edits
     return editsFile.getParentFile().getParentFile();
   }
+  
+  /**
+   * For error injection tests only. It closes edit stream, unlocks storage
+   * directory, and reopen the original stream with a different
+   * EditLogFileOutputStream which can inject errors.
+   */
+  synchronized void replaceEditsStream(FSImage fsimage, File sdRoot,
+      EditLogFileOutputStream stream) {
+    exitIfStreamsNotSet();
+
+    for (int idx = 0; idx < editStreams.size(); idx++) {
+      File parentDir = getStorageDirForStream(idx);
+      if (parentDir.getAbsolutePath().equals(sdRoot.getAbsolutePath())) {
+        StorageDirectory sd = fsimage.getStorageDir(idx);
+        try {
+          EditLogOutputStream estream = editStreams.get(idx);
+          estream.close();
+          editStreams.set(idx, stream);
+          sd.unlock();
+        } catch (IOException ioe) {
+          ioe.printStackTrace();
+        }
+      }
+    }
+  }
 
   /**
    * Remove the given edits stream and its containing storage dir.

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java?rev=1372728&r1=1372727&r2=1372728&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
(original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
Tue Aug 14 04:58:04 2012
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.server.na
 import static org.junit.Assert.*;
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.util.Collection;
 import java.util.Map;
@@ -31,9 +32,11 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.FSEditLog.EditLogFileOutputStream;
 import org.apache.hadoop.util.VersionInfo;
 
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.mortbay.util.ajax.JSON;
 
 import junit.framework.Assert;
@@ -42,6 +45,26 @@ import junit.framework.Assert;
  * Class for testing {@link NameNodeMXBean} implementation
  */
 public class TestNameNodeMXBean {
+  /**
+   * Create a mocked stream to fail edits log operations
+   */
+  public static EditLogFileOutputStream mockStream(File sdRoot)
+      throws IOException {
+    // Create a mocked EditLogFileOutputStream
+    String edits = sdRoot.getAbsolutePath() + "/current/edits";
+    EditLogFileOutputStream mockStream = Mockito
+        .mock(EditLogFileOutputStream.class);
+    Mockito.when(mockStream.getName()).thenReturn(edits);
+    IOException ioe = new IOException("Mock IOException");
+    Mockito.doThrow(ioe).when(mockStream).write(Mockito.anyInt());
+    Mockito.doThrow(ioe).when(mockStream).flushAndSync();
+    Mockito.doThrow(ioe).when(mockStream).close();
+    Mockito.doThrow(ioe).when(mockStream).setReadyToFlush();
+    Mockito.doThrow(ioe).when(mockStream).flushAndSync();
+    Mockito.when(mockStream.getFile()).thenReturn(new File(edits));
+    return mockStream;
+  }
+  
   @SuppressWarnings({ "unchecked", "deprecation" })
   @Test
   public void testNameNodeMXBeanInfo() throws Exception {
@@ -110,7 +133,13 @@ public class TestNameNodeMXBean {
       
       // This will cause the first dir to fail.
       File failedNameDir = nameDirs.toArray(new File[0])[0];
-      assertEquals(0, FileUtil.chmod(failedNameDir.getAbsolutePath(), "000"));
+      FSImage fsimage = cluster.getNameNode().getFSImage();
+      System.out.println("Use mocked stream to replace the edits in:"
+          + failedNameDir);
+      fsimage.getEditLog().replaceEditsStream(fsimage, failedNameDir,
+          mockStream(failedNameDir));
+    
+      // The above dir will be marked as failed during rollEditLog
       cluster.getNameNode().rollEditLog();
       
       nameDirStatuses = (String) (mbs.getAttribute(mxbeanName,



Mime
View raw message