From ed89856755fd20e814d3ba58e2c183a85a9389d3 Mon Sep 17 00:00:00 2001 From: Brahma Reddy Battula Date: Tue, 6 Dec 2016 22:30:43 +0530 Subject: [PATCH] HDFS-11178. TestAddStripedBlockInFBR#testAddBlockInFullBlockReport fails frequently in trunk. Contributed By Yiqun Lin. --- .../namenode/TestAddStripedBlockInFBR.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlockInFBR.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlockInFBR.java index ab24a25da5..6e02372a7f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlockInFBR.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlockInFBR.java @@ -30,9 +30,8 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; import org.apache.hadoop.hdfs.server.blockmanagement.NumberReplicas; import org.apache.hadoop.hdfs.server.datanode.DataNode; -import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -40,6 +39,8 @@ import org.mockito.Mockito; import org.mockito.internal.util.reflection.Whitebox; +import com.google.common.base.Supplier; + import java.io.IOException; public class TestAddStripedBlockInFBR { @@ -98,14 +99,27 @@ public void testAddBlockInFullBlockReport() throws Exception { DFSTestUtil.createFile(dfs, ecFile, cellSize * dataBlocks, (short) 1, 0L); - // trigger dn's FBR. The FBR will add block-dn mapping. - DataNodeTestUtils.triggerBlockReport(dn); + GenericTestUtils.waitFor(new Supplier() { - // make sure NN has correct block-dn mapping - BlockInfoStriped blockInfo = (BlockInfoStriped) cluster.getNamesystem() - .getFSDirectory().getINode(ecFile.toString()).asFile().getLastBlock(); - NumberReplicas nr = spy.countNodes(blockInfo); - Assert.assertEquals(groupSize, nr.liveReplicas()); - Assert.assertEquals(0, nr.excessReplicas()); + @Override + public Boolean get() { + try { + // trigger dn's FBR. The FBR will add block-dn mapping. + cluster.triggerBlockReports(); + + // make sure NN has correct block-dn mapping + BlockInfoStriped blockInfo = (BlockInfoStriped) cluster + .getNamesystem().getFSDirectory().getINode(ecFile.toString()) + .asFile().getLastBlock(); + NumberReplicas nr = spy.countNodes(blockInfo); + + return nr.excessReplicas() == 0 && nr.liveReplicas() == groupSize; + } catch (Exception ignored) { + // Ignore the exception + } + + return false; + } + }, 3000, 60000); } }