### Question:
NameNodeResourceChecker { Collection<String> getVolumesLowOnSpace() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Going to check the following volumes disk space: " + volumes); } Collection<String> lowVolumes = new ArrayList<String>(); for (DF volume : volumes.values()) { long availableSpace = volume.getAvailable(); String fileSystem = volume.getFilesystem(); if (LOG.isDebugEnabled()) { LOG.debug("Space available on volume '" + fileSystem + "' is " + availableSpace); } if (availableSpace < duReserved) { LOG.warn("Space available on volume '" + fileSystem + "' is " + availableSpace + ", which is below the configured reserved amount " + duReserved); lowVolumes.add(volume.getFilesystem()); } } return lowVolumes; } NameNodeResourceChecker(Configuration conf);   }### Answer:
@Test public void testChecking2NameDirsOnOneVolume() throws IOException { Configuration conf = new Configuration(); File nameDir1 = new File(conf.get("hadoop.tmp.dir", "name-dir1")); File nameDir2 = new File(conf.get("hadoop.tmp.dir", "name-dir2")); nameDir1.mkdirs(); nameDir2.mkdirs(); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir1.getAbsolutePath() + "," + nameDir2.getAbsolutePath()); conf.setLong(DFSConfigKeys.DFS_NAMENODE_DU_RESERVED_KEY, Long.MAX_VALUE); NameNodeResourceChecker nb = new NameNodeResourceChecker(conf); assertEquals("Should not check the same volume more than once.", 1, nb.getVolumesLowOnSpace().size()); }
@Test public void testCheckingExtraVolumes() throws IOException { Configuration conf = new Configuration(); File nameDir = new File(conf.get("hadoop.tmp.dir", "name-dir")); nameDir.mkdirs(); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); conf.set(DFSConfigKeys.DFS_NAMENODE_CHECKED_VOLUMES_KEY, nameDir.getAbsolutePath()); conf.setLong(DFSConfigKeys.DFS_NAMENODE_DU_RESERVED_KEY, Long.MAX_VALUE); NameNodeResourceChecker nb = new NameNodeResourceChecker(conf); assertEquals("Should not check the same volume more than once.", 1, nb.getVolumesLowOnSpace().size()); }