|
@@ -17,17 +17,23 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
|
|
+import com.google.common.base.Supplier;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager;
|
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
-import org.apache.hadoop.hdfs.server.datanode.TestDataNodeMXBean;
|
|
|
|
|
|
+import org.apache.hadoop.test.GenericTestUtils;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
import javax.management.MBeanServer;
|
|
import javax.management.MBeanServer;
|
|
import javax.management.ObjectName;
|
|
import javax.management.ObjectName;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Class for testing {@link NameNodeStatusMXBean} implementation.
|
|
* Class for testing {@link NameNodeStatusMXBean} implementation.
|
|
@@ -38,7 +44,7 @@ public class TestNameNodeStatusMXBean {
|
|
TestNameNodeStatusMXBean.class);
|
|
TestNameNodeStatusMXBean.class);
|
|
|
|
|
|
@Test(timeout = 120000L)
|
|
@Test(timeout = 120000L)
|
|
- public void testDataNodeMXBean() throws Exception {
|
|
|
|
|
|
+ public void testNameNodeStatusMXBean() throws Exception {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
MiniDFSCluster cluster = null;
|
|
MiniDFSCluster cluster = null;
|
|
|
|
|
|
@@ -84,6 +90,55 @@ public class TestNameNodeStatusMXBean {
|
|
String slowPeersReport = (String)mbs.getAttribute(mxbeanName,
|
|
String slowPeersReport = (String)mbs.getAttribute(mxbeanName,
|
|
"SlowPeersReport");
|
|
"SlowPeersReport");
|
|
Assert.assertEquals(nn.getSlowPeersReport(), slowPeersReport);
|
|
Assert.assertEquals(nn.getSlowPeersReport(), slowPeersReport);
|
|
|
|
+
|
|
|
|
+ // Get attribute "SlowDisksReport"
|
|
|
|
+ String slowDisksReport = (String)mbs.getAttribute(mxbeanName,
|
|
|
|
+ "SlowDisksReport");
|
|
|
|
+ Assert.assertEquals(nn.getSlowDisksReport(), slowDisksReport);
|
|
|
|
+ } finally {
|
|
|
|
+ if (cluster != null) {
|
|
|
|
+ cluster.shutdown();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNameNodeMXBeanSlowDisksEnabled() throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ conf.setDouble(
|
|
|
|
+ DFSConfigKeys.DFS_DATANODE_FILEIO_PROFILING_SAMPLING_FRACTION_KEY, 1.0);
|
|
|
|
+ conf.setTimeDuration(
|
|
|
|
+ DFSConfigKeys.DFS_DATANODE_OUTLIERS_REPORT_INTERVAL_KEY,
|
|
|
|
+ 1000, TimeUnit.MILLISECONDS);
|
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ List<DataNode> datanodes = cluster.getDataNodes();
|
|
|
|
+ Assert.assertEquals(datanodes.size(), 1);
|
|
|
|
+ DataNode datanode = datanodes.get(0);
|
|
|
|
+ String slowDiskPath = "test/data1/slowVolume";
|
|
|
|
+ datanode.getDiskMetrics().addSlowDiskForTesting(slowDiskPath, null);
|
|
|
|
+
|
|
|
|
+ NameNode nn = cluster.getNameNode();
|
|
|
|
+ DatanodeManager datanodeManager = nn.getNamesystem().getBlockManager()
|
|
|
|
+ .getDatanodeManager();
|
|
|
|
+
|
|
|
|
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
|
|
|
+ ObjectName mxbeanName = new ObjectName(
|
|
|
|
+ "Hadoop:service=NameNode,name=NameNodeStatus");
|
|
|
|
+
|
|
|
|
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean get() {
|
|
|
|
+ return (datanodeManager.getSlowDisksReport() != null);
|
|
|
|
+ }
|
|
|
|
+ }, 1000, 100000);
|
|
|
|
+
|
|
|
|
+ String slowDisksReport = (String)mbs.getAttribute(
|
|
|
|
+ mxbeanName, "SlowDisksReport");
|
|
|
|
+ Assert.assertEquals(datanodeManager.getSlowDisksReport(),
|
|
|
|
+ slowDisksReport);
|
|
|
|
+ Assert.assertTrue(slowDisksReport.contains(slowDiskPath));
|
|
} finally {
|
|
} finally {
|
|
if (cluster != null) {
|
|
if (cluster != null) {
|
|
cluster.shutdown();
|
|
cluster.shutdown();
|