HDFS-7301. TestMissingBlocksAlert should use MXBeans instead of old web UI. Contributed by Zhe Zhang.

This commit is contained in:
Haohui Mai 2014-10-28 16:27:28 -07:00
parent c2790932bd
commit d51ea6a248
2 changed files with 23 additions and 22 deletions

View File

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

View File

@ -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();