|
@@ -17,23 +17,33 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
|
|
+import static org.junit.Assert.*;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
+import java.net.URI;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.management.MBeanServer;
|
|
import javax.management.MBeanServer;
|
|
import javax.management.ObjectName;
|
|
import javax.management.ObjectName;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.FileUtil;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
import org.apache.hadoop.util.VersionInfo;
|
|
import org.apache.hadoop.util.VersionInfo;
|
|
|
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import org.mortbay.util.ajax.JSON;
|
|
|
|
+
|
|
import junit.framework.Assert;
|
|
import junit.framework.Assert;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Class for testing {@link NameNodeMXBean} implementation
|
|
* Class for testing {@link NameNodeMXBean} implementation
|
|
*/
|
|
*/
|
|
public class TestNameNodeMXBean {
|
|
public class TestNameNodeMXBean {
|
|
|
|
+ @SuppressWarnings({ "unchecked", "deprecation" })
|
|
@Test
|
|
@Test
|
|
public void testNameNodeMXBeanInfo() throws Exception {
|
|
public void testNameNodeMXBeanInfo() throws Exception {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
@@ -88,8 +98,46 @@ public class TestNameNodeMXBean {
|
|
String deadnodeinfo = (String) (mbs.getAttribute(mxbeanName,
|
|
String deadnodeinfo = (String) (mbs.getAttribute(mxbeanName,
|
|
"DeadNodes"));
|
|
"DeadNodes"));
|
|
Assert.assertEquals(fsn.getDeadNodes(), deadnodeinfo);
|
|
Assert.assertEquals(fsn.getDeadNodes(), deadnodeinfo);
|
|
|
|
+ // get attribute NameDirStatuses
|
|
|
|
+ String nameDirStatuses = (String) (mbs.getAttribute(mxbeanName,
|
|
|
|
+ "NameDirStatuses"));
|
|
|
|
+ Assert.assertEquals(fsn.getNameDirStatuses(), nameDirStatuses);
|
|
|
|
+ Map<String, Map<String, String>> statusMap =
|
|
|
|
+ (Map<String, Map<String, String>>) JSON.parse(nameDirStatuses);
|
|
|
|
+ Collection<URI> nameDirUris = cluster.getNameDirs(0);
|
|
|
|
+ for (URI nameDirUri : nameDirUris) {
|
|
|
|
+ File nameDir = new File(nameDirUri);
|
|
|
|
+ System.out.println("Checking for the presence of " + nameDir +
|
|
|
|
+ " in active name dirs.");
|
|
|
|
+ assertTrue(statusMap.get("active").containsKey(nameDir.getAbsolutePath()));
|
|
|
|
+ }
|
|
|
|
+ assertEquals(2, statusMap.get("active").size());
|
|
|
|
+ assertEquals(0, statusMap.get("failed").size());
|
|
|
|
+
|
|
|
|
+ // This will cause the first dir to fail.
|
|
|
|
+ File failedNameDir = new File(nameDirUris.toArray(new URI[0])[0]);
|
|
|
|
+ assertEquals(0, FileUtil.chmod(failedNameDir.getAbsolutePath(), "000"));
|
|
|
|
+ cluster.getNameNodeRpc().rollEditLog();
|
|
|
|
+
|
|
|
|
+ nameDirStatuses = (String) (mbs.getAttribute(mxbeanName,
|
|
|
|
+ "NameDirStatuses"));
|
|
|
|
+ statusMap = (Map<String, Map<String, String>>) JSON.parse(nameDirStatuses);
|
|
|
|
+ for (URI nameDirUri : nameDirUris) {
|
|
|
|
+ File nameDir = new File(nameDirUri);
|
|
|
|
+ String expectedStatus =
|
|
|
|
+ nameDir.equals(failedNameDir) ? "failed" : "active";
|
|
|
|
+ System.out.println("Checking for the presence of " + nameDir +
|
|
|
|
+ " in " + expectedStatus + " name dirs.");
|
|
|
|
+ assertTrue(statusMap.get(expectedStatus).containsKey(
|
|
|
|
+ nameDir.getAbsolutePath()));
|
|
|
|
+ }
|
|
|
|
+ assertEquals(1, statusMap.get("active").size());
|
|
|
|
+ assertEquals(1, statusMap.get("failed").size());
|
|
} finally {
|
|
} finally {
|
|
if (cluster != null) {
|
|
if (cluster != null) {
|
|
|
|
+ for (URI dir : cluster.getNameDirs(0)) {
|
|
|
|
+ FileUtil.chmod(new File(dir).toString(), "700");
|
|
|
|
+ }
|
|
cluster.shutdown();
|
|
cluster.shutdown();
|
|
}
|
|
}
|
|
}
|
|
}
|