From 621cbb4f69072bde259f213629f84494416ae12f Mon Sep 17 00:00:00 2001 From: Walter Su Date: Tue, 17 Nov 2015 10:51:29 +0800 Subject: [PATCH] HDFS-9358. TestNodeCount#testNodeCount timed out. Contributed by Masatake Iwasaki. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../server/blockmanagement/TestNodeCount.java | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index d76253a908a..d909d4649e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -2311,6 +2311,9 @@ Release 2.8.0 - UNRELEASED HDFS-9421. NNThroughputBenchmark replication test NPE with -namenode option. (Mingliang Liu via xyao) + HDFS-9358. TestNodeCount#testNodeCount timed out. + (Masatake Iwasaki via waltersu4549) + Release 2.7.3 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java index c33667d5e00..83d7305ac65 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java @@ -25,6 +25,7 @@ import java.util.concurrent.TimeoutException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; @@ -38,9 +39,6 @@ import org.junit.Test; /** * Test if live nodes count per node is correct * so NN makes right decision for under/over-replicated blocks - * - * Two of the "while" loops below use "busy wait" - * because they are detecting transient states. */ public class TestNodeCount { final short REPLICATION_FACTOR = (short)2; @@ -50,10 +48,19 @@ public class TestNodeCount { Block lastBlock = null; NumberReplicas lastNum = null; - @Test + @Test(timeout = 60000) public void testNodeCount() throws Exception { - // start a mini dfs cluster of 2 nodes final Configuration conf = new HdfsConfiguration(); + + // avoid invalidation by startup delay in order to make test non-transient + conf.setInt(DFSConfigKeys.DFS_NAMENODE_STARTUP_DELAY_BLOCK_DELETION_SEC_KEY, + 60); + + // reduce intervals to make test execution time shorter + conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, 1); + conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1); + + // start a mini dfs cluster of 2 nodes final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION_FACTOR).build(); try { @@ -90,7 +97,7 @@ public class TestNodeCount { cluster.restartDataNode(dnprop); cluster.waitActive(); - // check if excessive replica is detected (transient) + // check if excessive replica is detected initializeTimeout(TIMEOUT); while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() == 0) { checkTimeout("excess replicas not detected"); @@ -124,7 +131,7 @@ public class TestNodeCount { cluster.restartDataNode(dnprop); cluster.waitActive(); - // check if excessive replica is detected (transient) + // check if excessive replica is detected initializeTimeout(TIMEOUT); while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() != 2) { checkTimeout("excess replica count not equal to 2"); @@ -141,9 +148,8 @@ public class TestNodeCount { + ((timeout <= 0) ? Long.MAX_VALUE : timeout); } - /* busy wait on transient conditions */ void checkTimeout(String testLabel) throws TimeoutException { - checkTimeout(testLabel, 0); + checkTimeout(testLabel, 10); } /* check for timeout, then wait for cycleTime msec */