public virtual void TestChooseTargetWithDecomNodes() { namenode.GetNamesystem().WriteLock(); try { string blockPoolId = namenode.GetNamesystem().GetBlockPoolId(); dnManager.HandleHeartbeat(dnrList[3], BlockManagerTestUtil.GetStorageReportsForDatanode (dataNodes[3]), blockPoolId, dataNodes[3].GetCacheCapacity(), dataNodes[3].GetCacheRemaining (), 2, 0, 0, null); dnManager.HandleHeartbeat(dnrList[4], BlockManagerTestUtil.GetStorageReportsForDatanode (dataNodes[4]), blockPoolId, dataNodes[4].GetCacheCapacity(), dataNodes[4].GetCacheRemaining (), 4, 0, 0, null); dnManager.HandleHeartbeat(dnrList[5], BlockManagerTestUtil.GetStorageReportsForDatanode (dataNodes[5]), blockPoolId, dataNodes[5].GetCacheCapacity(), dataNodes[5].GetCacheRemaining (), 4, 0, 0, null); // value in the above heartbeats int load = 2 + 4 + 4; FSNamesystem fsn = namenode.GetNamesystem(); NUnit.Framework.Assert.AreEqual((double)load / 6, dnManager.GetFSClusterStats().GetInServiceXceiverAverage (), Epsilon); // Decommission DNs so BlockPlacementPolicyDefault.isGoodTarget() // returns false for (int i = 0; i < 3; i++) { DatanodeDescriptor d = dnManager.GetDatanode(dnrList[i]); dnManager.GetDecomManager().StartDecommission(d); d.SetDecommissioned(); } NUnit.Framework.Assert.AreEqual((double)load / 3, dnManager.GetFSClusterStats().GetInServiceXceiverAverage (), Epsilon); // update references of writer DN to update the de-commissioned state IList <DatanodeDescriptor> liveNodes = new AList <DatanodeDescriptor>(); dnManager.FetchDatanodes(liveNodes, null, false); DatanodeDescriptor writerDn = null; if (liveNodes.Contains(dataNodes[0])) { writerDn = liveNodes[liveNodes.IndexOf(dataNodes[0])]; } // Call chooseTarget() DatanodeStorageInfo[] targets = namenode.GetNamesystem().GetBlockManager().GetBlockPlacementPolicy ().ChooseTarget("testFile.txt", 3, writerDn, new AList <DatanodeStorageInfo>(), false , null, 1024, TestBlockStoragePolicy.DefaultStoragePolicy); NUnit.Framework.Assert.AreEqual(3, targets.Length); ICollection <DatanodeStorageInfo> targetSet = new HashSet <DatanodeStorageInfo>(Arrays .AsList(targets)); for (int i_1 = 3; i_1 < storages.Length; i_1++) { NUnit.Framework.Assert.IsTrue(targetSet.Contains(storages[i_1])); } } finally { dataNodes[0].StopDecommission(); dataNodes[1].StopDecommission(); dataNodes[2].StopDecommission(); namenode.GetNamesystem().WriteUnlock(); } }