DirListingMetadata extends ExpirableMetadata { public synchronized List<PathMetadata> removeExpiredEntriesFromListing( long ttl, long now) { List<PathMetadata> expired = new ArrayList<>(); final Iterator<Map.Entry<Path, PathMetadata>> iterator = listMap.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<Path, PathMetadata> entry = iterator.next(); PathMetadata metadata = entry.getValue(); if (metadata.getLastUpdated() != 0 && (metadata.getLastUpdated() + ttl) <= now) { expired.add(metadata); iterator.remove(); } } return expired; } DirListingMetadata(Path path, Collection<PathMetadata> listing,
      boolean isAuthoritative, long lastUpdated);  DirListingMetadata(Path path, Collection<PathMetadata> listing,
      boolean isAuthoritative);  DirListingMetadata(DirListingMetadata d); Path getPath(); Collection<PathMetadata> getListing(); Set<Path> listTombstones(); DirListingMetadata withoutTombstones(); int numEntries(); boolean isAuthoritative(); Tristate isEmpty(); void setAuthoritative(boolean authoritative); PathMetadata get(Path childPath); void markDeleted(Path childPath, long lastUpdated); void remove(Path childPath); boolean put(PathMetadata childPathMetadata); @Override String toString(); synchronized List<PathMetadata> removeExpiredEntriesFromListing(
      long ttl, long now); void prettyPrint(StringBuilder sb); String prettyPrint(); static final Collection<PathMetadata> EMPTY_DIR; }
@Test public void testRemoveExpiredEntriesFromListing() { long ttl = 9; long oldTime = 100; long newTime = 110; long now = 110; Path path = new Path("/path"); PathMetadata pathMeta1 = new PathMetadata( new S3AFileStatus(true, new Path(path, "dir1"), TEST_OWNER)); PathMetadata pathMeta2 = new PathMetadata( new S3AFileStatus(true, new Path(path, "dir2"), TEST_OWNER)); PathMetadata pathMeta3 = new PathMetadata( new S3AFileStatus(123, 456, new Path(path, "file1"), 8192, TEST_OWNER, TEST_ETAG, TEST_VERSION_ID)); pathMeta1.setLastUpdated(oldTime); pathMeta2.setLastUpdated(0); pathMeta3.setLastUpdated(newTime); List<PathMetadata> listing = Arrays.asList(pathMeta1, pathMeta2, pathMeta3); DirListingMetadata meta = new DirListingMetadata(path, listing, false); List<PathMetadata> expired = meta.removeExpiredEntriesFromListing(ttl, now); Assertions.assertThat(meta.getListing()) .describedAs("Metadata listing for %s", path) .doesNotContain(pathMeta1) .contains(pathMeta2) .contains(pathMeta3); Assertions.assertThat(expired) .describedAs("Expire entries underr %s", path) .doesNotContain(pathMeta2) .contains(pathMeta1); }