hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r730331 - in /hadoop/core/trunk: CHANGES.txt src/test/org/apache/hadoop/hdfs/TestSafeMode.java
Date Wed, 31 Dec 2008 07:05:11 GMT
Author: shv
Date: Tue Dec 30 23:05:11 2008
New Revision: 730331

URL: http://svn.apache.org/viewvc?rev=730331&view=rev
Log:
HADOOP-4936. Improvements to TestSafeMode. Contributed by Konstantin Shvachko.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestSafeMode.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=730331&r1=730330&r2=730331&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Dec 30 23:05:11 2008
@@ -11,6 +11,8 @@
 
   IMPROVEMENTS
 
+    HADOOP-4936. Improvements to TestSafeMode. (shv)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestSafeMode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestSafeMode.java?rev=730331&r1=730330&r2=730331&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestSafeMode.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/hdfs/TestSafeMode.java Tue Dec 30 23:05:11
2008
@@ -23,24 +23,37 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction;
-import org.apache.hadoop.hdfs.server.namenode.NameNode;
 
 import junit.framework.TestCase;
 
 /**
- * This test makes sure that if SafeMode is manually entered, NameNode does not
- * come out of safe mode even after the startup safemode conditions are met.
+ * Tests to verify safe mode correctness.
  */
 public class TestSafeMode extends TestCase {
   
   static Log LOG = LogFactory.getLog(TestSafeMode.class);
-  
+
+  /**
+   * This test verifies that if SafeMode is manually entered, name-node does not
+   * come out of safe mode even after the startup safe mode conditions are met.
+   * <ol>
+   * <li>Start cluster with 1 data-node.</li>
+   * <li>Create 2 files with replication 1.</li>
+   * <li>Re-start cluster with 0 data-nodes. 
+   * Name-node should stay in automatic safe-mode.</li>
+   * <li>Enter safe mode manually.</li>
+   * <li>Start the data-node.</li>
+   * <li>Wait longer than <tt>dfs.safemode.extension</tt> and 
+   * verify that the name-node is still in safe mode.</li>
+   * </ol>
+   *  
+   * @throws IOException
+   */
   public void testManualSafeMode() throws IOException {
     MiniDFSCluster cluster = null;
-    FileSystem fs = null;
+    DistributedFileSystem fs = null;
     try {
       Configuration conf = new Configuration();
       // disable safemode extension to make the test run faster.
@@ -48,7 +61,7 @@
       cluster = new MiniDFSCluster(conf, 1, true, null);
       cluster.waitActive();
       
-      fs = cluster.getFileSystem();
+      fs = (DistributedFileSystem)cluster.getFileSystem();
       Path file1 = new Path("/tmp/testManualSafeMode/file1");
       Path file2 = new Path("/tmp/testManualSafeMode/file2");
       
@@ -56,37 +69,40 @@
       
       // create two files with one block each.
       DFSTestUtil.createFile(fs, file1, 1000, (short)1, 0);
-      DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);    
+      DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);
+      fs.close();
       cluster.shutdown();
       
       // now bring up just the NameNode.
       cluster = new MiniDFSCluster(conf, 0, false, null);
       cluster.waitActive();
+      fs = (DistributedFileSystem)cluster.getFileSystem();
       
       LOG.info("Restarted cluster with just the NameNode");
       
-      NameNode namenode = cluster.getNameNode();
-      
       assertTrue("No datanode is started. Should be in SafeMode", 
-                 namenode.isInSafeMode());
+                 fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
       
       // manually set safemode.
-      namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
+      fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
       
       // now bring up the datanode and wait for it to be active.
       cluster.startDataNodes(conf, 1, true, null, null);
       cluster.waitActive();
       
       LOG.info("Datanode is started.");
-      
+
+      // wait longer than dfs.safemode.extension
       try {
         Thread.sleep(2000);
       } catch (InterruptedException ignored) {}
       
-      assertTrue("should still be in SafeMode", namenode.isInSafeMode());
+      assertTrue("should still be in SafeMode",
+          fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
       
-      namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
-      assertFalse("should not be in SafeMode", namenode.isInSafeMode());
+      fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
+      assertFalse("should not be in SafeMode",
+          fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
     } finally {
       if(fs != null) fs.close();
       if(cluster!= null) cluster.shutdown();



Mime
View raw message