HDFS-13542. TestBlockManager#testNeededReplicationWhileAppending fails due to improper cluster shutdown in TestBlockManager#testBlockManagerMachinesArray on Windows. Contributed by Anbang Hu.

(cherry picked from commit d50c4d71dc)
This commit is contained in:
Inigo Goiri 2018-05-11 09:47:57 -07:00
parent 3665217d50
commit e332e011ae
1 changed files with 84 additions and 69 deletions

View File

@ -452,8 +452,8 @@ public class TestBlockManager {
String src = "/test-file"; String src = "/test-file";
Path file = new Path(src); Path file = new Path(src);
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
cluster.waitActive();
try { try {
cluster.waitActive();
BlockManager bm = cluster.getNamesystem().getBlockManager(); BlockManager bm = cluster.getNamesystem().getBlockManager();
FileSystem fs = cluster.getFileSystem(); FileSystem fs = cluster.getFileSystem();
NamenodeProtocols namenode = cluster.getNameNodeRpc(); NamenodeProtocols namenode = cluster.getNameNodeRpc();
@ -492,9 +492,11 @@ public class TestBlockManager {
IOUtils.closeStream(out); IOUtils.closeStream(out);
} }
} finally { } finally {
if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
} }
}
/** /**
* Tell the block manager that replication is completed for the given * Tell the block manager that replication is completed for the given
@ -1043,9 +1045,11 @@ public class TestBlockManager {
assertTrue(fs.exists(file1)); assertTrue(fs.exists(file1));
fs.delete(file1, true); fs.delete(file1, true);
assertTrue(!fs.exists(file1)); assertTrue(!fs.exists(file1));
if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
} }
}
@Test @Test
public void testUseDelHint() { public void testUseDelHint() {
@ -1143,9 +1147,11 @@ public class TestBlockManager {
assertEquals(0, bm.getBlockOpQueueLength()); assertEquals(0, bm.getBlockOpQueueLength());
assertTrue(doneLatch.await(1, TimeUnit.SECONDS)); assertTrue(doneLatch.await(1, TimeUnit.SECONDS));
} finally { } finally {
if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
} }
}
// spam the block manager with IBRs to verify queuing is occurring. // spam the block manager with IBRs to verify queuing is occurring.
@Test @Test
@ -1218,15 +1224,18 @@ public class TestBlockManager {
long batched = MetricsAsserts.getLongCounter("BlockOpsBatched", rb); long batched = MetricsAsserts.getLongCounter("BlockOpsBatched", rb);
assertTrue(batched > 0); assertTrue(batched > 0);
} finally { } finally {
if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
} }
}
@Test(timeout = 60000) @Test(timeout = 60000)
public void testBlockManagerMachinesArray() throws Exception { public void testBlockManagerMachinesArray() throws Exception {
final Configuration conf = new HdfsConfiguration(); final Configuration conf = new HdfsConfiguration();
final MiniDFSCluster cluster = final MiniDFSCluster cluster =
new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
try {
cluster.waitActive(); cluster.waitActive();
BlockManager blockManager = cluster.getNamesystem().getBlockManager(); BlockManager blockManager = cluster.getNamesystem().getBlockManager();
FileSystem fs = cluster.getFileSystem(); FileSystem fs = cluster.getFileSystem();
@ -1243,7 +1252,8 @@ public class TestBlockManager {
File storageDir = cluster.getInstanceStorageDir(0, 0); File storageDir = cluster.getInstanceStorageDir(0, 0);
File dataDir = MiniDFSCluster.getFinalizedDir(storageDir, bpid); File dataDir = MiniDFSCluster.getFinalizedDir(storageDir, bpid);
assertTrue("Data directory does not exist", dataDir.exists()); assertTrue("Data directory does not exist", dataDir.exists());
BlockInfo blockInfo = blockManager.blocksMap.getBlocks().iterator().next(); BlockInfo blockInfo =
blockManager.blocksMap.getBlocks().iterator().next();
ExtendedBlock blk = new ExtendedBlock(bpid, blockInfo.getBlockId(), ExtendedBlock blk = new ExtendedBlock(bpid, blockInfo.getBlockId(),
blockInfo.getNumBytes(), blockInfo.getGenerationStamp()); blockInfo.getNumBytes(), blockInfo.getGenerationStamp());
DatanodeDescriptor failedStorageDataNode = DatanodeDescriptor failedStorageDataNode =
@ -1297,6 +1307,11 @@ public class TestBlockManager {
"replicas and failed storages", "replicas and failed storages",
locatedBlocks.getLocatedBlocks().size() == 1); locatedBlocks.getLocatedBlocks().size() == 1);
ns.readUnlock(); ns.readUnlock();
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
} }
@Test @Test