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