HDFS-13592. TestNameNodePrunesMissingStorages#testNameNodePrunesUnreportedStorages does not shut down cluster properly. Contributed by Anbang Hu.

(cherry picked from commit 57b893de3d36d20f65ee81b5cc3cfef12594b75b)
This commit is contained in:
Inigo Goiri 2018-05-18 09:36:58 -07:00
parent c4d4ae62cb
commit b0e0ec1648

View File

@ -376,6 +376,8 @@ public void testNameNodePrunesUnreportedStorages() throws Exception {
.Builder(conf).numDataNodes(1)
.storagesPerDatanode(2)
.build();
try {
cluster.waitActive();
// Create two files to ensure each storage has a block
DFSTestUtil.createFile(cluster.getFileSystem(), new Path("file1"),
102400, 102400, 102400, (short)1,
@ -385,7 +387,8 @@ public void testNameNodePrunesUnreportedStorages() throws Exception {
0x1BAD5EED);
// Get the datanode storages and data directories
DataNode dn = cluster.getDataNodes().get(0);
BlockManager bm = cluster.getNameNode().getNamesystem().getBlockManager();
BlockManager bm =
cluster.getNameNode().getNamesystem().getBlockManager();
DatanodeDescriptor dnDescriptor = bm.getDatanodeManager().
getDatanode(cluster.getDataNodes().get(0).getDatanodeUuid());
DatanodeStorageInfo[] dnStoragesInfosBeforeRestart =
@ -414,7 +417,8 @@ public void testNameNodePrunesUnreportedStorages() throws Exception {
}
}
assertEquals(1, numFailedStoragesWithBlocks);
// Heartbeat manager removes the blocks associated with this failed storage
// Heartbeat manager removes the blocks associated with this failed
// storage
bm.getDatanodeManager().getHeartbeatManager().heartbeatCheck();
assertTrue(!failedStorageInfo.areBlocksOnFailedStorage());
// pruneStorageMap removes the unreported storage
@ -422,5 +426,10 @@ public void testNameNodePrunesUnreportedStorages() throws Exception {
// Assert that the unreported storage is pruned
assertEquals(DataNode.getStorageLocations(dn.getConf()).size(),
dnDescriptor.getStorageInfos().length);
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
}