LeaseManager { synchronized long countPath() { return leasesById.size(); } LeaseManager(FSNamesystem fsnamesystem); Set<INodesInPath> getINodeWithLeases(final INodeDirectory
      ancestorDir); BatchedListEntries<OpenFileEntry> getUnderConstructionFiles(
      final long prevId); BatchedListEntries<OpenFileEntry> getUnderConstructionFiles(
      final long prevId, final String path); synchronized Lease getLease(INodeFile src); @VisibleForTesting synchronized int countLease(); void setLeasePeriod(long softLimit, long hardLimit); @Override synchronized String toString(); @VisibleForTesting void triggerMonitorCheckNow(); @VisibleForTesting void runLeaseChecks(); static final Logger LOG; }
@Test public void testCountPath() { LeaseManager lm = new LeaseManager(makeMockFsNameSystem()); lm.addLease("holder1", 1); assertThat(lm.countPath(), is(1L)); lm.addLease("holder2", 2); assertThat(lm.countPath(), is(2L)); lm.addLease("holder2", 2); assertThat(lm.countPath(), is(2L)); assertThat(lm.countPath(), is(2L)); lm.removeLease("holder2", stubInodeFile(3)); lm.removeLease("InvalidLeaseHolder", stubInodeFile(1)); assertThat(lm.countPath(), is(2L)); INodeFile file = stubInodeFile(1); lm.reassignLease(lm.getLease(file), file, "holder2"); assertThat(lm.countPath(), is(2L)); lm.removeLease("holder2", stubInodeFile(2)); assertThat(lm.countPath(), is(1L)); }