FsVolumeList { long getDfsUsed() throws IOException { long dfsUsed = 0L; for (FsVolumeImpl v : volumes) { try(FsVolumeReference ref = v.obtainReference()) { dfsUsed += v.getDfsUsed(); } catch (ClosedChannelException e) { } } return dfsUsed; } FsVolumeList(List<VolumeFailureInfo> initialVolumeFailureInfos,
      BlockScanner blockScanner,
      VolumeChoosingPolicy<FsVolumeImpl> blockChooser); @Override String toString();  }
@Test public void testNonDfsUsedMetricForVolume() throws Exception { File volDir = new File(baseDir, "volume-0"); volDir.mkdirs(); long diskCapacity = 1000L; long duReserved = 100L; long dfsUsage = 200L; long actualNonDfsUsage = 300L; long reservedForReplicas = 50L; conf.setLong(DFSConfigKeys.DFS_DATANODE_DU_RESERVED_KEY, duReserved); FsVolumeImpl volume = new FsVolumeImplBuilder().setDataset(dataset) .setStorageDirectory( new StorageDirectory( StorageLocation.parse(volDir.getPath()))) .setStorageID("storage-id") .setConf(conf) .build(); FsVolumeImpl spyVolume = Mockito.spy(volume); long testCapacity = diskCapacity - duReserved; spyVolume.setCapacityForTesting(testCapacity); long dfAvailable = diskCapacity - dfsUsage - actualNonDfsUsage; Mockito.doReturn(dfAvailable).when(spyVolume).getDfAvailable(); Mockito.doReturn(dfsUsage).when(spyVolume).getDfsUsed(); Mockito.doReturn(reservedForReplicas).when(spyVolume) .getReservedForReplicas(); Mockito.doReturn(actualNonDfsUsage).when(spyVolume) .getActualNonDfsUsed(); long expectedNonDfsUsage = actualNonDfsUsage - duReserved; assertEquals(expectedNonDfsUsage, spyVolume.getNonDfsUsed()); }