hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From waltersu4...@apache.org
Subject hadoop git commit: HDFS-10284. o.a.h.hdfs.server.blockmanagement.TestBlockManagerSafeMode.testCheckSafeMode fails intermittently. Contributed by Mingliang Liu.
Date Tue, 19 Apr 2016 10:09:42 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 438efc363 -> 4b4df2cd4


HDFS-10284. o.a.h.hdfs.server.blockmanagement.TestBlockManagerSafeMode.testCheckSafeMode fails
intermittently. Contributed by Mingliang Liu.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/4b4df2cd
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4b4df2cd
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4b4df2cd

Branch: refs/heads/trunk
Commit: 4b4df2cd48649b2d9cbdd97907c8d5f813cacdb1
Parents: 438efc3
Author: Walter Su <waltersu4549@apache.org>
Authored: Tue Apr 19 18:07:46 2016 +0800
Committer: Walter Su <waltersu4549@apache.org>
Committed: Tue Apr 19 18:07:46 2016 +0800

----------------------------------------------------------------------
 .../TestBlockManagerSafeMode.java               | 64 +++++++++++++++++---
 1 file changed, 54 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b4df2cd/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
index a347669..dc18a22 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
@@ -124,57 +124,101 @@ public class TestBlockManagerSafeMode {
 
   /**
    * Test the state machine transition.
+   *
+   * We use separate test methods instead of a single one because the mocked
+   * {@link #fsn} is accessed concurrently by the current thread and the
+   * <code>smmthread</code> thread in the {@link BlockManagerSafeMode}. Stubbing
+   * or verification of a shared mock from different threads is NOT the proper
+   * way of testing, which leads to intermittent behavior. Meanwhile, previous
+   * state transition may have side effects that should be reset before next
+   * test case. For example, in {@link BlockManagerSafeMode}, there is a safe
+   * mode monitor thread, which is created when BlockManagerSafeMode is
+   * constructed. It will start the first time the safe mode enters extension
+   * stage and will stop if the safe mode leaves to OFF state. Across different
+   * test cases, this thread should be reset.
    */
-  @Test(timeout = 30000)
-  public void testCheckSafeMode() {
-    bmSafeMode.activate(BLOCK_TOTAL);
-
+  @Test(timeout = 10000)
+  public void testCheckSafeMode1() {
     // stays in PENDING_THRESHOLD: pending block threshold
+    bmSafeMode.activate(BLOCK_TOTAL);
     setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
     for (long i = 0; i < BLOCK_THRESHOLD; i++) {
       setBlockSafe(i);
       bmSafeMode.checkSafeMode();
       assertEquals(BMSafeModeStatus.PENDING_THRESHOLD, getSafeModeStatus());
     }
+  }
 
-    // PENDING_THRESHOLD -> EXTENSION
+  /** Check safe mode transition from PENDING_THRESHOLD to EXTENSION. */
+  @Test(timeout = 10000)
+  public void testCheckSafeMode2() {
+    bmSafeMode.activate(BLOCK_TOTAL);
     Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE);
     setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
     setBlockSafe(BLOCK_THRESHOLD);
     bmSafeMode.checkSafeMode();
     assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+  }
 
-    // PENDING_THRESHOLD -> OFF
+  /** Check safe mode transition from PENDING_THRESHOLD to OFF. */
+  @Test(timeout = 10000)
+  public void testCheckSafeMode3() {
+    bmSafeMode.activate(BLOCK_TOTAL);
     Whitebox.setInternalState(bmSafeMode, "extension", 0);
     setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
     setBlockSafe(BLOCK_THRESHOLD);
     bmSafeMode.checkSafeMode();
     assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus());
+  }
 
-    // stays in EXTENSION
+  /** Check safe mode stays in EXTENSION pending threshold. */
+  @Test(timeout = 10000)
+  public void testCheckSafeMode4() {
+    bmSafeMode.activate(BLOCK_TOTAL);
     setBlockSafe(0);
     setSafeModeStatus(BMSafeModeStatus.EXTENSION);
     Whitebox.setInternalState(bmSafeMode, "extension", 0);
     bmSafeMode.checkSafeMode();
     assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+  }
 
-    // stays in EXTENSION: pending extension period
+  /** Check safe mode stays in EXTENSION pending extension period. */
+  @Test(timeout = 10000)
+  public void testCheckSafeMode5() {
+    bmSafeMode.activate(BLOCK_TOTAL);
     Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE);
     setSafeModeStatus(BMSafeModeStatus.EXTENSION);
     setBlockSafe(BLOCK_THRESHOLD);
     bmSafeMode.checkSafeMode();
     assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+  }
 
-    // should stay in PENDING_THRESHOLD during transitionToActive
+  /** Check it will not leave safe mode during NN transitionToActive. */
+  @Test(timeout = 10000)
+  public void testCheckSafeMode6() {
     doReturn(true).when(fsn).inTransitionToActive();
+    bmSafeMode.activate(BLOCK_TOTAL);
     Whitebox.setInternalState(bmSafeMode, "extension", 0);
     setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
     setBlockSafe(BLOCK_THRESHOLD);
     bmSafeMode.checkSafeMode();
     assertEquals(BMSafeModeStatus.PENDING_THRESHOLD, getSafeModeStatus());
+  }
+
+  /** Check smmthread will leave safe mode if NN is not in transitionToActive.*/
+  @Test(timeout = 10000)
+  public void testCheckSafeMode7() throws Exception {
     doReturn(false).when(fsn).inTransitionToActive();
+    bmSafeMode.activate(BLOCK_TOTAL);
+    Whitebox.setInternalState(bmSafeMode, "extension", 5);
+    setBlockSafe(BLOCK_THRESHOLD);
     bmSafeMode.checkSafeMode();
-    assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus());
+    GenericTestUtils.waitFor(new Supplier<Boolean>() {
+      @Override
+      public Boolean get() {
+        return getSafeModeStatus() == BMSafeModeStatus.OFF;
+      }
+    }, 100, 10000);
   }
 
   /**


Mime
View raw message