ReplicaMap { ReplicaInfo remove(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); try (AutoCloseableLock l = writeLock.acquire()) { FoldedTreeSet<ReplicaInfo> set = map.get(bpid); if (set != null) { ReplicaInfo replicaInfo = set.get(block.getBlockId(), LONG_AND_BLOCK_COMPARATOR); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return set.removeAndGet(replicaInfo); } } } return null; } ReplicaMap(AutoCloseableLock readLock, AutoCloseableLock writeLock);   ReplicaMap(ReadWriteLock lock);   }
@Test public void testRemove() { try { map.remove(bpid, null); fail("Expected exception not thrown"); } catch (IllegalArgumentException expected) { } Block b = new Block(block); b.setGenerationStamp(0); assertNull(map.remove(bpid, b)); b.setGenerationStamp(block.getGenerationStamp()); b.setBlockId(0); assertNull(map.remove(bpid, b)); assertNotNull(map.remove(bpid, block)); assertNull(map.remove(bpid, 0)); map.add(bpid, new FinalizedReplica(block, null, null)); assertNotNull(map.remove(bpid, block.getBlockId())); }