فهرست منبع

Add another unit test for SecondaryNameNode.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1073@1143512 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 14 سال پیش
والد
کامیت
1ef15adc6a
1فایلهای تغییر یافته به همراه44 افزوده شده و 0 حذف شده
  1. 44 0
      hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java

+ 44 - 0
hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java

@@ -1578,6 +1578,50 @@ public class TestCheckpoint extends TestCase {
   }
   }
 
 
 
 
+  /**
+   * Test case where the secondary does a checkpoint, then stops for a while.
+   * In the meantime, the NN saves its image several times, so that the
+   * logs that connect the 2NN's old checkpoint to the current txid
+   * get archived. Then, the 2NN tries to checkpoint again.
+   */
+  @SuppressWarnings("deprecation")
+  public void testSecondaryHasVeryOutOfDateImage() throws IOException {
+    MiniDFSCluster cluster = null;
+    SecondaryNameNode secondary = null;
+    
+    Configuration conf = new HdfsConfiguration();
+
+    try {
+      cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDatanodes)
+          .format(true).build();
+  
+      secondary = startSecondaryNameNode(conf);
+
+      // Checkpoint once
+      secondary.doCheckpoint();
+
+      // Now primary NN saves namespace 3 times
+      NameNode nn = cluster.getNameNode();
+      nn.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
+      for (int i = 0; i < 3; i++) {
+        nn.saveNamespace();
+      }
+      nn.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
+      
+      // Now the secondary tries to checkpoint again with its
+      // old image in memory.
+      secondary.doCheckpoint();
+      
+    } finally {
+      if (secondary != null) {
+        secondary.shutdown();
+      }
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
+
   @SuppressWarnings("deprecation")
   @SuppressWarnings("deprecation")
   private void cleanup(SecondaryNameNode snn) {
   private void cleanup(SecondaryNameNode snn) {
     if (snn != null) {
     if (snn != null) {