### Question:
DatanodeDescriptor extends DatanodeInfo { public Block[] getInvalidateBlocks(int maxblocks) { synchronized (invalidateBlocks) { Block[] deleteList = invalidateBlocks.pollToArray(new Block[Math.min( invalidateBlocks.size(), maxblocks)]); return deleteList.length == 0 ? null : deleteList; } } DatanodeDescriptor(DatanodeID nodeID);  DatanodeDescriptor(DatanodeID nodeID, 
                            String networkLocation);  DatanodeDescriptor(DatanodeID nodeID, 
                            long capacity,
                            long dfsUsed,
                            long remaining,
                            long bpused,
                            int xceiverCount,
                            int failedVolumes);  DatanodeDescriptor(DatanodeID nodeID,
                            String networkLocation,
                            long capacity,
                            long dfsUsed,
                            long remaining,
                            long bpused,
                            int xceiverCount,
                            int failedVolumes); boolean addBlock(BlockInfo b); boolean removeBlock(BlockInfo b); BlockInfo replaceBlock(BlockInfo oldBlock, BlockInfo newBlock); void resetBlocks(); void clearBlockQueues(); int numBlocks(); void updateHeartbeat(long capacity, long dfsUsed, long remaining,
      long blockPoolUsed, int xceiverCount, int volFailures); Iterator<BlockInfo> getBlockIterator(); List<BlockTargetPair> getReplicationCommand(int maxTransfers); BlockInfoUnderConstruction[] getLeaseRecoveryCommand(int maxTransfers); Block[] getInvalidateBlocks(int maxblocks); int getBlocksScheduled(); void incBlocksScheduled(); @Override int hashCode(); @Override boolean equals(Object obj); void setDisallowed(boolean flag); boolean isDisallowed(); int getVolumeFailures(); @Override void updateRegInfo(DatanodeID nodeReg); long getBalancerBandwidth(); void setBalancerBandwidth(long bandwidth); boolean areBlockContentsStale(); void markStaleAfterFailover(); void receivedBlockReport(); @Override String dumpDatanode(); public DecommissioningStatus decommissioningStatus; public boolean isAlive; public boolean needKeyUpdate; }### Answer:
@Test public void testGetInvalidateBlocks() throws Exception { final int MAX_BLOCKS = 10; final int REMAINING_BLOCKS = 2; final int MAX_LIMIT = MAX_BLOCKS - REMAINING_BLOCKS; DatanodeDescriptor dd = DFSTestUtil.getLocalDatanodeDescriptor(); ArrayList<Block> blockList = new ArrayList<Block>(MAX_BLOCKS); for (int i=0; i<MAX_BLOCKS; i++) { blockList.add(new Block(i, 0, GenerationStamp.FIRST_VALID_STAMP)); } dd.addBlocksToBeInvalidated(blockList); Block[] bc = dd.getInvalidateBlocks(MAX_LIMIT); assertEquals(bc.length, MAX_LIMIT); bc = dd.getInvalidateBlocks(MAX_LIMIT); assertEquals(bc.length, REMAINING_BLOCKS); }