package org.apache.hadoop.hdfs.server.namenode; import java.util.ArrayList; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.server.common.GenerationStamp; import org.apache.hadoop.hdfs.server.protocol.BlockCommand; import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand; import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import junit.framework.TestCase; /** * Test if FSNamesystem handles heartbeat right */ public class TestHeartbeatHandling extends TestCase { /** * Test if {@link FSNamesystem#handleHeartbeat(DatanodeRegistration, long, long, long, int, int)} * can pick up replication and/or invalidate requests and * observes the max limit */ public void testHeartbeat() throws Exception { final Configuration conf = new Configuration(); final MiniDFSCluster cluster = new MiniDFSCluster(conf, 1, true, null); try { cluster.waitActive(); final FSNamesystem namesystem = cluster.getNameNode().getNamesystem(); final DatanodeRegistration nodeReg = cluster.getDataNodes().get(0).dnRegistration; DatanodeDescriptor dd = namesystem.getDatanode(nodeReg); final int REMAINING_BLOCKS = 1; final int MAX_REPLICATE_LIMIT = conf.getInt("dfs.max-repl-streams", 2); final int MAX_INVALIDATE_LIMIT = FSNamesystem.BLOCK_INVALIDATE_CHUNK; final int MAX_INVALIDATE_BLOCKS = 2*MAX_INVALIDATE_LIMIT+REMAINING_BLOCKS; final int MAX_REPLICATE_BLOCKS = 2*MAX_REPLICATE_LIMIT+REMAINING_BLOCKS; final DatanodeDescriptor[] ONE_TARGET = new DatanodeDescriptor[1]; synchronized (namesystem.heartbeats) { for (int i=0; i blockList = new ArrayList(MAX_INVALIDATE_BLOCKS); for (int i=0; i