HDFS-9358. TestNodeCount#testNodeCount timed out. Contributed by Masatake Iwasaki.

This commit is contained in:
Walter Su 2015-11-17 10:51:29 +08:00
parent 6502d59e73
commit 621cbb4f69
2 changed files with 18 additions and 9 deletions

View File

@ -2311,6 +2311,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9421. NNThroughputBenchmark replication test NPE with -namenode option. HDFS-9421. NNThroughputBenchmark replication test NPE with -namenode option.
(Mingliang Liu via xyao) (Mingliang Liu via xyao)
HDFS-9358. TestNodeCount#testNodeCount timed out.
(Masatake Iwasaki via waltersu4549)
Release 2.7.3 - UNRELEASED Release 2.7.3 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -25,6 +25,7 @@ import java.util.concurrent.TimeoutException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
@ -38,9 +39,6 @@ import org.junit.Test;
/** /**
* Test if live nodes count per node is correct * Test if live nodes count per node is correct
* so NN makes right decision for under/over-replicated blocks * 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 { public class TestNodeCount {
final short REPLICATION_FACTOR = (short)2; final short REPLICATION_FACTOR = (short)2;
@ -50,10 +48,19 @@ public class TestNodeCount {
Block lastBlock = null; Block lastBlock = null;
NumberReplicas lastNum = null; NumberReplicas lastNum = null;
@Test @Test(timeout = 60000)
public void testNodeCount() throws Exception { public void testNodeCount() throws Exception {
// start a mini dfs cluster of 2 nodes
final Configuration conf = new HdfsConfiguration(); 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 = final MiniDFSCluster cluster =
new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION_FACTOR).build(); new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION_FACTOR).build();
try { try {
@ -90,7 +97,7 @@ public class TestNodeCount {
cluster.restartDataNode(dnprop); cluster.restartDataNode(dnprop);
cluster.waitActive(); cluster.waitActive();
// check if excessive replica is detected (transient) // check if excessive replica is detected
initializeTimeout(TIMEOUT); initializeTimeout(TIMEOUT);
while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() == 0) { while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() == 0) {
checkTimeout("excess replicas not detected"); checkTimeout("excess replicas not detected");
@ -124,7 +131,7 @@ public class TestNodeCount {
cluster.restartDataNode(dnprop); cluster.restartDataNode(dnprop);
cluster.waitActive(); cluster.waitActive();
// check if excessive replica is detected (transient) // check if excessive replica is detected
initializeTimeout(TIMEOUT); initializeTimeout(TIMEOUT);
while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() != 2) { while (countNodes(block.getLocalBlock(), namesystem).excessReplicas() != 2) {
checkTimeout("excess replica count not equal to 2"); checkTimeout("excess replica count not equal to 2");
@ -141,9 +148,8 @@ public class TestNodeCount {
+ ((timeout <= 0) ? Long.MAX_VALUE : timeout); + ((timeout <= 0) ? Long.MAX_VALUE : timeout);
} }
/* busy wait on transient conditions */
void checkTimeout(String testLabel) throws TimeoutException { void checkTimeout(String testLabel) throws TimeoutException {
checkTimeout(testLabel, 0); checkTimeout(testLabel, 10);
} }
/* check for timeout, then wait for cycleTime msec */ /* check for timeout, then wait for cycleTime msec */