HDFSDataPruner extends DataPruner { @Override public Long prune() throws IOException { long filesPruned = 0L; FileStatus[] filesToDelete = fileSystem.globStatus(globPath, new HDFSDataPruner.DateFileFilter(this)); for (FileStatus fileStatus : filesToDelete) { LOG.debug("Deleting File: {}", fileStatus.getPath()); fileSystem.delete(fileStatus.getPath(), false); filesPruned++; } return filesPruned; } HDFSDataPruner(Date startDate, Integer numDays, String fsUri, String globPath); static void main(String... argv); @Override Long prune();  }
@Test public void testDeletesCorrectFiles() throws Exception { createTestFiles(); HDFSDataPruner pruner = new HDFSDataPruner(yesterday, 30, "file: long prunedCount = pruner.prune(); assertEquals(45, prunedCount, "Should have pruned 45 files- pruned: " + prunedCount); File[] filesLeft = dataPath.listFiles(); File[] filesList = new File[filesLeft.length]; for (int i = 0; i < 5; i++) { filesList[i] = new File(dataPath.getPath() + " } Arrays.sort(filesLeft); assertArrayEquals(filesLeft, filesList, "First four files should have been left behind"); }