HDFS-10668. Fix intermittently failing UT TestDataNodeMXBean#testDataNodeMXBeanBlockCount. Contributed by Mingliang Liu.

This commit is contained in:
Brahma Reddy Battula 2016-07-27 10:28:31 +05:30
parent 77e0b6d1bf
commit 096d3fa25c
1 changed files with 17 additions and 7 deletions

View File

@ -25,11 +25,13 @@ import java.util.Map;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectName; import javax.management.ObjectName;
import com.google.common.base.Supplier;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mortbay.util.ajax.JSON; import org.mortbay.util.ajax.JSON;
@ -100,8 +102,8 @@ public class TestDataNodeMXBean {
List<DataNode> datanodes = cluster.getDataNodes(); List<DataNode> datanodes = cluster.getDataNodes();
assertEquals(datanodes.size(), 1); assertEquals(datanodes.size(), 1);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = final ObjectName mxbeanName =
new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo"); new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo");
FileSystem fs = cluster.getFileSystem(); FileSystem fs = cluster.getFileSystem();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
@ -113,10 +115,18 @@ public class TestDataNodeMXBean {
cluster.waitActive(); cluster.waitActive();
assertEquals("After restart DN", 5, getTotalNumBlocks(mbs, mxbeanName)); assertEquals("After restart DN", 5, getTotalNumBlocks(mbs, mxbeanName));
fs.delete(new Path("/tmp.txt1"), true); fs.delete(new Path("/tmp.txt1"), true);
// Wait till replica gets deleted on disk. // The total numBlocks should be updated after one file is deleted
Thread.sleep(5000); GenericTestUtils.waitFor(new Supplier<Boolean>() {
assertEquals("After delete one file", 4, @Override
getTotalNumBlocks(mbs, mxbeanName)); public Boolean get() {
try {
return getTotalNumBlocks(mbs, mxbeanName) == 4;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}, 100, 30000);
} finally { } finally {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
@ -125,7 +135,7 @@ public class TestDataNodeMXBean {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
int getTotalNumBlocks(MBeanServer mbs, ObjectName mxbeanName) private int getTotalNumBlocks(MBeanServer mbs, ObjectName mxbeanName)
throws Exception { throws Exception {
int totalBlocks = 0; int totalBlocks = 0;
String volumeInfo = (String) mbs.getAttribute(mxbeanName, "VolumeInfo"); String volumeInfo = (String) mbs.getAttribute(mxbeanName, "VolumeInfo");