hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umamah...@apache.org
Subject hadoop git commit: HDFS-10592:Fix intermittent test failure of TestNameNodeResourceChecker#testCheckThatNameNodeResourceMonitorIsRunning. Contributed by Rakesh R
Date Thu, 07 Jul 2016 21:01:04 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 f78be9746 -> 909fa138f


HDFS-10592:Fix intermittent test failure of TestNameNodeResourceChecker#testCheckThatNameNodeResourceMonitorIsRunning.
Contributed by Rakesh R

(cherry picked from commit ab092c56c251f27a9426e3c69a784417fdf9a26e)


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

Branch: refs/heads/branch-2
Commit: 909fa138f0dac6c88c4b02968f09b98c943d97d4
Parents: f78be97
Author: Uma Maheswara Rao G <uma.gangumalla@intel.com>
Authored: Thu Jul 7 13:52:35 2016 -0700
Committer: Uma Maheswara Rao G <uma.gangumalla@intel.com>
Committed: Thu Jul 7 14:00:05 2016 -0700

----------------------------------------------------------------------
 .../namenode/MockNameNodeResourceChecker.java   | 49 ++++++++++++++++++++
 .../namenode/TestNameNodeResourceChecker.java   | 11 +++--
 .../server/namenode/ha/TestNNHealthCheck.java   | 13 +++---
 .../hdfs/tools/TestDFSZKFailoverController.java | 11 ++---
 4 files changed, 66 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/909fa138/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/MockNameNodeResourceChecker.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/MockNameNodeResourceChecker.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/MockNameNodeResourceChecker.java
new file mode 100644
index 0000000..745ef8c
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/MockNameNodeResourceChecker.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * Mock NameNodeResourceChecker with resource availability flag which will be
+ * used to simulate the Namenode resource status.
+ */
+public class MockNameNodeResourceChecker extends NameNodeResourceChecker {
+  private volatile boolean hasResourcesAvailable = true;
+
+  public MockNameNodeResourceChecker(Configuration conf) throws IOException {
+    super(conf);
+  }
+
+  @Override
+  public boolean hasAvailableDiskSpace() {
+    return hasResourcesAvailable;
+  }
+
+  /**
+   * Sets resource availability flag.
+   *
+   * @param resourceAvailable
+   *          sets true if the resource is available otherwise sets to false
+   */
+  public void setResourcesAvailable(boolean resourceAvailable) {
+    hasResourcesAvailable = resourceAvailable;
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/909fa138/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
index 2012b6a..f86ce5f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
@@ -97,9 +97,10 @@ public class TestNameNodeResourceChecker {
       cluster = new MiniDFSCluster.Builder(conf)
           .numDataNodes(1).build();
 
-      NameNodeResourceChecker mockResourceChecker = Mockito.mock(NameNodeResourceChecker.class);
-      Mockito.when(mockResourceChecker.hasAvailableDiskSpace()).thenReturn(true);
-      cluster.getNameNode().getNamesystem().nnResourceChecker = mockResourceChecker;
+      MockNameNodeResourceChecker mockResourceChecker =
+          new MockNameNodeResourceChecker(conf);
+      cluster.getNameNode()
+          .getNamesystem().nnResourceChecker = mockResourceChecker;
 
       cluster.waitActive();
 
@@ -117,8 +118,8 @@ public class TestNameNodeResourceChecker {
           isNameNodeMonitorRunning);
       assertFalse("NN should not presently be in safe mode",
           cluster.getNameNode().isInSafeMode());
-      
-      Mockito.when(mockResourceChecker.hasAvailableDiskSpace()).thenReturn(false);
+
+      mockResourceChecker.setResourcesAvailable(false);
 
       // Make sure the NNRM thread has a chance to run.
       long startMillis = Time.now();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/909fa138/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java
index 4fca63b..e0f794f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java
@@ -20,7 +20,8 @@ package org.apache.hadoop.hdfs.server.namenode.ha;
 import static org.apache.hadoop.fs.CommonConfigurationKeys.HA_HM_RPC_TIMEOUT_DEFAULT;
 import static org.apache.hadoop.fs.CommonConfigurationKeys.HA_HM_RPC_TIMEOUT_KEY;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 
@@ -30,14 +31,13 @@ import org.apache.hadoop.ha.HealthCheckFailedException;
 import org.apache.hadoop.hdfs.DFSUtil;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.MiniDFSNNTopology;
-import org.apache.hadoop.hdfs.server.namenode.NameNodeResourceChecker;
+import org.apache.hadoop.hdfs.server.namenode.MockNameNodeResourceChecker;
 import org.apache.hadoop.hdfs.tools.NNHAServiceTarget;
 import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 
 public class TestNNHealthCheck {
 
@@ -77,9 +77,8 @@ public class TestNNHealthCheck {
   }
 
   private void doNNHealthCheckTest() throws IOException {
-    NameNodeResourceChecker mockResourceChecker = Mockito.mock(
-        NameNodeResourceChecker.class);
-    Mockito.doReturn(true).when(mockResourceChecker).hasAvailableDiskSpace();
+    MockNameNodeResourceChecker mockResourceChecker =
+        new MockNameNodeResourceChecker(conf);
     cluster.getNameNode(0).getNamesystem()
         .setNNResourceChecker(mockResourceChecker);
 
@@ -101,7 +100,7 @@ public class TestNNHealthCheck {
     // Should not throw error, which indicates healthy.
     rpc.monitorHealth();
 
-    Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace();
+    mockResourceChecker.setResourcesAvailable(false);
 
     try {
       // Should throw error - NN is unhealthy.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/909fa138/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFailoverController.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFailoverController.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFailoverController.java
index 94ccced..dfdcf34 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFailoverController.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFailoverController.java
@@ -36,9 +36,9 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.MiniDFSNNTopology;
 import org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream;
-import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
+import org.apache.hadoop.hdfs.server.namenode.MockNameNodeResourceChecker;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
-import org.apache.hadoop.hdfs.server.namenode.NameNodeResourceChecker;
+import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.test.MultithreadedTestUtil.TestContext;
 import org.apache.hadoop.test.MultithreadedTestUtil.TestingThread;
@@ -47,7 +47,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.base.Supplier;
-import org.mockito.Mockito;
 
 public class TestDFSZKFailoverController extends ClientBaseWithFixes {
   private Configuration conf;
@@ -135,9 +134,9 @@ public class TestDFSZKFailoverController extends ClientBaseWithFixes {
    */
   @Test(timeout=60000)
   public void testThreadDumpCaptureAfterNNStateChange() throws Exception {
-    NameNodeResourceChecker mockResourceChecker = Mockito.mock(
-        NameNodeResourceChecker.class);
-    Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace();
+    MockNameNodeResourceChecker mockResourceChecker =
+        new MockNameNodeResourceChecker(conf);
+    mockResourceChecker.setResourcesAvailable(false);
     cluster.getNameNode(0).getNamesystem()
         .setNNResourceChecker(mockResourceChecker);
     waitForHAState(0, HAServiceState.STANDBY);


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message