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

This commit is contained in:
Uma Maheswara Rao G 2016-07-07 13:52:35 -07:00
parent 0185de0767
commit ab092c56c2
4 changed files with 66 additions and 18 deletions

View File

@ -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;
}
}

View File

@ -97,9 +97,10 @@ public class TestNameNodeResourceChecker {
cluster = new MiniDFSCluster.Builder(conf) cluster = new MiniDFSCluster.Builder(conf)
.numDataNodes(1).build(); .numDataNodes(1).build();
NameNodeResourceChecker mockResourceChecker = Mockito.mock(NameNodeResourceChecker.class); MockNameNodeResourceChecker mockResourceChecker =
Mockito.when(mockResourceChecker.hasAvailableDiskSpace()).thenReturn(true); new MockNameNodeResourceChecker(conf);
cluster.getNameNode().getNamesystem().nnResourceChecker = mockResourceChecker; cluster.getNameNode()
.getNamesystem().nnResourceChecker = mockResourceChecker;
cluster.waitActive(); cluster.waitActive();
@ -117,8 +118,8 @@ public class TestNameNodeResourceChecker {
isNameNodeMonitorRunning); isNameNodeMonitorRunning);
assertFalse("NN should not presently be in safe mode", assertFalse("NN should not presently be in safe mode",
cluster.getNameNode().isInSafeMode()); cluster.getNameNode().isInSafeMode());
Mockito.when(mockResourceChecker.hasAvailableDiskSpace()).thenReturn(false); mockResourceChecker.setResourcesAvailable(false);
// Make sure the NNRM thread has a chance to run. // Make sure the NNRM thread has a chance to run.
long startMillis = Time.now(); long startMillis = Time.now();

View File

@ -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_DEFAULT;
import static org.apache.hadoop.fs.CommonConfigurationKeys.HA_HM_RPC_TIMEOUT_KEY; 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.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; 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.DFSUtil;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.MiniDFSNNTopology; 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.hdfs.tools.NNHAServiceTarget;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
public class TestNNHealthCheck { public class TestNNHealthCheck {
@ -77,9 +77,8 @@ public class TestNNHealthCheck {
} }
private void doNNHealthCheckTest() throws IOException { private void doNNHealthCheckTest() throws IOException {
NameNodeResourceChecker mockResourceChecker = Mockito.mock( MockNameNodeResourceChecker mockResourceChecker =
NameNodeResourceChecker.class); new MockNameNodeResourceChecker(conf);
Mockito.doReturn(true).when(mockResourceChecker).hasAvailableDiskSpace();
cluster.getNameNode(0).getNamesystem() cluster.getNameNode(0).getNamesystem()
.setNNResourceChecker(mockResourceChecker); .setNNResourceChecker(mockResourceChecker);
@ -101,7 +100,7 @@ public class TestNNHealthCheck {
// Should not throw error, which indicates healthy. // Should not throw error, which indicates healthy.
rpc.monitorHealth(); rpc.monitorHealth();
Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace(); mockResourceChecker.setResourcesAvailable(false);
try { try {
// Should throw error - NN is unhealthy. // Should throw error - NN is unhealthy.

View File

@ -36,9 +36,9 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.MiniDFSNNTopology; import org.apache.hadoop.hdfs.MiniDFSNNTopology;
import org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream; 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.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.GenericTestUtils;
import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; import org.apache.hadoop.test.MultithreadedTestUtil.TestContext;
import org.apache.hadoop.test.MultithreadedTestUtil.TestingThread; import org.apache.hadoop.test.MultithreadedTestUtil.TestingThread;
@ -47,7 +47,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import org.mockito.Mockito;
public class TestDFSZKFailoverController extends ClientBaseWithFixes { public class TestDFSZKFailoverController extends ClientBaseWithFixes {
private Configuration conf; private Configuration conf;
@ -135,9 +134,9 @@ public class TestDFSZKFailoverController extends ClientBaseWithFixes {
*/ */
@Test(timeout=60000) @Test(timeout=60000)
public void testThreadDumpCaptureAfterNNStateChange() throws Exception { public void testThreadDumpCaptureAfterNNStateChange() throws Exception {
NameNodeResourceChecker mockResourceChecker = Mockito.mock( MockNameNodeResourceChecker mockResourceChecker =
NameNodeResourceChecker.class); new MockNameNodeResourceChecker(conf);
Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace(); mockResourceChecker.setResourcesAvailable(false);
cluster.getNameNode(0).getNamesystem() cluster.getNameNode(0).getNamesystem()
.setNNResourceChecker(mockResourceChecker); .setNNResourceChecker(mockResourceChecker);
waitForHAState(0, HAServiceState.STANDBY); waitForHAState(0, HAServiceState.STANDBY);