### Question:
HdfsSnapshotEvictor extends Configured implements Tool { protected static void evictSnapshots(DistributedFileSystem fs, String dirName, String ageLimit, int numSnapshots) throws FalconException { try { LOG.info("Started evicting snapshots on dir {}{} using policy {}, agelimit {}, numSnapshot {}", fs.getUri(), dirName, ageLimit, numSnapshots); long evictionTime = System.currentTimeMillis() - EvictionHelper.evalExpressionToMilliSeconds(ageLimit); dirName = StringUtils.removeEnd(dirName, Path.SEPARATOR); String snapshotDir = dirName + Path.SEPARATOR + HdfsSnapshotUtil.SNAPSHOT_DIR_PREFIX + Path.SEPARATOR; FileStatus[] snapshots = fs.listStatus(new Path(snapshotDir)); if (snapshots.length <= numSnapshots) { return; } Arrays.sort(snapshots, new Comparator<FileStatus>() { @Override public int compare(FileStatus f1, FileStatus f2) { return Long.compare(f1.getModificationTime(), f2.getModificationTime()); } }); for (int i = 0; i < (snapshots.length - numSnapshots); i++) { if (snapshots[i].getModificationTime() < evictionTime) { fs.deleteSnapshot(new Path(dirName), snapshots[i].getPath().getName()); } } } catch (ELException ele) { LOG.warn("Unable to parse retention age limit {} {}", ageLimit, ele.getMessage()); throw new FalconException("Unable to parse retention age limit " + ageLimit, ele); } catch (IOException ioe) { LOG.warn("Unable to evict snapshots from dir {} {}", dirName, ioe); throw new FalconException("Unable to evict snapshots from dir " + dirName, ioe); } }  static void main(String[] args); @Override int run(String[] args);  }### Answer:
@Test public void evictionTest() throws Exception { Path snapshotDir = new Path(evictionDir, ".snapshot"); FileStatus[] fileStatuses = miniDfs.listStatus(snapshotDir); Assert.assertEquals(fileStatuses.length, NUM_FILES); evictSnapshots(miniDfs, evictionDir.toString(), "minutes(1)", NUM_FILES + 1); fileStatuses = miniDfs.listStatus(snapshotDir); Assert.assertEquals(fileStatuses.length, NUM_FILES); evictSnapshots(miniDfs, evictionDir.toString(), "minutes(1)", NUM_FILES - 1); fileStatuses = miniDfs.listStatus(snapshotDir); Assert.assertEquals(fileStatuses.length, NUM_FILES - 1); evictSnapshots(miniDfs, evictionDir.toString(), "minutes(1)", 2); fileStatuses = miniDfs.listStatus(snapshotDir); Assert.assertTrue(fileStatuses.length >= 5); }
@Test(expectedExceptions = FalconException.class, expectedExceptionsMessageRegExp = "Unable to evict snapshots from dir /apps/falcon/non-snapshot-eviction") public void evictionTestCannotSnapshot() throws Exception { Path nonSnapshotDir = new Path("/apps/falcon/non-snapshot-eviction/"); miniDfs.mkdirs(nonSnapshotDir, fsPermission); evictSnapshots(miniDfs, nonSnapshotDir.toString(), "minutes(1)", NUM_FILES); }