Repository: hadoop Updated Branches: refs/heads/branch-2 c2790932b -> d51ea6a24
HDFS-7301. TestMissingBlocksAlert should use MXBeans instead of old web UI. Contributed by Zhe Zhang. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/d51ea6a2 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/d51ea6a2 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/d51ea6a2 Branch: refs/heads/branch-2 Commit: d51ea6a2480b2693eb6458a87ed2357f674f6fd6 Parents: c279093 Author: Haohui Mai <[email protected]> Authored: Tue Oct 28 16:27:28 2014 -0700 Committer: Haohui Mai <[email protected]> Committed: Tue Oct 28 16:28:17 2014 -0700 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hadoop/hdfs/TestMissingBlocksAlert.java | 42 ++++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/d51ea6a2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 290b3ef..44f253e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -106,6 +106,9 @@ Release 2.7.0 - UNRELEASED TestBlockReaderFactory failures resulting from TemporarySocketDirectory GC. (Jinghui Wang via Colin Patrick McCabe) + HDFS-7301. TestMissingBlocksAlert should use MXBeans instead of old web UI. + (Zhe Zhang via wheat9) + Release 2.6.0 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/d51ea6a2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMissingBlocksAlert.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMissingBlocksAlert.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMissingBlocksAlert.java index 65a69b3..099d547 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMissingBlocksAlert.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMissingBlocksAlert.java @@ -17,13 +17,6 @@ */ package org.apache.hadoop.hdfs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.URL; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -32,8 +25,16 @@ import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; +import org.junit.Assert; import org.junit.Test; +import javax.management.*; +import java.io.IOException; +import java.lang.management.ManagementFactory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * The test makes sure that NameNode detects presense blocks that do not have * any valid replicas. In addition, it verifies that HDFS front page displays @@ -45,8 +46,11 @@ public class TestMissingBlocksAlert { LogFactory.getLog(TestMissingBlocksAlert.class); @Test - public void testMissingBlocksAlert() throws IOException, - InterruptedException { + public void testMissingBlocksAlert() + throws IOException, InterruptedException, + MalformedObjectNameException, AttributeNotFoundException, + MBeanException, ReflectionException, + InstanceNotFoundException { MiniDFSCluster cluster = null; @@ -95,14 +99,11 @@ public class TestMissingBlocksAlert { assertEquals(4, dfs.getUnderReplicatedBlocksCount()); assertEquals(3, bm.getUnderReplicatedNotMissingBlocks()); - - // Now verify that it shows up on webui - URL url = new URL("http://" + conf.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY) + - "/dfshealth.jsp"); - String dfsFrontPage = DFSTestUtil.urlGet(url); - String warnStr = "WARNING : There are "; - assertTrue("HDFS Front page does not contain expected warning", - dfsFrontPage.contains(warnStr + "1 missing blocks")); + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + ObjectName mxbeanName = new ObjectName( + "Hadoop:service=NameNode,name=NameNodeInfo"); + Assert.assertEquals(1, (long)(Long) mbs.getAttribute(mxbeanName, + "NumberOfMissingBlocks")); // now do the reverse : remove the file expect the number of missing // blocks to go to zero @@ -117,11 +118,8 @@ public class TestMissingBlocksAlert { assertEquals(2, dfs.getUnderReplicatedBlocksCount()); assertEquals(2, bm.getUnderReplicatedNotMissingBlocks()); - // and make sure WARNING disappears - // Now verify that it shows up on webui - dfsFrontPage = DFSTestUtil.urlGet(url); - assertFalse("HDFS Front page contains unexpected warning", - dfsFrontPage.contains(warnStr)); + Assert.assertEquals(0, (long)(Long) mbs.getAttribute(mxbeanName, + "NumberOfMissingBlocks")); } finally { if (cluster != null) { cluster.shutdown();
