diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockReplacement.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockReplacement.java index bfd02e2fd0..286a18081a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockReplacement.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockReplacement.java @@ -412,11 +412,19 @@ public void testDeletedBlockWhenAddBlockIsInEdit() throws Exception { (DatanodeInfo)sourceDnDesc, (DatanodeInfo)sourceDnDesc, (DatanodeInfo)destDnDesc)); // Waiting for the FsDatasetAsyncDsikService to delete the block - Thread.sleep(3000); - // Triggering the incremental block report to report the deleted block to - // namnemode - cluster.getDataNodes().get(0).triggerBlockReport( - new BlockReportOptions.Factory().setIncremental(true).build()); + for (int tries = 0; tries < 20; tries++) { + Thread.sleep(1000); + // Triggering the deletion block report to report the deleted block + // to namnemode + DataNodeTestUtils.triggerDeletionReport(cluster.getDataNodes().get(0)); + locatedBlocks = + client.getNamenode().getBlockLocations("/tmp.txt", 0, 10L) + .getLocatedBlocks(); + // If block was deleted and only on 1 datanode then break out + if (locatedBlocks.get(0).getLocations().length == 1) { + break; + } + } cluster.transitionToStandby(0); cluster.transitionToActive(1);