LeaseManager { @VisibleForTesting synchronized void removeLeases(Collection<Long> inodes) { for (long inode : inodes) { Lease lease = leasesById.get(inode); if (lease != null) { removeLease(lease, inode); } } } LeaseManager(FSNamesystem fsnamesystem); 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 Log LOG; }
@Test public void testRemoveLeases() throws Exception { FSNamesystem fsn = mock(FSNamesystem.class); LeaseManager lm = new LeaseManager(fsn); ArrayList<Long> ids = Lists.newArrayList(INodeId.ROOT_INODE_ID + 1, INodeId.ROOT_INODE_ID + 2, INodeId.ROOT_INODE_ID + 3, INodeId.ROOT_INODE_ID + 4); for (long id : ids) { lm.addLease("foo", id); } assertEquals(4, lm.getINodeIdWithLeases().size()); synchronized (lm) { lm.removeLeases(ids); } assertEquals(0, lm.getINodeIdWithLeases().size()); }