public virtual void TestQueues() { DatanodeDescriptor fakeDN = DFSTestUtil.GetLocalDatanodeDescriptor(); DatanodeStorage storage = new DatanodeStorage("STORAGE_ID"); DatanodeStorageInfo storageInfo = new DatanodeStorageInfo(fakeDN, storage); msgs.EnqueueReportedBlock(storageInfo, block1Gs1, HdfsServerConstants.ReplicaState .Finalized); msgs.EnqueueReportedBlock(storageInfo, block1Gs2, HdfsServerConstants.ReplicaState .Finalized); NUnit.Framework.Assert.AreEqual(2, msgs.Count()); // Nothing queued yet for block 2 NUnit.Framework.Assert.IsNull(msgs.TakeBlockQueue(block2Gs1)); NUnit.Framework.Assert.AreEqual(2, msgs.Count()); Queue <PendingDataNodeMessages.ReportedBlockInfo> q = msgs.TakeBlockQueue(block1Gs2DifferentInstance ); NUnit.Framework.Assert.AreEqual("ReportedBlockInfo [block=blk_1_1, dn=127.0.0.1:50010, reportedState=FINALIZED]," + "ReportedBlockInfo [block=blk_1_2, dn=127.0.0.1:50010, reportedState=FINALIZED]" , Joiner.On(",").Join(q)); NUnit.Framework.Assert.AreEqual(0, msgs.Count()); // Should be null if we pull again NUnit.Framework.Assert.IsNull(msgs.TakeBlockQueue(block1Gs1)); NUnit.Framework.Assert.AreEqual(0, msgs.Count()); }
public virtual void TestCorruptReplicaInfo() { CorruptReplicasMap crm = new CorruptReplicasMap(); // Make sure initial values are returned correctly NUnit.Framework.Assert.AreEqual("Number of corrupt blocks must initially be 0", 0 , crm.Size()); NUnit.Framework.Assert.IsNull("Param n cannot be less than 0", crm.GetCorruptReplicaBlockIds (-1, null)); NUnit.Framework.Assert.IsNull("Param n cannot be greater than 100", crm.GetCorruptReplicaBlockIds (101, null)); long[] l = crm.GetCorruptReplicaBlockIds(0, null); NUnit.Framework.Assert.IsNotNull("n = 0 must return non-null", l); NUnit.Framework.Assert.AreEqual("n = 0 must return an empty list", 0, l.Length); // create a list of block_ids. A list is used to allow easy validation of the // output of getCorruptReplicaBlockIds int NumBlockIds = 140; IList <long> block_ids = new List <long>(); for (int i = 0; i < NumBlockIds; i++) { block_ids.AddItem((long)i); } DatanodeDescriptor dn1 = DFSTestUtil.GetLocalDatanodeDescriptor(); DatanodeDescriptor dn2 = DFSTestUtil.GetLocalDatanodeDescriptor(); AddToCorruptReplicasMap(crm, GetBlock(0), dn1); NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , 1, crm.Size()); AddToCorruptReplicasMap(crm, GetBlock(1), dn1); NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , 2, crm.Size()); AddToCorruptReplicasMap(crm, GetBlock(1), dn2); NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , 2, crm.Size()); crm.RemoveFromCorruptReplicasMap(GetBlock(1)); NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , 1, crm.Size()); crm.RemoveFromCorruptReplicasMap(GetBlock(0)); NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , 0, crm.Size()); foreach (long block_id in block_ids) { AddToCorruptReplicasMap(crm, GetBlock(block_id), dn1); } NUnit.Framework.Assert.AreEqual("Number of corrupt blocks not returning correctly" , NumBlockIds, crm.Size()); NUnit.Framework.Assert.IsTrue("First five block ids not returned correctly ", Arrays .Equals(new long[] { 0, 1, 2, 3, 4 }, crm.GetCorruptReplicaBlockIds(5, null))); Log.Info(crm.GetCorruptReplicaBlockIds(10, 7L)); Log.Info(block_ids.SubList(7, 18)); NUnit.Framework.Assert.IsTrue("10 blocks after 7 not returned correctly ", Arrays .Equals(new long[] { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, crm.GetCorruptReplicaBlockIds (10, 7L))); }
public virtual void TestUseDelHint() { DatanodeStorageInfo delHint = new DatanodeStorageInfo(DFSTestUtil.GetLocalDatanodeDescriptor (), new DatanodeStorage("id")); IList <DatanodeStorageInfo> moreThan1Racks = Arrays.AsList(delHint); IList <StorageType> excessTypes = new AList <StorageType>(); excessTypes.AddItem(StorageType.Default); NUnit.Framework.Assert.IsTrue(BlockManager.UseDelHint(true, delHint, null, moreThan1Racks , excessTypes)); excessTypes.Remove(0); excessTypes.AddItem(StorageType.Ssd); NUnit.Framework.Assert.IsFalse(BlockManager.UseDelHint(true, delHint, null, moreThan1Racks , excessTypes)); }
public virtual void TestGetInvalidateBlocks() { int MaxBlocks = 10; int RemainingBlocks = 2; int MaxLimit = MaxBlocks - RemainingBlocks; DatanodeDescriptor dd = DFSTestUtil.GetLocalDatanodeDescriptor(); AList <Block> blockList = new AList <Block>(MaxBlocks); for (int i = 0; i < MaxBlocks; i++) { blockList.AddItem(new Block(i, 0, GenerationStamp.LastReservedStamp)); } dd.AddBlocksToBeInvalidated(blockList); Block[] bc = dd.GetInvalidateBlocks(MaxLimit); NUnit.Framework.Assert.AreEqual(bc.Length, MaxLimit); bc = dd.GetInvalidateBlocks(MaxLimit); NUnit.Framework.Assert.AreEqual(bc.Length, RemainingBlocks); }