/// <summary> /// Check that even if LeaseManager.checkLease is not able to relinquish /// leases, the Namenode does't enter an infinite loop while holding the FSN /// write lock and thus become unresponsive /// </summary> public virtual void TestCheckLeaseNotInfiniteLoop() { FSDirectory dir = Org.Mockito.Mockito.Mock <FSDirectory>(); FSNamesystem fsn = Org.Mockito.Mockito.Mock <FSNamesystem>(); Org.Mockito.Mockito.When(fsn.IsRunning()).ThenReturn(true); Org.Mockito.Mockito.When(fsn.HasWriteLock()).ThenReturn(true); Org.Mockito.Mockito.When(fsn.GetFSDirectory()).ThenReturn(dir); LeaseManager lm = new LeaseManager(fsn); //Make sure the leases we are going to add exceed the hard limit lm.SetLeasePeriod(0, 0); //Add some leases to the LeaseManager lm.AddLease("holder1", "src1"); lm.AddLease("holder2", "src2"); lm.AddLease("holder3", "src3"); NUnit.Framework.Assert.AreEqual(lm.GetNumSortedLeases(), 3); //Initiate a call to checkLease. This should exit within the test timeout lm.CheckLeases(); }
public virtual void TestRemoveLeaseWithPrefixPath() { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Build(); cluster.WaitActive(); LeaseManager lm = NameNodeAdapter.GetLeaseManager(cluster.GetNamesystem()); lm.AddLease("holder1", "/a/b"); lm.AddLease("holder2", "/a/c"); NUnit.Framework.Assert.IsNotNull(lm.GetLeaseByPath("/a/b")); NUnit.Framework.Assert.IsNotNull(lm.GetLeaseByPath("/a/c")); lm.RemoveLeaseWithPrefixPath("/a"); NUnit.Framework.Assert.IsNull(lm.GetLeaseByPath("/a/b")); NUnit.Framework.Assert.IsNull(lm.GetLeaseByPath("/a/c")); lm.AddLease("holder1", "/a/b"); lm.AddLease("holder2", "/a/c"); lm.RemoveLeaseWithPrefixPath("/a/"); NUnit.Framework.Assert.IsNull(lm.GetLeaseByPath("/a/b")); NUnit.Framework.Assert.IsNull(lm.GetLeaseByPath("/a/c")); }
public virtual void TestFSNamespaceClearLeases() { Configuration conf = new HdfsConfiguration(); FilePath nameDir = new FilePath(MiniDFSCluster.GetBaseDirectory(), "name"); conf.Set(DFSConfigKeys.DfsNamenodeNameDirKey, nameDir.GetAbsolutePath()); NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode); DFSTestUtil.FormatNameNode(conf); FSNamesystem fsn = FSNamesystem.LoadFromDisk(conf); LeaseManager leaseMan = fsn.GetLeaseManager(); leaseMan.AddLease("client1", "importantFile"); NUnit.Framework.Assert.AreEqual(1, leaseMan.CountLease()); fsn.Clear(); leaseMan = fsn.GetLeaseManager(); NUnit.Framework.Assert.AreEqual(0, leaseMan.CountLease()); }