BlockScanner { @VisibleForTesting synchronized VolumeScanner.Statistics getVolumeStats(String volumeId) { VolumeScanner scanner = scanners.get(volumeId); if (scanner == null) { return null; } return scanner.getStatistics(); } BlockScanner(DataNode datanode);  BlockScanner(DataNode datanode, Configuration conf); boolean isEnabled(); synchronized void addVolumeScanner(FsVolumeReference ref); synchronized void removeVolumeScanner(FsVolumeSpi volume); synchronized void removeAllVolumeScanners(); static final Logger LOG; }
@Test(timeout=120000) public void testMultipleBlockPoolScanning() throws Exception { Configuration conf = new Configuration(); conf.setLong(DFS_DATANODE_SCAN_PERIOD_HOURS_KEY, 100L); conf.set(INTERNAL_VOLUME_SCANNER_SCAN_RESULT_HANDLER, TestScanResultHandler.class.getName()); final TestContext ctx = new TestContext(conf, 3); final int BYTES_SCANNED_PER_FILE = 5; int TOTAL_FILES = 16; ctx.createFiles(0, TOTAL_FILES, 1); final TestScanResultHandler.Info info = TestScanResultHandler.getInfo(ctx.volumes.get(0)); synchronized (info) { info.shouldRun = true; info.notify(); } GenericTestUtils.waitFor(new Supplier<Boolean>() { @Override public Boolean get() { synchronized (info) { Statistics stats = ctx.blockScanner.getVolumeStats( ctx.volumes.get(0).getStorageID()); if (stats.scansSinceRestart < 3) { LOG.info("Waiting for scansSinceRestart to reach 3 (it is {})", stats.scansSinceRestart); return false; } if (!stats.eof) { LOG.info("Waiting for eof."); return false; } return true; } } }, 3, 30000); Statistics stats = ctx.blockScanner.getVolumeStats( ctx.volumes.get(0).getStorageID()); assertEquals(TOTAL_FILES, stats.blocksScannedSinceRestart); assertEquals(BYTES_SCANNED_PER_FILE * TOTAL_FILES, stats.bytesScannedInPastHour); ctx.close(); }