Author: dhruba Date: Sat Dec 1 21:24:33 2007 New Revision: 600244 URL: http://svn.apache.org/viewvc?rev=600244&view=rev Log: HADOOP-2314. Prevent TestBlockReplacement from occasionally getting into an infinite loop. (Hairong Kuang via dhruba)
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestBlockReplacement.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=600244&r1=600243&r2=600244&view=diff ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Sat Dec 1 21:24:33 2007 @@ -172,6 +172,9 @@ HADOOP-2209. SecondaryNamenode process exits if it encounters exceptions that it cannot handle. (Dhruba Borthakur via dhruba) + HADOOP-2314. Prevent TestBlockReplacement from occasionally getting + into an infinite loop. (Hairong Kuang via dhruba) + Branch 0.15 (unreleased) BUG FIXES Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestBlockReplacement.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestBlockReplacement.java?rev=600244&r1=600243&r2=600244&view=diff ============================================================================== --- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestBlockReplacement.java (original) +++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestBlockReplacement.java Sat Dec 1 21:24:33 2007 @@ -23,6 +23,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Random; @@ -142,34 +143,36 @@ // start to replace the block // case 1: proxySource does not contain the block LOG.info("Testcase 1: Proxy " + newNode.getName() - + "does not contain the block " + b.getBlockName() ); + + " does not contain the block " + b.getBlockName() ); assertFalse(replaceBlock(b, source, newNode, proxies.get(0))); // case 2: destination contains the block LOG.info("Testcase 2: Destination " + proxies.get(1).getName() - + "contains the block " + b.getBlockName() ); + + " contains the block " + b.getBlockName() ); assertFalse(replaceBlock(b, source, proxies.get(0), proxies.get(1))); // case 3: correct case - LOG.info("Testcase 3: Proxy=" + source.getName() + "source=" + + LOG.info("Testcase 3: Proxy=" + source.getName() + " source=" + proxies.get(0).getName() + " destination=" + newNode.getName() ); assertTrue(replaceBlock(b, source, proxies.get(0), newNode)); // block locations should contain two proxies and newNode - checkBlocks(source, fileName.toString(), + checkBlocks(new DatanodeInfo[]{newNode, proxies.get(0), proxies.get(1)}, + fileName.toString(), DEFAULT_BLOCK_SIZE, REPLICATION_FACTOR); - // case 4: proxies.get(1) is not a valid del hint - LOG.info("Testcase 3: invalid del hint " + proxies.get(0).getName() ); + // case 4: proxies.get(0) is not a valid del hint + LOG.info("Testcase 4: invalid del hint " + proxies.get(0).getName() ); assertTrue(replaceBlock(b, proxies.get(1), proxies.get(0), source)); - /* block locations should contain two proxies and source; - * newNode was deleted. + /* block locations should contain two proxies, + * and either of source or newNode */ - checkBlocks(newNode, fileName.toString(), + checkBlocks(proxies.toArray(new DatanodeInfo[proxies.size()]), + fileName.toString(), DEFAULT_BLOCK_SIZE, REPLICATION_FACTOR); } finally { cluster.shutdown(); } } - /* file's blocks do not exist at excludedNode */ - private void checkBlocks(DatanodeInfo excludedNode, String fileName, + /* check if file's blocks exist at includeNodes */ + private void checkBlocks(DatanodeInfo[] includeNodes, String fileName, long fileLen, short replFactor) throws IOException { Boolean notDone; do { @@ -186,10 +189,11 @@ LOG.info("Expected replication factor is " + replFactor + " but the real replication factor is " + nodes.length ); } else { - for( DatanodeInfo node : nodes) { - if (node.equals(excludedNode) ) { + List<DatanodeInfo> nodeLocations = Arrays.asList(nodes); + for (DatanodeInfo node : includeNodes) { + if (!nodeLocations.contains(node) ) { notDone=true; - LOG.info("Unexpected block location " + excludedNode.getName() ); + LOG.info("Block is not located at " + node.getName() ); break; } }