HDFS-8645. Resolve inconsistent code in TestReplicationPolicy between trunk and branch-2. Contributed by Zhe Zhang.

This commit is contained in:
Andrew Wang 2015-06-24 18:26:14 -07:00
parent aef9ab2128
commit 4b8593caf8
2 changed files with 16 additions and 17 deletions

View File

@ -327,6 +327,9 @@ Release 2.8.0 - UNRELEASED
HDFS-8639. Add Option for NameNode HTTP port in MiniDFSClusterManager. HDFS-8639. Add Option for NameNode HTTP port in MiniDFSClusterManager.
(Kai Sasaki via jing9) (Kai Sasaki via jing9)
HDFS-8645. Resolve inconsistent code in TestReplicationPolicy between
trunk and branch-2. (Zhe Zhang via wang)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

View File

@ -52,7 +52,6 @@ import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.StatefulBlockInfo; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.StatefulBlockInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
@ -854,6 +853,7 @@ public class TestReplicationPolicy {
.getNamesystem().getBlockManager().neededReplications; .getNamesystem().getBlockManager().neededReplications;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
// Adding the blocks directly to normal priority // Adding the blocks directly to normal priority
neededReplications.add(genBlockInfo(ThreadLocalRandom.current(). neededReplications.add(genBlockInfo(ThreadLocalRandom.current().
nextLong()), 2, 0, 3); nextLong()), 2, 0, 3);
} }
@ -1159,8 +1159,7 @@ public class TestReplicationPolicy {
Namesystem mockNS = mock(Namesystem.class); Namesystem mockNS = mock(Namesystem.class);
when(mockNS.isPopulatingReplQueues()).thenReturn(true); when(mockNS.isPopulatingReplQueues()).thenReturn(true);
when(mockNS.hasWriteLock()).thenReturn(true); when(mockNS.hasWriteLock()).thenReturn(true);
BlockManager bm = BlockManager bm = new BlockManager(mockNS, new HdfsConfiguration());
new BlockManager(mockNS, new HdfsConfiguration());
UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications; UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications;
BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong()); BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong());
@ -1183,18 +1182,16 @@ public class TestReplicationPolicy {
// block under construction, the BlockManager will realize the expected // block under construction, the BlockManager will realize the expected
// replication has been achieved and remove it from the under-replicated // replication has been achieved and remove it from the under-replicated
// queue. // queue.
BlockInfoUnderConstruction info = new BlockInfoUnderConstructionContiguous(block1, (short)1); BlockInfoUnderConstruction info =
new BlockInfoUnderConstructionContiguous(block1, (short) 1);
BlockCollection bc = mock(BlockCollection.class); BlockCollection bc = mock(BlockCollection.class);
when(bc.getPreferredBlockReplication()).thenReturn((short)1); when(bc.getPreferredBlockReplication()).thenReturn((short)1);
bm.addBlockCollection(info, bc); bm.addBlockCollection(info, bc);
StatefulBlockInfo statefulBlockInfo = new StatefulBlockInfo(info,
block1, ReplicaState.RBW);
// Adding this block will increase its current replication, and that will // Adding this block will increase its current replication, and that will
// remove it from the queue. // remove it from the queue.
bm.addStoredBlockUnderConstruction(statefulBlockInfo, bm.addStoredBlockUnderConstruction(new StatefulBlockInfo(info, info,
TestReplicationPolicy.storages[0]); ReplicaState.FINALIZED), TestReplicationPolicy.storages[0]);
// Choose 1 block from UnderReplicatedBlocks. Then it should pick 1 block // Choose 1 block from UnderReplicatedBlocks. Then it should pick 1 block
// from QUEUE_VERY_UNDER_REPLICATED. // from QUEUE_VERY_UNDER_REPLICATED.
@ -1209,8 +1206,7 @@ public class TestReplicationPolicy {
throws IOException { throws IOException {
Namesystem mockNS = mock(Namesystem.class); Namesystem mockNS = mock(Namesystem.class);
when(mockNS.isPopulatingReplQueues()).thenReturn(true); when(mockNS.isPopulatingReplQueues()).thenReturn(true);
BlockManager bm = BlockManager bm = new BlockManager(mockNS, new HdfsConfiguration());
new BlockManager(mockNS, new HdfsConfiguration());
UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications; UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications;
BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong()); BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong());
@ -1234,17 +1230,18 @@ public class TestReplicationPolicy {
when(mbc.getLastBlock()).thenReturn(info); when(mbc.getLastBlock()).thenReturn(info);
when(mbc.getPreferredBlockSize()).thenReturn(block1.getNumBytes() + 1); when(mbc.getPreferredBlockSize()).thenReturn(block1.getNumBytes() + 1);
when(mbc.getPreferredBlockReplication()).thenReturn((short)1); when(mbc.getPreferredBlockReplication()).thenReturn((short)1);
when(mbc.isUnderConstruction()).thenReturn(true);
ContentSummary cs = mock(ContentSummary.class); ContentSummary cs = mock(ContentSummary.class);
when(cs.getLength()).thenReturn((long)1); when(cs.getLength()).thenReturn((long)1);
when(mbc.computeContentSummary(bm.getStoragePolicySuite())).thenReturn(cs); when(mbc.computeContentSummary(bm.getStoragePolicySuite())).thenReturn(cs);
info.setBlockCollection(mbc); info.setBlockCollection(mbc);
bm.addBlockCollection(info, mbc); bm.addBlockCollection(info, mbc);
DatanodeStorageInfo[] dnAry = {storages[0]}; DatanodeStorageInfo[] storageAry = {new DatanodeStorageInfo(
dataNodes[0], new DatanodeStorage("s1"))};
final BlockInfoUnderConstruction ucBlock = final BlockInfoUnderConstruction ucBlock =
info.convertToBlockUnderConstruction(BlockUCState.UNDER_CONSTRUCTION, info.convertToBlockUnderConstruction(BlockUCState.UNDER_CONSTRUCTION,
dnAry); storageAry);
DatanodeStorageInfo storage = mock(DatanodeStorageInfo.class); DatanodeStorageInfo storage = mock(DatanodeStorageInfo.class);
DatanodeDescriptor dn = mock(DatanodeDescriptor.class); DatanodeDescriptor dn = mock(DatanodeDescriptor.class);
when(dn.isDecommissioned()).thenReturn(true); when(dn.isDecommissioned()).thenReturn(true);
@ -1258,7 +1255,7 @@ public class TestReplicationPolicy {
when(mbc.setLastBlock((BlockInfo) any(), (DatanodeStorageInfo[]) any())) when(mbc.setLastBlock((BlockInfo) any(), (DatanodeStorageInfo[]) any()))
.thenReturn(ucBlock); .thenReturn(ucBlock);
bm.convertLastBlockToUnderConstruction(mbc, 0); bm.convertLastBlockToUnderConstruction(mbc, 0L);
// Choose 1 block from UnderReplicatedBlocks. Then it should pick 1 block // Choose 1 block from UnderReplicatedBlocks. Then it should pick 1 block
// from QUEUE_VERY_UNDER_REPLICATED. // from QUEUE_VERY_UNDER_REPLICATED.
@ -1272,8 +1269,7 @@ public class TestReplicationPolicy {
throws IOException { throws IOException {
Namesystem mockNS = mock(Namesystem.class); Namesystem mockNS = mock(Namesystem.class);
when(mockNS.isPopulatingReplQueues()).thenReturn(true); when(mockNS.isPopulatingReplQueues()).thenReturn(true);
BlockManager bm = BlockManager bm = new BlockManager(mockNS, new HdfsConfiguration());
new BlockManager(mockNS, new HdfsConfiguration());
UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications; UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications;
BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong()); BlockInfo block1 = genBlockInfo(ThreadLocalRandom.current().nextLong());