@Test
  public void testCleanup() throws Exception {
    int[] inRange = { 3, 5, 2, 1 }; // Must have one entry per eventsSubDirs
    int[] outRange = { 2, 2, 2, 1 }; // Must have one entry per eventsSubDirs
    LocalDate today = getNow();

    // Add partitions for the given range of dates from today to past.
    for (int i = 0; i < inRange.length; i++) {
      Path basePath = new Path(baseDir + "/" + eventsSubDirs[i]);
      for (int j = 0; j < inRange[i]; j++) {
        addDatePartition(basePath, today.minusDays(j));
      }
    }

    // Run the task to cleanup
    cleanerTask.run();

    // Verify if the remaining partitions are not expired ones.
    String expiredPtn = getDirForDate(today.minusDays(2));
    for (int i = 0; i < inRange.length; i++) {
      Path basePath = new Path(baseDir + "/" + eventsSubDirs[i]);
      FileStatus[] statuses = fs.listStatus(basePath);

      // If the test setup created today and if test runs tomorrow, then extra dir will be deleted.
      // So, checking for both cases.
      assertTrue((statuses.length == outRange[i]) || (statuses.length == (outRange[i] - 1)));
      for (FileStatus status : statuses) {
        assertTrue(status.getPath().getName().compareTo(expiredPtn) >= 0);
      }
    }
  }
Returns the directory name for a given date.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveProtoEventsCleanerTask.java