HDFS-16935. Fix TestFsDatasetImpl#testReportBadBlocks (#5432)

Contributed by Viraj Jasani
This commit is contained in:
Viraj Jasani 2023-03-01 10:53:10 -08:00 committed by GitHub
parent 8f6be3678d
commit 2ab7eb4caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 15 deletions

View File

@ -1075,16 +1075,14 @@ public void testCleanShutdownOfVolume() throws Exception {
@Test(timeout = 30000)
public void testReportBadBlocks() throws Exception {
boolean threwException = false;
MiniDFSCluster cluster = null;
try {
Configuration config = new HdfsConfiguration();
cluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
final Configuration config = new HdfsConfiguration();
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(config)
.numDataNodes(1).build()) {
cluster.waitActive();
Assert.assertEquals(0, cluster.getNamesystem().getCorruptReplicaBlocks());
DataNode dataNode = cluster.getDataNodes().get(0);
ExtendedBlock block =
new ExtendedBlock(cluster.getNamesystem().getBlockPoolId(), 0);
ExtendedBlock block = new ExtendedBlock(cluster.getNamesystem().getBlockPoolId(), 0);
try {
// Test the reportBadBlocks when the volume is null
dataNode.reportBadBlocks(block);
@ -1101,15 +1099,11 @@ public void testReportBadBlocks() throws Exception {
block = DFSTestUtil.getFirstBlock(fs, filePath);
// Test for the overloaded method reportBadBlocks
dataNode.reportBadBlocks(block, dataNode.getFSDataset()
.getFsVolumeReferences().get(0));
Thread.sleep(3000);
BlockManagerTestUtil.updateState(cluster.getNamesystem()
.getBlockManager());
// Verify the bad block has been reported to namenode
Assert.assertEquals(1, cluster.getNamesystem().getCorruptReplicaBlocks());
} finally {
cluster.shutdown();
dataNode.reportBadBlocks(block, dataNode.getFSDataset().getFsVolumeReferences().get(0));
DataNodeTestUtils.triggerHeartbeat(dataNode);
BlockManagerTestUtil.updateState(cluster.getNamesystem().getBlockManager());
assertEquals("Corrupt replica blocks could not be reflected with the heartbeat", 1,
cluster.getNamesystem().getCorruptReplicaBlocks());
}
}