This is an automated email from the ASF dual-hosted git repository.

stevel pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2ab7eb4caa9 HDFS-16935. Fix TestFsDatasetImpl#testReportBadBlocks 
(#5432)
2ab7eb4caa9 is described below

commit 2ab7eb4caa9fe012e671434c5bce0e7169440e16
Author: Viraj Jasani <vjas...@apache.org>
AuthorDate: Wed Mar 1 10:53:10 2023 -0800

    HDFS-16935. Fix TestFsDatasetImpl#testReportBadBlocks (#5432)
    
    
    Contributed by Viraj Jasani
---
 .../datanode/fsdataset/impl/TestFsDatasetImpl.java | 24 ++++++++--------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java
index d6f42f3d020..b744a6fa586 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java
@@ -1075,16 +1075,14 @@ public class TestFsDatasetImpl {
   @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 class TestFsDatasetImpl {
 
       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());
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to